py_alist.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 re
  8. import difflib
  9. import urllib
  10. class Spider(Spider): # 元类 默认的元类 type
  11. def getName(self):
  12. return "Alist"
  13. def init(self, extend=""):
  14. print("============{0}============".format(extend))
  15. pass
  16. def isVideoFormat(self, url):
  17. pass
  18. def manualVideoCheck(self):
  19. pass
  20. def homeContent(self, filter):
  21. result = {}
  22. cateManual = {
  23. "丫仙女": "http://alist.xiaoya.pro/",
  24. "七米蓝": "https://al.chirmyram.com/",
  25. "梅花盘": "https://pan.142856.xyz/OneDrive",
  26. "触光云盘": "https://pan.ichuguang.com",
  27. # "小孟资源": "https://8023.haohanba.cn/小孟丨资源大合集/无损音乐",
  28. "资源小站": "https://960303.xyz/ali",
  29. "轻弹浅唱": "https://g.xiang.lol",
  30. "小兵组网盘视频": "https://6vv.app",
  31. # "wenwen": "http://518p8g7316.goho.co:5244",
  32. }
  33. classes = []
  34. for k in cateManual:
  35. classes.append({
  36. 'type_name': k,
  37. "type_flag": "1",
  38. 'type_id': cateManual[k]
  39. })
  40. result['class'] = classes
  41. if (filter):
  42. result['filters'] = self.config['filter']
  43. return result
  44. def homeVideoContent(self):
  45. result = {
  46. 'list': []
  47. }
  48. return result
  49. ver = ''
  50. baseurl = ''
  51. def getVersion(self, gtid):
  52. param = {
  53. "path": '/'
  54. }
  55. if gtid.count('/') == 2:
  56. gtid = gtid + '/'
  57. baseurl = re.findall(r"http.*://.*?/", gtid)[0]
  58. ver = self.fetch(baseurl + 'api/public/settings', param)
  59. vjo = json.loads(ver.text)['data']
  60. if type(vjo) is dict:
  61. ver = 3
  62. else:
  63. ver = 2
  64. self.ver = ver
  65. self.baseurl = baseurl
  66. def categoryContent(self, tid, pg, filter, extend):
  67. result = {}
  68. if tid.count('/') == 2:
  69. tid = tid + '/'
  70. nurl = re.findall(r"http.*://.*?/", tid)[0]
  71. if self.ver == '' or self.baseurl != nurl:
  72. self.getVersion(tid)
  73. ver = self.ver
  74. baseurl = self.baseurl
  75. if tid.count('/') == 2:
  76. tid = tid + '/'
  77. pat = tid.replace(baseurl,"")
  78. param = {
  79. "path": '/' + pat
  80. }
  81. if ver == 2:
  82. rsp = self.postJson(baseurl + 'api/public/path', param)
  83. jo = json.loads(rsp.text)
  84. vodList = jo['data']['files']
  85. elif ver == 3:
  86. rsp = self.postJson(baseurl + 'api/fs/list', param)
  87. jo = json.loads(rsp.text)
  88. vodList = jo['data']['content']
  89. videos = []
  90. cid = ''
  91. for vod in vodList:
  92. if ver == 2:
  93. img = vod['thumbnail']
  94. elif ver == 3:
  95. img = vod['thumb']
  96. if len(img) == 0:
  97. if vod['type'] == 1:
  98. img = "http://img1.3png.com/281e284a670865a71d91515866552b5f172b.png"
  99. if pat != '':
  100. aid = pat + '/'
  101. else:
  102. aid = pat
  103. if vod['type'] == 1:
  104. tag = "folder"
  105. remark = "文件夹"
  106. cid = baseurl + aid + vod['name']
  107. #计算文件大小
  108. else:
  109. size = vod['size']
  110. if size > 1024 * 1024 * 1024 * 1024.0:
  111. fs = "TB"
  112. sz = round(size / (1024 * 1024 * 1024 * 1024.0), 2)
  113. elif size > 1024 * 1024 * 1024.0:
  114. fs = "GB"
  115. sz = round(size / (1024 * 1024 * 1024.0), 2)
  116. elif size > 1024 * 1024.0:
  117. fs = "MB"
  118. sz = round(size / (1024 * 1024.0), 2)
  119. elif size > 1024.0:
  120. fs = "KB"
  121. sz = round(size / (1024.0), 2)
  122. else:
  123. fs = "KB"
  124. sz = round(size / (1024.0), 2)
  125. tag = "file"
  126. remark = str(sz) + fs
  127. # 开始爬视频与字幕
  128. srtvodList = str(vodList)
  129. foldernum = srtvodList.count('\'type\': 1')
  130. filename = len(vodList) - foldernum
  131. if filename < 60:
  132. if 'mp4' in vod['name'] or 'mkv' in vod['name'] or 'TS' in vod['name'] or 'flv' in vod[
  133. 'name'] or 'rmvb' in vod['name'] or 'mp3' in vod['name'] or 'flac' in vod['name'] or 'wav' in \
  134. vod['name'] or 'wma' in vod['name'] or 'wma' in vod['name']:
  135. cid = ''
  136. for temvod in vodList:
  137. if 'mp4' in temvod['name'] or 'mkv' in temvod['name'] or 'TS' in temvod['name'] or 'flv' in \
  138. temvod['name'] or 'rmvb' in temvod['name'] or 'mp3' in temvod['name'] or 'flac' in \
  139. temvod['name'] or 'wav' in temvod['name'] or 'wma' in temvod['name'] or 'wma' in \
  140. temvod['name']:
  141. vurl = baseurl + aid + temvod['name']
  142. # 开始爬字幕
  143. subname = re.findall(r"(.*)\.", temvod['name'])[0]
  144. substr = re.findall(r"\'name\': \'(.*?)\'", str(vodList))
  145. if len(substr) == 2:
  146. suball = substr
  147. else:
  148. suball = difflib.get_close_matches(subname, substr, len(vodList), cutoff=0.8)
  149. for sub in suball:
  150. if sub.endswith(".ass") or sub.endswith(".srt"):
  151. subt = '@@@' + baseurl + aid + sub
  152. ifsubt = 'subt' in locals().keys()
  153. if ifsubt is False:
  154. cid = cid + '{0}${1}#'.format(temvod['name'], vurl)
  155. else:
  156. cid = cid + '{0}${1}{2}#'.format(temvod['name'], vurl, subt)
  157. else:
  158. cid = cid
  159. if cid == '':
  160. cid = baseurl + aid + vod['name']
  161. else:
  162. subname = re.findall(r"(.*)\.", vod['name'])[0]
  163. substr = re.findall(r"\'name\': \'(.*?)\'", str(vodList))
  164. if subname + '.ass' in substr:
  165. subt = '@@@' + baseurl + aid + subname + '.ass'
  166. cid = baseurl + aid + vod['name'] + subt
  167. elif subname + '.srt' in substr:
  168. subt = '@@@' + baseurl + aid + subname + '.srt'
  169. cid = baseurl + aid + vod['name'] + subt
  170. else:
  171. cid = baseurl + aid + vod['name']
  172. videos.append({
  173. "vod_id": cid,
  174. "vod_name": vod['name'],
  175. "vod_pic": img,
  176. "vod_tag": tag,
  177. "vod_remarks": remark
  178. })
  179. result['list'] = videos
  180. result['page'] = 1
  181. result['pagecount'] = 1
  182. result['limit'] = 999
  183. result['total'] = 999999
  184. return result
  185. def detailContent(self, array):
  186. id = array[0]
  187. if '$' in id:
  188. ids = id.split('$')[1].split('#')[0].split('@@@')
  189. url = ids[0]
  190. else:
  191. url = id
  192. if self.ver == '' or self.baseurl == '':
  193. self.getVersion(url)
  194. baseurl = self.baseurl
  195. if '$' in id:
  196. vid = re.findall(r"(.*)/", url.replace(baseurl, ""))[0].replace(baseurl, "")
  197. else:
  198. vid = url.replace(re.findall(r".*/", url)[0], "")
  199. id = vid + '$' + id
  200. vod = {
  201. "vod_id": vid,
  202. "vod_name": vid,
  203. "vod_pic": '',
  204. "vod_tag": '',
  205. "vod_play_from": "播放",
  206. "vod_play_url": id
  207. }
  208. result = {
  209. 'list': [
  210. vod
  211. ]
  212. }
  213. return result
  214. def searchContent(self, key, quick):
  215. result = {
  216. 'list': []
  217. }
  218. return result
  219. def playerContent(self, flag, id, vipFlags):
  220. result = {}
  221. ifsub = '@@@' in id
  222. if ifsub is True:
  223. ids = id.split('@@@')
  224. if self.ver == '' or self.baseurl == '':
  225. self.getVersion(ids[1])
  226. ver = self.ver
  227. baseurl = self.baseurl
  228. fileName = ids[1].replace(baseurl, "")
  229. vfileName = ids[0].replace(baseurl, "")
  230. param = {
  231. "path": '/' + fileName,
  232. "password": "",
  233. "page_num": 1,
  234. "page_size": 100
  235. }
  236. vparam = {
  237. "path": '/' + vfileName,
  238. "password": "",
  239. "page_num": 1,
  240. "page_size": 100
  241. }
  242. if ver == 2:
  243. rsp = self.postJson(baseurl + 'api/public/path', param)
  244. jo = json.loads(rsp.text)
  245. vodList = jo['data']['files'][0]
  246. subturl = vodList['url']
  247. vrsp = self.postJson(baseurl + 'api/public/path', vparam)
  248. vjo = json.loads(vrsp.text)
  249. vList = vjo['data']['files'][0]
  250. url = vList['url']
  251. elif ver == 3:
  252. rsp = self.postJson(baseurl + 'api/fs/get', param)
  253. jo = json.loads(rsp.text)
  254. vodList = jo['data']
  255. subturl = vodList['raw_url']
  256. vrsp = self.postJson(baseurl + 'api/fs/get', vparam)
  257. vjo = json.loads(vrsp.text)
  258. vList = vjo['data']
  259. url = vList['raw_url']
  260. if subturl.startswith('http') is False:
  261. head = re.findall(r"h.*?:", baseurl)[0]
  262. subturl = head + subturl
  263. if url.startswith('http') is False:
  264. head = re.findall(r"h.*?:", baseurl)[0]
  265. url = head + url
  266. urlfileName = urllib.parse.quote(fileName)
  267. subturl = subturl.replace(fileName, urlfileName)
  268. urlvfileName = urllib.parse.quote(vfileName)
  269. url = url.replace(vfileName, urlvfileName)
  270. result['subt'] = subturl
  271. else:
  272. if self.ver == '' or self.baseurl == '':
  273. self.getVersion(id)
  274. ver = self.ver
  275. baseurl = self.baseurl
  276. vfileName = id.replace(baseurl, "")
  277. vparam = {
  278. "path": '/' + vfileName,
  279. "password": "",
  280. "page_num": 1,
  281. "page_size": 100
  282. }
  283. if ver == 2:
  284. vrsp = self.postJson(baseurl + 'api/public/path', vparam)
  285. vjo = json.loads(vrsp.text)
  286. vList = vjo['data']['files'][0]
  287. driver = vList['driver']
  288. url = vList['url']
  289. elif ver == 3:
  290. vrsp = self.postJson(baseurl + 'api/fs/get', vparam)
  291. vjo = json.loads(vrsp.text)
  292. vList = vjo['data']
  293. url = vList['raw_url']
  294. driver = vList['provider']
  295. if url.startswith('http') is False:
  296. head = re.findall(r"h.*?:", baseurl)[0]
  297. url = head + url
  298. urlvfileName = urllib.parse.quote(vfileName)
  299. url = url.replace(vfileName, urlvfileName)
  300. if driver == 'Baidu.Disk':
  301. result["header"] = {"User-Agent": "pan.baidu.com"}
  302. result["parse"] = 0
  303. result["playUrl"] = ''
  304. result["url"] = url
  305. return result
  306. config = {
  307. "player": {},
  308. "filter": {}
  309. }
  310. header = {}
  311. def localProxy(self, param):
  312. return [200, "video/MP2T", action, ""]