0925py_alist.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. "小雅": "http://43.139.29.179:5244",
  23. "七米蓝": "https://al.chirmyram.com",
  24. "梅花盘": "https://pan.142856.xyz/OneDrive",
  25. "触光云盘": "https://pan.ichuguang.com",
  26. "小孟资源": "https://8023.haohanba.cn/小孟丨资源大合集/无损音乐",
  27. "资源小站": "https://960303.xyz/ali",
  28. "轻弹浅唱": "https://g.xiang.lol",
  29. "小兵组网盘视频": "https://6vv.app"
  30. }
  31. classes = []
  32. for k in cateManual:
  33. classes.append({
  34. 'type_name': k,
  35. "type_flag": "1",
  36. 'type_id': cateManual[k]
  37. })
  38. result['class'] = classes
  39. if (filter):
  40. result['filters'] = self.config['filter']
  41. return result
  42. def homeVideoContent(self):
  43. result = {
  44. 'list': []
  45. }
  46. return result
  47. ver = ''
  48. baseurl = ''
  49. def getVersion(self, gtid):
  50. param = {
  51. "path": '/'
  52. }
  53. if gtid.count('/') == 2:
  54. gtid = gtid + '/'
  55. baseurl = re.findall(r"http.*://.*?/", gtid)[0]
  56. ver = self.fetch(baseurl + 'api/public/settings', param)
  57. vjo = json.loads(ver.text)['data']
  58. if type(vjo) is dict:
  59. ver = 3
  60. else:
  61. ver = 2
  62. self.ver = ver
  63. self.baseurl = baseurl
  64. def categoryContent(self, tid, pg, filter, extend):
  65. result = {}
  66. if tid.count('/') == 2:
  67. tid = tid + '/'
  68. nurl = re.findall(r"http.*://.*?/", tid)[0]
  69. if self.ver == '' or self.baseurl != nurl:
  70. self.getVersion(tid)
  71. ver = self.ver
  72. baseurl = self.baseurl
  73. if tid.count('/') == 2:
  74. tid = tid + '/'
  75. pat = tid.replace(baseurl,"")
  76. param = {
  77. "path": '/' + pat
  78. }
  79. if ver == 2:
  80. rsp = self.postJson(baseurl + 'api/public/path', param)
  81. jo = json.loads(rsp.text)
  82. vodList = jo['data']['files']
  83. elif ver == 3:
  84. rsp = self.postJson(baseurl + 'api/fs/list', param)
  85. jo = json.loads(rsp.text)
  86. vodList = jo['data']['content']
  87. videos = []
  88. cid = ''
  89. purl = ''
  90. svodList = str(vodList)
  91. lenvodList = len(vodList)
  92. substr = str(re.findall(r"\'name\': \'(.*?)\'", svodList))
  93. foldernum = svodList.count('\'type\': 1')
  94. filenum = lenvodList - foldernum
  95. for vod in vodList:
  96. if ver == 2:
  97. img = vod['thumbnail']
  98. elif ver == 3:
  99. img = vod['thumb']
  100. if len(img) == 0:
  101. if vod['type'] == 1:
  102. img = "http://img1.3png.com/281e284a670865a71d91515866552b5f172b.png"
  103. if pat != '':
  104. aid = pat + '/'
  105. else:
  106. aid = pat
  107. if vod['type'] == 1:
  108. tag = "folder"
  109. remark = "文件夹"
  110. cid = baseurl + aid + vod['name']
  111. #计算文件大小
  112. else:
  113. size = vod['size']
  114. if size > 1024 * 1024 * 1024 * 1024.0:
  115. fs = "TB"
  116. sz = round(size / (1024 * 1024 * 1024 * 1024.0), 2)
  117. elif size > 1024 * 1024 * 1024.0:
  118. fs = "GB"
  119. sz = round(size / (1024 * 1024 * 1024.0), 2)
  120. elif size > 1024 * 1024.0:
  121. fs = "MB"
  122. sz = round(size / (1024 * 1024.0), 2)
  123. elif size > 1024.0:
  124. fs = "KB"
  125. sz = round(size / (1024.0), 2)
  126. else:
  127. fs = "KB"
  128. sz = round(size / (1024.0), 2)
  129. tag = "file"
  130. remark = str(sz) + fs
  131. cid = baseurl + aid + vod['name']
  132. # 开始爬视频与字幕
  133. if filenum < 150:
  134. 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']:
  135. vodurl = vod['name']
  136. # 开始爬字幕
  137. cid = '###'
  138. subname = re.findall(r"(.*)\.", vod['name'])[0]
  139. if filenum == 2:
  140. if '.ass' in substr:
  141. sub = re.findall(r"'(.*).ass", substr)[0]
  142. subt = '@@@' + sub + '.ass'
  143. if ',' in sub:
  144. sub = re.findall(r"', '(.*).ass", substr)[0]
  145. subt = '@@@' + sub + '.ass'
  146. if '.srt' in substr:
  147. sub = re.findall(r"'(.*).srt", substr)[0]
  148. subt = '@@@' + sub + '.srt'
  149. if ',' in sub:
  150. sub = re.findall(r"', '(.*).srt", substr)[0]
  151. subt = '@@@' + sub + '.srt'
  152. else:
  153. if subname + '.ass' in substr:
  154. subt = '@@@' + subname + '.ass'
  155. elif subname + '.srt' in substr:
  156. subt = '@@@' + subname + '.srt'
  157. # 合并链接
  158. if 'subt' in locals().keys():
  159. purl = purl + '{0}{1}#'.format(vodurl, subt)
  160. else:
  161. purl = purl + '{0}#'.format(vodurl)
  162. else:
  163. subname = re.findall(r"(.*)\.", vod['name'])[0]
  164. if subname + '.ass' in substr:
  165. subt = '@@@' + subname + '.ass'
  166. cid = cid + subt
  167. elif subname + '.srt' in substr:
  168. subt = '@@@' + subname + '.srt'
  169. cid = cid + subt
  170. videos.append({
  171. "vod_id": cid,
  172. "vod_name": vod['name'],
  173. "vod_pic": img,
  174. "vod_tag": tag,
  175. "vod_remarks": remark
  176. })
  177. if 'purl' in locals().keys():
  178. purl = baseurl + aid + '+++' + purl
  179. for i in range(foldernum, lenvodList):
  180. if videos[i]['vod_id'] == '###':
  181. videos[i]['vod_id'] = purl
  182. result['list'] = videos
  183. result['page'] = 1
  184. result['pagecount'] = 1
  185. result['limit'] = 999
  186. result['total'] = 999999
  187. return result
  188. def detailContent(self, array):
  189. id = array[0]
  190. if '+++' in id:
  191. ids = id.split('+++')
  192. durl = ids[0]
  193. vsList = ids[1].strip('#').split('#')
  194. vsurl = ''
  195. for vs in vsList:
  196. if '@@@' in vs:
  197. dvs = vs.split('@@@')
  198. vname = dvs[0]
  199. vurl = durl + dvs[0]
  200. surl = durl + dvs[1]
  201. vsurl = vsurl + '{0}${1}@@@{2}#'.format(vname, vurl, surl)
  202. else:
  203. vurl = durl + vs
  204. vsurl = vsurl + '{0}${1}#'.format(vs, vurl)
  205. url = vsurl
  206. else:
  207. durl = id
  208. if self.ver == '' or self.baseurl == '':
  209. self.getVersion(durl)
  210. baseurl = self.baseurl
  211. if '+++' in id:
  212. vid = durl.replace(baseurl, "").strip('/')
  213. else:
  214. vid = durl.replace(re.findall(r".*/", durl)[0], "")
  215. url = vid + '$' + id
  216. vod = {
  217. "vod_id": vid,
  218. "vod_name": vid,
  219. "vod_pic": '',
  220. "vod_tag": '',
  221. "vod_play_from": "播放",
  222. "vod_play_url": url
  223. }
  224. result = {
  225. 'list': [
  226. vod
  227. ]
  228. }
  229. return result
  230. def searchContent(self, key, quick):
  231. result = {
  232. 'list': []
  233. }
  234. return result
  235. def playerContent(self, flag, id, vipFlags):
  236. result = {}
  237. url = ''
  238. subturl = ''
  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, ""]