py_firstaid.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #coding=utf-8
  2. #!/usr/bin/python
  3. import sys
  4. import json
  5. from difflib import SequenceMatcher
  6. sys.path.append('..')
  7. from base.spider import Spider
  8. class Spider(Spider): # 元类 默认的元类 type
  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 homeVideoContent(self):
  18. return self.categoryContent('FIRSTAID', 1, False, {})
  19. def homeContent(self, filter):
  20. result = {}
  21. cateManual = {
  22. "急救指南": "FIRSTAID"
  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. return result
  32. def categoryContent(self, cid, page, filter, ext):
  33. result = {}
  34. header = self.header.copy()
  35. r = self.fetch('https://m.youlai.cn/jijiu', headers=header)
  36. html = self.html(r.text)
  37. vodList = html.xpath("//ul[contains(@class,'list-flex-br')]/li")
  38. videos = []
  39. for vod in vodList:
  40. title = vod.xpath(".//div/text()")[0].strip()
  41. cid = vod.xpath("./a/@href")[0]
  42. videos.append({
  43. "vod_id": cid,
  44. "vod_name": title,
  45. "vod_pic": 'https://api-lmteam.koyeb.app/files/firstaid.png',
  46. "vod_remarks": ''
  47. })
  48. lenvideos = len(videos)
  49. result['list'] = videos
  50. result['page'] = page
  51. result['pagecount'] = page
  52. result['limit'] = lenvideos
  53. result['total'] = lenvideos
  54. return result
  55. def detailContent(self, did):
  56. did = did[0]
  57. header = self.header.copy()
  58. url = f'https://m.youlai.cn{did}'
  59. r = self.fetch(url, headers=header)
  60. if '/video/article' in did:
  61. data = json.loads(self.regStr(reg='_DATA__ =(.*?});', src=r.text))
  62. title = data['videoDetailData']['title']
  63. director = f"{data['videoDetailData']['doctor']['name']}|{data['videoDetailData']['doctor']['medical_title']}|{data['videoDetailData']['doctor']['hospital_name']}"
  64. content = data['videoDetailData']['description'].strip()
  65. playUrl = data['videoDetailData']['media_url']
  66. else:
  67. html = self.html(r.text)
  68. title = html.xpath("//h2[contains(@class,'video-title')]/text()")[0].strip()
  69. director = '|'.join(html.xpath("//div[contains(@class,'list-flex')]/span /text()")).strip()
  70. content = '\n'.join(html.xpath("//div[@class='img-text-con']//text()[not(parent::span[@class='breakpoint-item'])]")).strip()
  71. playUrl = html.xpath("//video[contains(@id,'video')]/source/@src")[0]
  72. vod = {
  73. "vod_id": did,
  74. "vod_name": title,
  75. "vod_pic": 'https://img1.imgtp.com/2023/09/19/bydPPaLp.png',
  76. "vod_content": content.strip(),
  77. "vod_director": director,
  78. "vod_play_from": '急救指南',
  79. "vod_play_url": title + '$' + playUrl
  80. }
  81. result = {'list': [vod]}
  82. return result
  83. def searchContent(self, key, quick):
  84. return self.searchContentPage(key, quick, '1')
  85. def searchContentPage(self, key, quick, page):
  86. header = self.header.copy()
  87. url = f'https://m.youlai.cn/kp/videobydise?q={key}&page={page}&keyword={key}'
  88. r = self.fetch(url, headers=header, timeout=5)
  89. html = self.html(r.text)
  90. vodList = html.xpath("//div[contains(@class,'re-li li-video')]")
  91. videos = []
  92. for vod in vodList:
  93. sid = vod.xpath("./a/@href")[0]
  94. title = vod.xpath(".//h5/text()")[0].strip()
  95. if SequenceMatcher(None, title, key).ratio() < 0.6 and not key in title:
  96. continue
  97. img = vod.xpath(".//img/@src")[0]
  98. if not img.startswith('http'):
  99. img = 'https:' + img
  100. videos.append({
  101. "vod_id": sid,
  102. "vod_name": title,
  103. "vod_pic": img,
  104. "vod_remarks": ''
  105. })
  106. result = {'list': videos}
  107. return result
  108. def playerContent(self, flag, pid, vipFlags):
  109. result = {}
  110. result["parse"] = 0
  111. result["playUrl"] = ''
  112. result["url"] = pid
  113. result["header"] = ''
  114. return result
  115. def localProxy(self, param):
  116. return [200, "video/MP2T", {}, ""]
  117. header = {
  118. "User-Agent":"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36 Edg/116.0.1938.76"
  119. }