py_alist1.py 13 KB

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