py_douyu.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #coding=utf-8
  2. #!/usr/bin/python
  3. import sys
  4. import requests
  5. sys.path.append('..')
  6. from base.spider import Spider
  7. import json
  8. class Spider(Spider):
  9. def getName(self):
  10. return "斗鱼"
  11. def init(self,extend=""):
  12. pass
  13. def isVideoFormat(self,url):
  14. pass
  15. def manualVideoCheck(self):
  16. pass
  17. def homeContent(self,filter):
  18. result = {}
  19. cateManual = {
  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['ownerName']).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 = 'https://getplayurl.lmteam.repl.co/live?platform=douyu&rid={0}'.format(id)
  101. rsp = requests.get(url, allow_redirects=False)
  102. if 'Location' in rsp.headers:
  103. url = rsp.headers['Location']
  104. else:
  105. url = ''
  106. result["parse"] = 0
  107. result["playUrl"] = ''
  108. result["url"] = url
  109. result["header"] = ''
  110. return result
  111. config = {
  112. "player": {},
  113. "filter": {}
  114. }
  115. header = {}
  116. config = {
  117. "player": {},
  118. "filter": {}
  119. }
  120. header = {}
  121. def localProxy(self,param):
  122. action = {
  123. 'url':'',
  124. 'header':'',
  125. 'param':'',
  126. 'type':'string',
  127. 'after':''
  128. }
  129. return [200, "video/MP2T", action, ""]