py_alist.py 13 KB

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