def GET(self, *t): if 'dcvideo' in se and se['dcvideo']: h = web.cookies().get('section') if logincheck(h): return '' s: str = t[0] if s is None: s = '' o = 'Download/' if 'o' in se2: o = se2['o'] if exists(o + s[1:]) and isdir(o + s[1:]): if not s.endswith('/'): web.HTTPError( '301', { 'location': quote( web.ctx.get('homepath') + web.ctx.get('path') + '/') + web.ctx.get('query') }) return '' web.header('Content-Type', 'text/html; charset=utf-8') video2 = gettemplate('video') return video2(s, se, ip, se2, str) elif exists(o + s[1:]) and isfile(o + s[1:]): fn = o + s[1:] mime = 'application/octet-stream' ex = spfn(fn)[1] if ex.lower() in mimetype: mime = mimetype[ex.lower()] web.header('Content-type', mime) et = web.ctx.env.get('HTTP_IF_NONE_MATCH') et2 = getEtag(fn) if et == et2: web.HTTPError('304') return '' else: web.header('Etag', et2) web.header('Content-Transfer-Encoding', 'BINARY') fs = getsize(fn) ran = web.ctx.env.get('HTTP_RANGE') if ran is None: web.header('Content-Length', str(fs)) return getcontentbyrange(None, fn) else: ran2 = getrange(ran) if not checkrange(ran2, fs): web.HTTPError('416') return '416 Range Not Satisfiable' else: web.header('Content-Range', DashRange(ran2, fs)) web.HTTPError('206') return getcontentbyrange(ran2, fn) else: web.HTTPError('404') HTTP404 = gettemplate('HTTP404') return HTTP404(ip, se)
def downsub(r: Session,fn: str,i: dict,ip: dict,se: dict,data: dict,pr: bool = False,pi: int = 1, width: int = None, height: int = None): "下载字幕" ass = False if JSONParser.getset(se, 'ass') == True: ass = True if 'ass' in ip: ass = ip['ass'] global lan fq=spfn(fn)[0] if not ass: fn = f"{fq}.{i['lan']}.srt" else: fn = f"{fq}.{i['lan']}.ass" i['fn']=fn if os.path.exists(fn) : fg=False bs=True if 's' in ip: fg=True bs=False if 'y' in se: fg = se['y'] bs = False if 'y' in ip : fg = ip['y'] bs = False while bs: inp=input(f'{lan["INPUT1"]}(y/n)'.replace("<filename>",fn))#"<filename>"文件已存在,是否覆盖? if len(inp)>0 : if inp[0].lower()=='y' : fg=True bs=False elif inp[0].lower()=='n' : bs=False if fg: try : os.remove('%s'%(fn)) except : print(lan['OUTPUT1'])#删除原有文件失败,跳过下载 return 0 re=r.get(i['url']) re.encoding='utf8' re=re.json() if not ass: if assrt(fn, re['body']) == 0 and pr : print(lan['OUTPUT2'].replace('<number>', str(pi)).replace('<languagename>', i['land'])) # 第<number>P<languagename>字幕下载完毕! else: if width is None: width = 1920 if height is None: height = 1080 if asass(fn, re, width, height) == 0 and pr : print(lan['OUTPUT2'].replace('<number>', str(pi)).replace('<languagename>', i['land'])) # 第<number>P<languagename>字幕下载完毕! return 0
def __writetof(self): if self.__f is None: return for s in self.__temstr: i = self.__f.write(f'{s}\n') self.__fsize = self.__fsize + i self.__tsize = self.__tsize + i if self.__fsize >= self.limit_size: fn, fd = spfn(self.__fn) self.__index = self.__index + 1 fn = f"{fn}_{self.__index}" if fd != "": fn = f"{fn}.{fd}" self.openf(fn) self.__temstr = []
def GET(self): h = web.cookies().get('section') if logincheck2(h): return '403 Forbidden' t = web.input().get('l') if not exists(t): web.HTTPError('404') return '404 Not Found' elif spfn(t)[1].lower() in mimetype: mime = mimetype[spfn(t)[1].lower()] web.header('Content-type', mime) et = web.ctx.env.get('HTTP_IF_NONE_MATCH') et2 = getEtag(t) if et == et2: web.HTTPError('304') return '' else: web.header('Etag', et2) web.header('Content-Transfer-Encoding', 'BINARY') fs = getsize(t) ran = web.ctx.env.get('HTTP_RANGE') if ran is None: web.header('Content-Length', str(fs)) return getcontentbyrange(None, t) else: ran2 = getrange(ran) if not checkrange(ran2, fs): web.HTTPError('416') return '416 Range Not Satisfiable' else: web.header('Content-Range', DashRange(ran2, fs)) web.HTTPError('206') return getcontentbyrange(ran2, t) else: web.HTTPError('400') return '400 Bad Request'
def downsub(r: Session, fn: str, i: dict, ip: dict, se: dict, pr: bool = False, pi: int = 1): "下载字幕" global lan fq = spfn(fn)[0] fn = "%s.%s.srt" % (fq, i['lan']) i['fn'] = fn if os.path.exists(fn): fg = False bs = True if 's' in ip: fg = True bs = False if 'y' in ip: if ip['y']: fg = True bs = False else: fg = False bs = False while bs: inp = input(f'{lan["INPUT1"]}(y/n)'.replace( "<filename>", fn)) #"<filename>"文件已存在,是否覆盖? if len(inp) > 0: if inp[0].lower() == 'y': fg = True bs = False elif inp[0].lower() == 'n': bs = False if fg: try: os.remove('%s' % (fn)) except: print(lan['OUTPUT1']) #删除原有文件失败,跳过下载 return 0 re = r.get(i['url']) re.encoding = 'utf8' re = re.json() if assrt(fn, re['body']) == 0 and pr: print(lan['OUTPUT2'].replace('<number>', str(pi)).replace( '<languagename>', i['land'])) #第<number>P<languagename>字幕下载完毕! return 0
def downlrc(r: Session, fn: str, i: dict, ip: dict, se: dict, data: dict,pr: bool=False, pi: int=1, nal: bool=False): global lan fq = spfn(fn)[0] if nal: fn = f"{fq}.lrc" else: fn = f"{fq}.{i['lan']}.lrc" i['fn'] = fn if os.path.exists(fn): fg = False bs = True if 's' in ip: fg = True bs = False if 'y' in se: fg = se['y'] bs = False if 'y' in ip : fg = ip['y'] bs = False while bs: inp = input(f'{lan["INPUT1"]}(y/n)'.replace("<filename>", fn)) # "<filename>"文件已存在,是否覆盖? if len(inp) > 0: if inp[0].lower() == 'y': fg = True bs = False elif inp[0].lower() == 'n': bs = False if fg: try: os.remove('%s'%(fn)) except: print(lan['OUTPUT1']) # 删除原有文件失败,跳过下载 return 0 re = r.get(i['url']) re.encoding = 'utf8' re = re.json() if aslrc(fn, re['body'], se, ip, data, pi) == 0 and pr: print(lan['OUTPUT3'].replace('<number>', str(pi)).replace('<languagename>', i['land'])) # 第<number>P<languagename>歌词下载完毕! return 0
def downsub(r: Session, fn: str, i: dict, ip: dict, se: dict, data: dict, pr: bool = False, pi: int = 1, width: int = None, height: int = None): "下载字幕" log = False logg = None if 'logg' in ip: log = True logg = ip['logg'] oll = None if 'oll' in ip: oll = ip['oll'] ass = False if JSONParser.getset(se, 'ass') is True: ass = True if 'ass' in ip: ass = ip['ass'] global lan fq = spfn(fn)[0] if not ass: fn = f"{fq}.{i['lan']}.srt" else: fn = f"{fq}.{i['lan']}.ass" if log: logg.write(f"ass = {ass}\nfn = {fn}\ni = {i}", currentframe(), "Normal Video Subtitle Download Var") i['fn'] = fn if os.path.exists(fn): fg = False bs = True if 's' in ip: fg = True bs = False if 'y' in se: fg = se['y'] bs = False if 'y' in ip: fg = ip['y'] bs = False while bs: inp = input(f'{lan["INPUT1"]}(y/n)'.replace("<filename>", fn)) # "<filename>"文件已存在,是否覆盖? if len(inp) > 0: if inp[0].lower() == 'y': fg = True bs = False elif inp[0].lower() == 'n': bs = False if fg: try: os.remove('%s' % (fn)) except: if log: logg.write(format_exc(), currentframe(), "Normal Video Subtitle Download Remove File Failed") print(lan['OUTPUT1']) # 删除原有文件失败,跳过下载 return 0 if log: logg.write(f"GET {i['url']}", currentframe(), "Normal Video Subtitle Download Request") re = r.get(i['url']) re.encoding = 'utf8' if log: logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "Normal Video Subtitle Download Result") re = re.json() if not ass: if assrt(fn, re['body'], logg) == 0: if oll: oll.add(fn) if pr: print(lan['OUTPUT2'].replace('<number>', str(pi)).replace('<languagename>', i['land'])) # 第<number>P<languagename>字幕下载完毕! else: if width is None: width = 1920 if height is None: height = 1080 if asass(fn, re, width, height, logg) == 0: if oll: oll.add(fn) if pr: print(lan['OUTPUT2'].replace('<number>', str(pi)).replace('<languagename>', i['land'])) # 第<number>P<languagename>字幕下载完毕! return 0
def downlrc(r: Session, fn: str, i: dict, ip: dict, se: dict, data: dict, pr: bool = False, pi: int = 1, nal: bool = False, isau: bool = False): log = False logg = None if 'logg' in ip: log = True logg = ip['logg'] oll = None if 'oll' in ip: oll = ip['oll'] global lan fq = spfn(fn)[0] if nal: fn = f"{fq}.lrc" else: fn = f"{fq}.{i['lan']}.lrc" if log: logg.write(f"fn = {fn}", currentframe(), "Download Lyrics Var1") i['fn'] = fn if os.path.exists(fn): fg = False bs = True if 's' in ip: fg = True bs = False if 'y' in se: fg = se['y'] bs = False if 'y' in ip: fg = ip['y'] bs = False while bs: inp = input(f'{lan["INPUT1"]}(y/n)'.replace("<filename>", fn)) # "<filename>"文件已存在,是否覆盖? if len(inp) > 0: if inp[0].lower() == 'y': fg = True bs = False elif inp[0].lower() == 'n': bs = False if fg: try: os.remove('%s' % (fn)) except: if log: logg.write(format_exc(), currentframe(), "Download Lyrics Remove File Failed") print(lan['OUTPUT1']) # 删除原有文件失败,跳过下载 return 0 if log: logg.write(f"GET {i['url']}", currentframe(), "Download Lyrics JSON") re = r.get(i['url']) re.encoding = 'utf8' if log: logg.write(f"status = {re.status_code}\n{re.text}", currentframe(), "Download Lyrics JSON Result") re = re.json() if aslrc(fn, re['body'], se, ip, data, pi, isau) == 0: if oll: oll.add(fn) if not isau and pr: print(lan['OUTPUT3'].replace('<number>', str(pi)).replace('<languagename>', i['land'])) # 第<number>P<languagename>歌词下载完毕! elif pr: print(lan['AULRCCOM'].replace('<languagename>', i['land'])) return 0