乐猪.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. import base64
  8. import hashlib
  9. class Spider(Spider): # 元类 默认的元类 type
  10. def getName(self):
  11. return "LeZhuTV"
  12. def init(self, extend=""):
  13. print("============{0}============".format(extend))
  14. pass
  15. def homeContent(self, filter):
  16. result = {}
  17. cateManual = {
  18. "电影": "1",
  19. "连续剧": "2",
  20. "动漫": "4",
  21. "综艺": "3",
  22. "韩剧": "14",
  23. "美剧": "15"
  24. }
  25. classes = []
  26. for k in cateManual:
  27. classes.append({
  28. 'type_name': k,
  29. 'type_id': cateManual[k]
  30. })
  31. result['class'] = classes
  32. if (filter):
  33. result['filters'] = self.config['filter']
  34. return result
  35. def homeVideoContent(self):
  36. rsp = self.fetch("http://www.lezhutv.com")
  37. root = self.html(rsp.text)
  38. aList = root.xpath("//ul[@class='tbox_m2']/li")
  39. videos = []
  40. for a in aList:
  41. name = a.xpath('.//@title')[0]
  42. pic = a.xpath('.//@data-original')[0]
  43. mark = a.xpath(".//span/text()")[0]
  44. sid = a.xpath(".//@href")[0]
  45. sid = self.regStr(sid, "/detail/(\\d+).html")
  46. videos.append({
  47. "vod_id": sid,
  48. "vod_name": name,
  49. "vod_pic": pic,
  50. "vod_remarks": mark
  51. })
  52. result = {
  53. 'list': videos
  54. }
  55. return result
  56. def categoryContent(self, tid, pg, filter, extend):
  57. result = {}
  58. ext = extend.get("by","")
  59. url = 'http://www.lezhutv.com/list/{0}_{1}_desc_{2}_0_0___.html'.format(tid,pg,ext)
  60. rsp = self.fetch(url)
  61. root = self.html(rsp.text)
  62. aList = root.xpath("//ul[@class='tbox_m2']/li")
  63. videos = []
  64. for a in aList:
  65. name = a.xpath('.//@title')[0]
  66. pic = a.xpath('.//@data-original')[0]
  67. mark = a.xpath(".//span/text()")[0]
  68. sid = a.xpath(".//@href")[0]
  69. sid = self.regStr(sid, "/detail/(\\d+).html")
  70. videos.append({
  71. "vod_id": sid,
  72. "vod_name": name,
  73. "vod_pic": pic,
  74. "vod_remarks": mark
  75. })
  76. result['list'] = videos
  77. result['page'] = pg
  78. result['pagecount'] = 9999
  79. result['limit'] = 90
  80. result['total'] = 999999
  81. return result
  82. def detailContent(self, array):
  83. tid = array[0]
  84. url = 'http://www.lezhutv.com/detail/{0}.html'.format(tid)
  85. rsp = self.fetch(url)
  86. root = self.html(rsp.text)
  87. node = root.xpath(".//div[@class='dbox']")[0]
  88. nodes = root.xpath(".//div[@class='tbox2']")[0]
  89. pic = node.xpath(".//div/@data-original")[0]
  90. title = node.xpath('.//h4/text()')[0]
  91. detail = nodes.xpath(".//div[@class='tbox_js']/text()")[0]
  92. yac = node.xpath(".//p[@class='yac']/text()")[0]
  93. yac = yac.split('/')
  94. yacs = yac[0].strip()
  95. type_name = yac[1].strip()
  96. actor = node.xpath(".//p[@class='act']/text()")[0]
  97. director = node.xpath(".//p[@class='dir']/text()")[0]
  98. vod = {
  99. "vod_id": tid,
  100. "vod_name": title,
  101. "vod_pic": pic,
  102. "type_name": type_name,
  103. "vod_year": yacs,
  104. "vod_area": "",
  105. "vod_remarks": "",
  106. "vod_actor": actor,
  107. "vod_director": director,
  108. "vod_content": detail
  109. }
  110. vod_play_from = '$$$'
  111. playFrom = []
  112. vodHeader = root.xpath(".//div[@class='tbox2 tabs']/div/h3/text()")
  113. i=1
  114. for v in vodHeader:
  115. playFrom.append("线路" + str(i))
  116. i = i+1
  117. vod_play_from = vod_play_from.join(playFrom)
  118. vod_play_url = '$$$'
  119. playList = []
  120. vodList = root.xpath("//div[@class='tbox2 tabs']")
  121. for vl in vodList:
  122. vodItems = []
  123. aList = vl.xpath(".//ul/li/a")
  124. for tA in aList:
  125. href = tA.xpath('./@href')[0]
  126. name = tA.xpath('./text()')[0]
  127. tId = self.regStr(href, '/play/(\\S+).html')
  128. vodItems.append(name + "$" + tId)
  129. joinStr = '#'
  130. joinStr = joinStr.join(vodItems)
  131. playList.append(joinStr)
  132. vod_play_url = vod_play_url.join(playList)
  133. vod['vod_play_from'] = vod_play_from
  134. vod['vod_play_url'] = vod_play_url
  135. result = {
  136. 'list': [
  137. vod
  138. ]
  139. }
  140. return result
  141. def searchContent(self, key, quick):
  142. url = 'http://www.lezhutv.com/search-pg-1-wd-{0}.html'.format(key)
  143. rsp = self.fetch(url)
  144. root = self.html(rsp.text)
  145. seaArray = root.xpath("//ul[@class='tbox_m']/li")
  146. seaList = []
  147. for vod in seaArray:
  148. name = vod.xpath('.//@title')[0]
  149. pic = vod.xpath('.//@data-original')[0]
  150. mark = vod.xpath(".//span/text()")[0]
  151. sid = vod.xpath(".//@href")[0]
  152. sid = self.regStr(sid, "/detail/(\\d+).html")
  153. seaList.append({
  154. "vod_id": sid,
  155. "vod_name": name,
  156. "vod_pic": pic,
  157. "vod_remarks": mark
  158. })
  159. result = {
  160. 'list': seaList
  161. }
  162. return result
  163. config = {
  164. "player":{},
  165. "filter":{"1":[{"key":"by","name":"排序","value":[{"n":"时间","v":"time"},{"n":"人气","v":"score"},{"n":"评分","v":"hits"}]}],"2":[{"key":"by","name":"排序","value":[{"n":"时间","v":"time"},{"n":"人气","v":"score"},{"n":"评分","v":"hits"}]}],"3":[{"key":"by","name":"排序","value":[{"n":"时间","v":"time"},{"n":"人气","v":"score"},{"n":"评分","v":"hits"}]}],"4":[{"key":"by","name":"排序","value":[{"n":"时间","v":"time"},{"n":"人气","v":"score"},{"n":"评分","v":"hits"}]}],"14":[{"key":"by","name":"排序","value":[{"n":"时间","v":"time"},{"n":"人气","v":"score"},{"n":"评分","v":"hits"}]}],"15":[{"key":"by","name":"排序","value":[{"n":"时间","v":"time"},{"n":"人气","v":"score"},{"n":"评分","v":"hits"}]}]}
  166. }
  167. header = {
  168. "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36"
  169. }
  170. def get_md5(self,value):
  171. b64 = base64.b64encode((base64.b64encode(value.encode()).decode() + "NTY2").encode()).decode()
  172. md5 = hashlib.md5(b64.encode()).hexdigest()
  173. return "".join(char if char.isdigit() else "zyxwvutsrqponmlkjihgfedcba"["abcdefghijklmnopqrstuvwxyz".find(char)] for char in md5)
  174. def playerContent(self, flag, id, vipFlags):
  175. result = {}
  176. url = 'http://www.lezhutv.com/play/{0}.html'.format(id)
  177. rsp = self.fetch(url)
  178. root = self.html(rsp.text)
  179. scripts = root.xpath("//script/text()")
  180. scripts = scripts[1].replace('\n', '')
  181. nid = self.regStr(scripts, 'view_path = \'(.*?)\';')
  182. md5url = 'http://www.lezhutv.com/hls2/index.php?url={0}'.format(nid)
  183. rsp = self.fetch(md5url)
  184. root = self.html(rsp.text)
  185. value = root.xpath(".//input[@id='hdMd5']/@value")
  186. value = ''.join(value)
  187. md5s = self.get_md5(str(value))
  188. data = {
  189. "id": nid,
  190. "type": "vid",
  191. "siteuser": "",
  192. "md5": md5s,
  193. "referer": url,
  194. "hd": "",
  195. "lg": ""
  196. }
  197. payUrl = 'http://www.lezhutv.com/hls2/url.php'
  198. parseRsp = self.post(payUrl,data,headers=self.header)
  199. parseRsps = json.loads(parseRsp.text)
  200. realUrl = parseRsps['media']['url']
  201. if len(realUrl) > 0:
  202. result["parse"] = 0
  203. result["playUrl"] = ""
  204. result["url"] = realUrl
  205. result["header"] = ""
  206. else:
  207. result["parse"] = 1
  208. result["playUrl"] = ""
  209. result["url"] = url
  210. result["header"] = json.dumps(self.header)
  211. return result
  212. def isVideoFormat(self, url):
  213. pass
  214. def manualVideoCheck(self):
  215. pass
  216. def localProxy(self, param):
  217. return [200, "video/MP2T", action, ""]