py_douyu.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. "热门游戏": "热门游戏",
  20. "一起看": "一起看",
  21. "主机游戏": "主机游戏",
  22. "原创IP": "原创IP",
  23. "王者荣耀":"王者荣耀",
  24. "英雄联盟":"英雄联盟",
  25. "第五人格":"第五人格",
  26. "火影忍者":"火影忍者",
  27. "和平精英":"和平精英",
  28. "DOTA2":"DOTA2",
  29. "CF手游":"CF手游"
  30. }
  31. classes = []
  32. for k in cateManual:
  33. classes.append({
  34. 'type_name': k,
  35. 'type_id': cateManual[k]
  36. })
  37. result['class'] = classes
  38. if (filter):
  39. result['filters'] = self.config['filter']
  40. return result
  41. def homeVideoContent(self):
  42. result = {}
  43. return result
  44. def categoryContent(self,tid,pg,filter,extend):
  45. result = {}
  46. url = 'http://live.yj1211.work/api/live/getRecommendByPlatformArea?platform=douyu&size=20&area={0}&page={1}'.format(tid, pg)
  47. rsp = self.fetch(url)
  48. content = rsp.text
  49. jo = json.loads(content)
  50. videos = []
  51. vodList = jo['data']
  52. for vod in vodList:
  53. aid = (vod['roomId']).strip()
  54. title = vod['roomName'].strip()
  55. img = vod['roomPic'].strip()
  56. remark = (vod['categoryName']).strip()
  57. videos.append({
  58. "vod_id": aid,
  59. "vod_name": title,
  60. "vod_pic": img,
  61. "vod_remarks": remark
  62. })
  63. result['list'] = videos
  64. result['page'] = pg
  65. result['pagecount'] = 9999
  66. result['limit'] = 90
  67. result['total'] = 999999
  68. return result
  69. def detailContent(self,array):
  70. aid = array[0]
  71. url = "http://live.yj1211.work/api/live/getRoomInfo?platform=douyu&roomId={0}".format(aid)
  72. rsp = self.fetch(url)
  73. jRoot = json.loads(rsp.text)
  74. jo = jRoot['data']
  75. title = jo['roomName']
  76. pic = jo['roomPic']
  77. desc = str(jo['online'])
  78. dire = jo['ownerName']
  79. typeName = jo['categoryName']
  80. remark = jo['categoryName']
  81. vod = {
  82. "vod_id": aid,
  83. "vod_name": title,
  84. "vod_pic": pic,
  85. "type_name": typeName,
  86. "vod_year": "",
  87. "vod_area": "",
  88. "vod_remarks": remark,
  89. "vod_actor": '在线人数:' + desc,
  90. "vod_director": dire,
  91. "vod_content": ""
  92. }
  93. playUrl = '原画' + '${0}#'.format(aid)
  94. vod['vod_play_from'] = '斗鱼直播'
  95. vod['vod_play_url'] = playUrl
  96. result = {
  97. 'list': [
  98. vod
  99. ]
  100. }
  101. return result
  102. def searchContent(self,key,quick):
  103. result = {}
  104. return result
  105. def playerContent(self,flag,id,vipFlags):
  106. result = {}
  107. url = 'http://live.yj1211.work/api/live/getRealUrl?platform=douyu&roomId={0}'.format(id)
  108. rsp = self.fetch(url)
  109. jRoot = json.loads(rsp.text)
  110. jo = jRoot['data']
  111. ja = jo['OD']
  112. url = ja
  113. result["parse"] = 0
  114. result["playUrl"] = ''
  115. result["url"] = url
  116. result["header"] = {
  117. "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"
  118. }
  119. result["contentType"] = 'video/x-flv'
  120. return result
  121. config = {
  122. "player": {},
  123. "filter": {}
  124. }
  125. header = {}
  126. config = {
  127. "player": {},
  128. "filter": {}
  129. }
  130. header = {}
  131. def localProxy(self,param):
  132. action = {
  133. 'url':'',
  134. 'header':'',
  135. 'param':'',
  136. 'type':'string',
  137. 'after':''
  138. }
  139. return [200, "video/MP2T", action, ""]