py_jrskbs.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. infoArray = a.xpath(".//div[@class='contentCenter']/p")
  51. remark = ''
  52. for info in infoArray:
  53. content = info.xpath('string(.)').replace(' ','')
  54. remark = remark + '|' + content
  55. videos.append({
  56. "vod_id": aid,
  57. "vod_name": home + 'vs' + away,
  58. "vod_pic": img,
  59. "vod_remarks": remark.strip('|')
  60. })
  61. result['list'] = videos
  62. result['page'] = pg
  63. result['pagecount'] = pgc
  64. result['limit'] = numvL
  65. result['total'] = numvL
  66. return result
  67. def detailContent(self,array):
  68. aid = array[0]
  69. url = "http://m.jrskbs.com/live/{0}.html".format(aid)
  70. rsp = self.fetch(url)
  71. root = self.html(rsp.text)
  72. divContent = root.xpath("//div[@class='today']")[0]
  73. home = divContent.xpath(".//p[@class='onePlayer homeTeam']/text()")[0]
  74. away = divContent.xpath(".//div[3]/text()")[0].strip()
  75. title = home + 'vs' + away
  76. pic = divContent.xpath(".//img[@class='gameLogo1 homeTeam_img']/@src")[0]
  77. typeName = divContent.xpath(".//div/p[@class='name1 matchTime_wap']/text()")[0]
  78. remark = divContent.xpath(".//div/p[@class='time1 matchTitle']/text()")[0].replace(' ','')
  79. vod = {
  80. "vod_id": aid,
  81. "vod_name": title,
  82. "vod_pic": pic,
  83. "type_name": typeName,
  84. "vod_year": "",
  85. "vod_area": "",
  86. "vod_remarks": remark,
  87. "vod_actor": '',
  88. "vod_director":'',
  89. "vod_content": ''
  90. }
  91. urlList = root.xpath("//div[@class='liveshow']/a")
  92. playUrl = ''
  93. for url in urlList:
  94. name = url.xpath("./text()")[0]
  95. purl = url.xpath("./@data-url")[0]
  96. playUrl =playUrl + '{0}${1}#'.format(name, purl)
  97. vod['vod_play_from'] = '体育直播'
  98. vod['vod_play_url'] = playUrl
  99. result = {
  100. 'list': [
  101. vod
  102. ]
  103. }
  104. return result
  105. def searchContent(self,key,quick):
  106. result = {}
  107. return result
  108. def playerContent(self,flag,id,vipFlags):
  109. result = {}
  110. url = id
  111. if '04stream' in url:
  112. rsp = self.fetch(url)
  113. html = rsp.text
  114. strList = re.findall(r"eval\((.*?)\);", html)
  115. fuctList = strList[1].split('+')
  116. scrpit = ''
  117. for fuc in fuctList:
  118. if fuc.endswith(')'):
  119. append = fuc.split(')')[-1]
  120. else:
  121. append = ''
  122. Unicode = int(self.regStr(reg=r'l\((.*?)\)', src=fuc))
  123. char = chr(Unicode % 256)
  124. char = char + append
  125. scrpit = scrpit + char
  126. par = self.regStr(reg=r'/(.*)/', src=scrpit).replace(')', '')
  127. pars = par.split('/')
  128. infoList = strList[2].split('+')
  129. str = ''
  130. for info in infoList:
  131. if info.startswith('O'):
  132. Unicode = int(int(self.regStr(reg=r'O\((.*?)\)', src=info)) / int(pars[0]) / int(pars[1]))
  133. char = chr(Unicode % 256)
  134. str = str + char
  135. url = self.regStr(reg=r"play_url=\'(.*?)\'", src=str)
  136. result["parse"] = 0
  137. else:
  138. url = id
  139. result["parse"] = 1
  140. result["playUrl"] = ''
  141. result["url"] = url
  142. result["header"] = ''
  143. return result
  144. config = {
  145. "player": {},
  146. "filter": {}
  147. }
  148. header = {}
  149. def localProxy(self,param):
  150. action = {
  151. 'url':'',
  152. 'header':'',
  153. 'param':'',
  154. 'type':'string',
  155. 'after':''
  156. }
  157. return [200, "video/MP2T", action, ""]