虎牙.py 3.2 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. "音乐": "音乐",
  20. "一起看": "一起看",
  21. "三国杀": "三国杀",
  22. "网游竞技": "网游竞技"
  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=huya&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=huya&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://mp.huya.com/cache.php?m=Live&do=profileRoom&roomid={0}'.format(id)
  101. rsp = self.fetch(url)
  102. jRoot = json.loads(rsp.text)
  103. if jRoot['data']['liveStatus'] != 'ON':
  104. return {}
  105. jo = jRoot['data']
  106. ja = jo['stream']['baseSteamInfoList'][0]['sStreamName']
  107. url = 'http://txtest-xp2p.p2p.huya.com/src/' + ja + '.xs?ratio=4000'
  108. result["parse"] = 0
  109. result["playUrl"] = ''
  110. result["url"] = url
  111. result["header"] = {
  112. "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"
  113. }
  114. result["contentType"] = 'video/x-flv'
  115. return result
  116. config = {
  117. "player": {},
  118. "filter": {}
  119. }
  120. header = {}
  121. config = {
  122. "player": {},
  123. "filter": {}
  124. }
  125. header = {}
  126. def localProxy(self,param):
  127. action = {
  128. 'url':'',
  129. 'header':'',
  130. 'param':'',
  131. 'type':'string',
  132. 'after':''
  133. }
  134. return [200, "video/MP2T", action, ""]