py_douyu.py 3.1 KB

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