py_alist.py 13 KB

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