py_alist.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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 urllib
  9. import difflib
  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. "🔮嗨翻":"https://pan.hikerfans.com",
  24. "🦀9T(Adult)":"https://drive.9t.ee",
  25. "🐱梓澪の妙妙屋":"https://xn--i0v44m.xyz",
  26. "🚆资源小站":"https://pan.142856.xyz",
  27. "🌤晴园的宝藏库":"https://alist.52qy.repl.co",
  28. "🐭米奇妙妙屋":"https://anime.mqmmw.ga",
  29. "💂小兵组网盘影视":"https://6vv.app",
  30. "📀小光盘":"https://alist.xiaoguanxiaocheng.life",
  31. "🐋一只鱼":"https://alist.youte.ml",
  32. "🌊七米蓝":"https://al.chirmyram.com",
  33. "🌴非盘":"http://www.feifwp.top",
  34. "🥼帅盘":"https://hi.shuaipeng.wang",
  35. "🐉神族九帝":"https://alist.shenzjd.com",
  36. "☃姬路白雪":"https://pan.jlbx.xyz",
  37. "🎧听闻网盘":"https://wangpan.sangxuesheng.com",
  38. "💾DISK":"http://124.222.140.243:8080",
  39. "🌨云播放":"https://quanzi.laoxianghuijia.cn",
  40. "✨星梦":"https://pan.bashroot.top",
  41. "🌊小江":"https://dyj.me",
  42. "💫触光":"https://pan.ichuguang.com",
  43. "🕵好汉吧":"https://8023.haohanba.cn",
  44. "🥗AUNEY":"http://121.227.25.116:8008",
  45. "🎡资源小站":"https://960303.xyz/",
  46. "🐝神器云": "https://quanzi.laoxianghuijia.cn",
  47. "🏝fenwe":"http://www.fenwe.tk:5244",
  48. "🎢轻弹浅唱":"https://g.xiang.lol"
  49. }
  50. classes = []
  51. for k in cateManual:
  52. classes.append({
  53. 'type_name': k,
  54. "type_flag": "1",
  55. 'type_id': cateManual[k]
  56. })
  57. result['class'] = classes
  58. if (filter):
  59. filters = {}
  60. for lk in cateManual:
  61. link = cateManual[lk]
  62. filters.update({
  63. link: [{"key": "nm", "name": "名 称", "value": [{"n": "复位", "v": ""},{"n": "正序", "v": "False"},{"n": "反序", "v": "True"}]},{"key": "sz", "name": "大 小", "value": [{"n": "复位", "v": ""},{"n": "升序", "v": "False"},{"n": "降序", "v": "True"}]},{"key": "tp", "name": "类 型", "value": [{"n": "复位", "v": ""},{"n": "升序", "v": "False"},{"n": "降序", "v": "True"}]},{"key": "tm", "name": "修改时间", "value": [{"n": "复位", "v": ""},{"n": "升序", "v": "False"},{"n": "降序", "v": "True"}]}]
  64. })
  65. result['filters'] = filters
  66. return result
  67. def homeVideoContent(self):
  68. result = {
  69. 'list': []
  70. }
  71. return result
  72. ver = ''
  73. baseurl = ''
  74. def getVersion(self, gtid):
  75. param = {
  76. "path": '/'
  77. }
  78. if gtid.count('/') == 2:
  79. gtid = gtid + '/'
  80. baseurl = re.findall(r"http.*://.*?/", gtid)[0]
  81. ver = self.fetch(baseurl + 'api/public/settings', param)
  82. vjo = json.loads(ver.text)['data']
  83. if type(vjo) is dict:
  84. ver = 3
  85. else:
  86. ver = 2
  87. self.ver = ver
  88. self.baseurl = baseurl
  89. def categoryContent(self, tid, pg, filter, extend):
  90. result = {}
  91. if tid.count('/') == 2:
  92. tid = tid + '/'
  93. nurl = re.findall(r"http.*://.*?/", tid)[0]
  94. if self.ver == '' or self.baseurl != nurl:
  95. self.getVersion(tid)
  96. ver = self.ver
  97. baseurl = self.baseurl
  98. if tid.count('/') == 2:
  99. tid = tid + '/'
  100. pat = tid.replace(baseurl,"")
  101. param = {
  102. "path": '/' + pat
  103. }
  104. if ver == 2:
  105. rsp = self.postJson(baseurl + 'api/public/path', param)
  106. jo = json.loads(rsp.text)
  107. vodList = jo['data']['files']
  108. elif ver == 3:
  109. rsp = self.postJson(baseurl + 'api/fs/list', param)
  110. jo = json.loads(rsp.text)
  111. vodList = jo['data']['content']
  112. ovodList = vodList
  113. if len(extend) != 0:
  114. if 'tp' in extend and extend['tp'] != '':
  115. fl = 'type'
  116. if extend['tp'] == "True":
  117. key = True
  118. if extend['tp'] == "False":
  119. key = False
  120. vodList.sort(key=lambda x: (x['{0}'.format(fl)]), reverse=key)
  121. elif 'sz' in extend and extend['sz'] != '':
  122. fl = 'size'
  123. if extend['sz'] == "True":
  124. key = True
  125. if extend['sz'] == "False":
  126. key = False
  127. vodList.sort(key=lambda x: (x['{0}'.format(fl)]), reverse=key)
  128. elif 'nm' in extend and extend['nm'] != '':
  129. fl = 'name'
  130. if extend['nm'] == "True":
  131. key = True
  132. if extend['nm'] == "False":
  133. key = False
  134. vodList.sort(key=lambda x: (x['{0}'.format(fl)]), reverse=key)
  135. elif 'tm' in extend and extend['tm'] != '':
  136. if ver == 2:
  137. fl = 'updated_at'
  138. elif ver == 3:
  139. fl = 'modified'
  140. if extend['tm'] == "True":
  141. key = True
  142. if extend['tm'] == "False":
  143. key = False
  144. vodList.sort(key=lambda x: (x['{0}'.format(fl)]), reverse=key)
  145. else:
  146. vodList = ovodList
  147. else:
  148. vodList = ovodList
  149. videos = []
  150. cid = ''
  151. purl = ''
  152. svodList = str(vodList)
  153. lenvodList = len(vodList)
  154. nameList = re.findall(r"\'name\': \'(.*?)\'", svodList)
  155. substr = str(nameList)
  156. foldernum = svodList.count('\'type\': 1')
  157. filenum = lenvodList - foldernum
  158. for vod in vodList:
  159. if ver == 2:
  160. img = vod['thumbnail']
  161. elif ver == 3:
  162. img = vod['thumb']
  163. if len(img) == 0:
  164. if vod['type'] == 1:
  165. img = "http://img1.3png.com/281e284a670865a71d91515866552b5f172b.png"
  166. if pat != '':
  167. aid = pat + '/'
  168. else:
  169. aid = pat
  170. if vod['type'] == 1:
  171. tag = "folder"
  172. remark = "文件夹"
  173. cid = baseurl + aid + vod['name']
  174. #计算文件大小
  175. else:
  176. size = vod['size']
  177. if size > 1024 * 1024 * 1024 * 1024.0:
  178. fs = "TB"
  179. sz = round(size / (1024 * 1024 * 1024 * 1024.0), 2)
  180. elif size > 1024 * 1024 * 1024.0:
  181. fs = "GB"
  182. sz = round(size / (1024 * 1024 * 1024.0), 2)
  183. elif size > 1024 * 1024.0:
  184. fs = "MB"
  185. sz = round(size / (1024 * 1024.0), 2)
  186. elif size > 1024.0:
  187. fs = "KB"
  188. sz = round(size / (1024.0), 2)
  189. else:
  190. fs = "KB"
  191. sz = round(size / (1024.0), 2)
  192. tag = "file"
  193. remark = str(sz) + fs
  194. cid = baseurl + aid + vod['name']
  195. # 开始爬视频与字幕
  196. if filenum < 150:
  197. if vod['name'].endswith('.mp4') or vod['name'].endswith('.mkv') or vod['name'].endswith('.ts') or vod['name'].endswith('.TS') or vod['name'].endswith('.avi') or vod['name'].endswith('.flv') or vod['name'].endswith('.rmvb') or vod['name'].endswith('.mp3') or vod['name'].endswith('.flac') or vod['name'].endswith('.wav') or vod['name'].endswith('.wma') or vod['name'].endswith('.dff'):
  198. vodurl = vod['name']
  199. # 开始爬字幕
  200. cid = '###'
  201. subname = re.findall(r"(.*)\.", vod['name'])[0]
  202. if filenum == 2:
  203. if '.ass' in substr:
  204. sub = difflib.get_close_matches('.ass', nameList, 1, cutoff=0.1)
  205. if len(sub) != 0:
  206. sub = sub[0]
  207. else:
  208. sub = ''
  209. if sub.endswith('.ass'):
  210. subt = '@@@' + sub
  211. if '.srt' in substr:
  212. sub = difflib.get_close_matches('.srt', nameList, 1, cutoff=0.1)
  213. if len(sub) != 0:
  214. sub = sub[0]
  215. else:
  216. sub = ''
  217. if sub.endswith('.srt'):
  218. subt = '@@@' + sub
  219. else:
  220. if '.ass' in substr:
  221. sub = difflib.get_close_matches('{0}.ass'.format(subname), nameList, 1, cutoff=0.1)
  222. if len(sub) != 0:
  223. sub = sub[0]
  224. else:
  225. sub = ''
  226. if subname in sub and sub.endswith('.ass'):
  227. subt = '@@@' + sub
  228. elif '.srt' in substr:
  229. sub = difflib.get_close_matches('{0}.srt'.format(subname), nameList, 1, cutoff=0.1)
  230. if len(sub) != 0:
  231. sub = sub[0]
  232. else:
  233. sub = ''
  234. if subname in sub and sub.endswith('.srt'):
  235. subt = '@@@' + sub
  236. # 合并链接
  237. if 'subt' in locals().keys():
  238. purl = purl + '{0}{1}##'.format(vodurl, subt)
  239. else:
  240. purl = purl + '{0}##'.format(vodurl)
  241. else:
  242. subname = re.findall(r"(.*)\.", vod['name'])[0]
  243. if '.ass' in substr:
  244. sub = difflib.get_close_matches('{0}.ass'.format(subname), nameList, 1, cutoff=0.1)
  245. if len(sub) != 0:
  246. sub = sub[0]
  247. else:
  248. sub = ''
  249. if subname in sub and sub.endswith('.ass'):
  250. subt = '@@@' + sub
  251. cid = cid + subt
  252. elif '.srt' in substr:
  253. sub = difflib.get_close_matches('{0}.srt'.format(subname), nameList, 1, cutoff=0.1)
  254. if len(sub) != 0:
  255. sub = sub[0]
  256. else:
  257. sub = ''
  258. if subname in sub and sub.endswith('.srt'):
  259. subt = '@@@' + sub
  260. cid = cid + subt
  261. videos.append({
  262. "vod_id": cid,
  263. "vod_name": vod['name'],
  264. "vod_pic": img,
  265. "vod_tag": tag,
  266. "vod_remarks": remark
  267. })
  268. if 'purl' in locals().keys():
  269. purl = baseurl + aid + '+++' + purl
  270. for i in range(foldernum, lenvodList):
  271. if videos[i]['vod_id'] == '###':
  272. videos[i]['vod_id'] = purl
  273. result['list'] = videos
  274. result['page'] = 1
  275. result['pagecount'] = 1
  276. result['limit'] = lenvodList
  277. result['total'] = lenvodList
  278. return result
  279. def detailContent(self, array):
  280. id = array[0]
  281. if '+++' in id:
  282. ids = id.split('+++')
  283. durl = ids[0]
  284. vsList = ids[1].strip('##').split('##')
  285. vsurl = ''
  286. for vs in vsList:
  287. if '@@@' in vs:
  288. dvs = vs.split('@@@')
  289. vname = dvs[0].replace('#','-')
  290. vurl = durl + dvs[0].replace('#','---')
  291. surl = durl + dvs[1].replace('#','---')
  292. vsurl = vsurl + '{0}${1}@@@{2}#'.format(vname, vurl, surl)
  293. else:
  294. vurl = durl + vs.replace('#','---')
  295. vsurl = vsurl + '{0}${1}#'.format(vs.replace('#','-'), vurl)
  296. url = vsurl
  297. else:
  298. durl = id.replace('#','-')
  299. if self.ver == '' or self.baseurl == '':
  300. self.getVersion(durl)
  301. baseurl = self.baseurl
  302. if '+++' in id:
  303. vid = durl.replace(baseurl, "").strip('/')
  304. else:
  305. vid = durl.replace(re.findall(r".*/", durl)[0], "")
  306. url = vid + '$' + id.replace('#','---')
  307. vod = {
  308. "vod_id": vid,
  309. "vod_name": vid,
  310. "vod_pic": '',
  311. "vod_tag": '',
  312. "vod_play_from": "播放",
  313. "vod_play_url": url
  314. }
  315. result = {
  316. 'list': [
  317. vod
  318. ]
  319. }
  320. return result
  321. def searchContent(self, key, quick):
  322. result = {
  323. 'list': []
  324. }
  325. return result
  326. def playerContent(self, flag, id, vipFlags):
  327. result = {}
  328. url = ''
  329. subturl = ''
  330. id = id.replace('---','#')
  331. ifsub = '@@@' in id
  332. if ifsub is True:
  333. ids = id.split('@@@')
  334. if self.ver == '' or self.baseurl == '':
  335. self.getVersion(ids[1])
  336. ver = self.ver
  337. baseurl = self.baseurl
  338. fileName = ids[1].replace(baseurl, "")
  339. vfileName = ids[0].replace(baseurl, "")
  340. param = {
  341. "path": '/' + fileName,
  342. "password": "",
  343. "page_num": 1,
  344. "page_size": 100
  345. }
  346. vparam = {
  347. "path": '/' + vfileName,
  348. "password": "",
  349. "page_num": 1,
  350. "page_size": 100
  351. }
  352. if ver == 2:
  353. rsp = self.postJson(baseurl + 'api/public/path', param)
  354. jo = json.loads(rsp.text)
  355. vodList = jo['data']['files'][0]
  356. subturl = vodList['url']
  357. vrsp = self.postJson(baseurl + 'api/public/path', vparam)
  358. vjo = json.loads(vrsp.text)
  359. vList = vjo['data']['files'][0]
  360. url = vList['url']
  361. elif ver == 3:
  362. rsp = self.postJson(baseurl + 'api/fs/get', param)
  363. jo = json.loads(rsp.text)
  364. vodList = jo['data']
  365. subturl = vodList['raw_url']
  366. vrsp = self.postJson(baseurl + 'api/fs/get', vparam)
  367. vjo = json.loads(vrsp.text)
  368. vList = vjo['data']
  369. url = vList['raw_url']
  370. if subturl.startswith('http') is False:
  371. head = re.findall(r"h.*?:", baseurl)[0]
  372. subturl = head + subturl
  373. if url.startswith('http') is False:
  374. head = re.findall(r"h.*?:", baseurl)[0]
  375. url = head + url
  376. urlfileName = urllib.parse.quote(fileName)
  377. subturl = subturl.replace(fileName, urlfileName)
  378. urlvfileName = urllib.parse.quote(vfileName)
  379. url = url.replace(vfileName, urlvfileName)
  380. result['subt'] = subturl
  381. else:
  382. if self.ver == '' or self.baseurl == '':
  383. self.getVersion(id)
  384. ver = self.ver
  385. baseurl = self.baseurl
  386. vfileName = id.replace(baseurl, "")
  387. vparam = {
  388. "path": '/' + vfileName,
  389. "password": "",
  390. "page_num": 1,
  391. "page_size": 100
  392. }
  393. if ver == 2:
  394. vrsp = self.postJson(baseurl + 'api/public/path', vparam)
  395. vjo = json.loads(vrsp.text)
  396. vList = vjo['data']['files'][0]
  397. driver = vList['driver']
  398. url = vList['url']
  399. elif ver == 3:
  400. vrsp = self.postJson(baseurl + 'api/fs/get', vparam)
  401. vjo = json.loads(vrsp.text)
  402. vList = vjo['data']
  403. url = vList['raw_url']
  404. driver = vList['provider']
  405. if url.startswith('http') is False:
  406. head = re.findall(r"h.*?:", baseurl)[0]
  407. url = head + url
  408. urlvfileName = urllib.parse.quote(vfileName)
  409. url = url.replace(vfileName, urlvfileName)
  410. if driver == 'Baidu.Disk':
  411. result["header"] = {"User-Agent": "pan.baidu.com"}
  412. result["parse"] = 0
  413. result["playUrl"] = ''
  414. result["url"] = url
  415. return result
  416. flurl = ''
  417. config = {
  418. "player": {},
  419. "filter": {}
  420. }
  421. header = {}
  422. def localProxy(self, param):
  423. return [200, "video/MP2T", action, ""]