py_douyu.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #coding=utf-8
  2. #!/usr/bin/python
  3. import sys
  4. sys.path.append('..')
  5. from base.spider import Spider
  6. import json
  7. class Spider(Spider):
  8. def getName(self):
  9. return "斗鱼"
  10. def init(self,extend=""):
  11. pass
  12. def isVideoFormat(self,url):
  13. pass
  14. def manualVideoCheck(self):
  15. pass
  16. def homeContent(self,filter):
  17. result = {}
  18. cateManual = {
  19. "真的很博通": "222931",
  20. "热门游戏": "热门游戏",
  21. "主机游戏": "主机游戏",
  22. "原创IP": "原创IP"
  23. }
  24. classes = []
  25. for k in cateManual:
  26. classes.append({
  27. 'type_name': k,
  28. 'type_id': cateManual[k]
  29. })
  30. result['class'] = classes
  31. if (filter):
  32. result['filters'] = self.config['filter']
  33. return result
  34. def homeVideoContent(self):
  35. result = {}
  36. return result
  37. def categoryContent(self,tid,pg,filter,extend):
  38. result = {}
  39. url = 'http://live.yj1211.work/api/live/getRecommendByPlatformArea?platform=douyu&size=20&area={0}&page={1}'.format(tid, pg)
  40. rsp = self.fetch(url)
  41. content = rsp.text
  42. jo = json.loads(content)
  43. videos = []
  44. vodList = jo['data']
  45. for vod in vodList:
  46. aid = (vod['roomId']).strip()
  47. title = vod['roomName'].strip()
  48. img = vod['roomPic'].strip()
  49. remark = (vod['categoryName']).strip()
  50. videos.append({
  51. "vod_id": aid,
  52. "vod_name": title,
  53. "vod_pic": img,
  54. "vod_remarks": remark
  55. })
  56. result['list'] = videos
  57. result['page'] = pg
  58. result['pagecount'] = 9999
  59. result['limit'] = 90
  60. result['total'] = 999999
  61. return result
  62. def detailContent(self,array):
  63. aid = array[0]
  64. url = "http://live.yj1211.work/api/live/getRoomInfo?platform=douyu&roomId={0}".format(aid)
  65. rsp = self.fetch(url)
  66. jRoot = json.loads(rsp.text)
  67. jo = jRoot['data']
  68. title = jo['roomName']
  69. pic = jo['roomPic']
  70. desc = str(jo['online'])
  71. dire = jo['ownerName']
  72. typeName = jo['categoryName']
  73. remark = jo['categoryName']
  74. vod = {
  75. "vod_id": aid,
  76. "vod_name": title,
  77. "vod_pic": pic,
  78. "type_name": typeName,
  79. "vod_year": "",
  80. "vod_area": "",
  81. "vod_remarks": remark,
  82. "vod_actor": '在线人数:' + desc,
  83. "vod_director": dire,
  84. "vod_content": ""
  85. }
  86. playUrl = '原画' + '${0}#'.format(aid)
  87. vod['vod_play_from'] = '斗鱼直播'
  88. vod['vod_play_url'] = playUrl
  89. result = {
  90. 'list': [
  91. vod
  92. ]
  93. }
  94. return result
  95. def searchContent(self,key,quick):
  96. result = {}
  97. return result
  98. def playerContent(self,flag,id,vipFlags):
  99. result = {}
  100. url = 'http://live.yj1211.work/api/live/getRealUrl?platform=douyu&roomId={0}'.format(id)
  101. rsp = self.fetch(url)
  102. jRoot = json.loads(rsp.text)
  103. jo = jRoot['data']
  104. ja = jo['OD']
  105. url = ja
  106. result["parse"] = 0
  107. result["playUrl"] = ''
  108. result["url"] = url
  109. result["header"] = {
  110. "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36"
  111. }
  112. result["contentType"] = 'video/x-flv'
  113. return result
  114. config = {
  115. "player": {},
  116. "filter": {}
  117. }
  118. header = {}
  119. config = {
  120. "player": {},
  121. "filter": {}
  122. }
  123. header = {}
  124. def localProxy(self,param):
  125. action = {
  126. 'url':'',
  127. 'header':'',
  128. 'param':'',
  129. 'type':'string',
  130. 'after':''
  131. }
  132. return [200, "video/MP2T", action, ""]