py_jrskbs.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #coding=utf-8
  2. #!/usr/bin/python
  3. import sys
  4. sys.path.append('..')
  5. from base.spider import Spider
  6. import re
  7. import math
  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. classes = []
  23. for k in cateManual:
  24. classes.append({
  25. 'type_name': k,
  26. 'type_id': cateManual[k]
  27. })
  28. result['class'] = classes
  29. if (filter):
  30. result['filters'] = self.config['filter']
  31. return result
  32. def homeVideoContent(self):
  33. result = {}
  34. return result
  35. def categoryContent(self,tid,pg,filter,extend):
  36. result = {}
  37. url = 'https://m.jrskbs.com'
  38. rsp = self.fetch(url)
  39. html = self.html(rsp.text)
  40. aList = html.xpath("//div[contains(@class, 'contentList')]/a")
  41. videos = []
  42. numvL = len(aList)
  43. pgc = math.ceil(numvL/15)
  44. for a in aList:
  45. aid = a.xpath("./@href")[0]
  46. aid = self.regStr(reg=r'/live/(.*?).html', src=aid)
  47. img = a.xpath(".//div[@class='contentLeft']/p/img/@src")[0]
  48. home = a.xpath(".//div[@class='contentLeft']/p[@class='false false']/text()")[0]
  49. away = a.xpath(".//div[@class='contentRight']/p[@class='false false']/text()")[0]
  50. rmList = a.xpath(".//div[@class='contentCenter']/p/text()")
  51. remark = rmList[1].replace('|','').replace(' ','') + '|' + rmList[0]
  52. videos.append({
  53. "vod_id": aid,
  54. "vod_name": home + 'vs' + away,
  55. "vod_pic": img,
  56. "vod_remarks": remark
  57. })
  58. result['list'] = videos
  59. result['page'] = pg
  60. result['pagecount'] = pgc
  61. result['limit'] = numvL
  62. result['total'] = numvL
  63. return result
  64. def detailContent(self,array):
  65. aid = array[0]
  66. url = "http://m.jrskbs.com/live/{0}.html".format(aid)
  67. rsp = self.fetch(url)
  68. root = self.html(rsp.text)
  69. divContent = root.xpath("//div[@class='today']")[0]
  70. home = divContent.xpath(".//p[@class='onePlayer homeTeam']/text()")[0]
  71. away = divContent.xpath(".//div[3]/text()")[0].strip()
  72. title = home + 'vs' + away
  73. pic = divContent.xpath(".//img[@class='gameLogo1 homeTeam_img']/@src")[0]
  74. typeName = divContent.xpath(".//div/p[@class='name1 matchTime_wap']/text()")[0]
  75. remark = divContent.xpath(".//div/p[@class='time1 matchTitle']/text()")[0].replace(' ','')
  76. vod = {
  77. "vod_id": aid,
  78. "vod_name": title,
  79. "vod_pic": pic,
  80. "type_name": typeName,
  81. "vod_year": "",
  82. "vod_area": "",
  83. "vod_remarks": remark,
  84. "vod_actor": '',
  85. "vod_director":'',
  86. "vod_content": ''
  87. }
  88. urlList = root.xpath("//div[@class='liveshow']/a")
  89. playUrl = ''
  90. for url in urlList:
  91. name = url.xpath("./text()")[0]
  92. purl = url.xpath("./@data-url")[0]
  93. playUrl =playUrl + '{0}${1}#'.format(name, purl)
  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 = id
  108. if '04stream' in url:
  109. rsp = self.fetch(url)
  110. html = rsp.text
  111. strList = re.findall(r"eval\((.*?)\);", html)
  112. fuctList = strList[1].split('+')
  113. scrpit = ''
  114. for fuc in fuctList:
  115. if fuc.endswith(')'):
  116. append = fuc.split(')')[-1]
  117. else:
  118. append = ''
  119. Unicode = int(self.regStr(reg=r'l\((.*?)\)', src=fuc))
  120. char = chr(Unicode % 256)
  121. char = char + append
  122. scrpit = scrpit + char
  123. par = self.regStr(reg=r'/(.*)/', src=scrpit).replace(')', '')
  124. pars = par.split('/')
  125. infoList = strList[2].split('+')
  126. str = ''
  127. for info in infoList:
  128. if info.startswith('O'):
  129. Unicode = int(int(self.regStr(reg=r'O\((.*?)\)', src=info)) / int(pars[0]) / int(pars[1]))
  130. char = chr(Unicode % 256)
  131. str = str + char
  132. purl = self.regStr(reg=r"play_url=\'(.*?)\'", src=str)
  133. result["parse"] = 0
  134. elif 'v.stnye.cc' in url:
  135. purl = id
  136. result["parse"] = 1
  137. elif 'dplayer' in url:
  138. url = 'https://m.jrskbs.com' + url
  139. rsp = self.fetch(url)
  140. purl = self.regStr(reg=r'var PlayUrl = \"(.*?)\"', src=rsp.text)
  141. result["parse"] = 0
  142. result["playUrl"] = ''
  143. result["url"] = purl
  144. result["header"] = ''
  145. return result
  146. config = {
  147. "player": {},
  148. "filter": {}
  149. }
  150. header = {}
  151. def localProxy(self,param):
  152. action = {
  153. 'url':'',
  154. 'header':'',
  155. 'param':'',
  156. 'type':'string',
  157. 'after':''
  158. }
  159. return [200, "video/MP2T", action, ""]