示例#1
0
def gopt(args, d: bool = False):
    re = getopt(args, 'h?i:d:p:m:r:ynFv:a:o:s', [
        'help', 'ac=', 'dm=', 'ad=', 'yf', 'nf', 'mc=', 'ar', 'nar', 'ax=',
        'as=', 'ak=', 'ab', 'nab', 'fa=', 'sv=', 'ma=', 'ms=', 'da=',
        'httpproxy=', 'httpsproxy=', 'jt=', 'jts=', 'af', 'naf', 'afp=', 'slt',
        'nslt', 'te', 'nte', 'bd', 'nbd', 'cad', 'ncad', 'lrh', 'nlrh', 'ym',
        'nm', 'yac', 'nac', 'ydm', 'ndm', 'yad', 'nad', 'yr', 'nr', 'ysv',
        'nsv', 'yma', 'nma', 'yda', 'nda', 'ahttpproxy=', 'ahttpsproxy=',
        'lan=', 'bp', 'nbp', 'in', 'nin', 'mt', 'nmt', 'vi=', 'uc', 'nuc',
        'ass', 'nass', 'dmp', 'ndmp', 'vf=', 'lmd=', 'ynal', 'nnal', 'log',
        'nlog', 'yauf', 'nauf', 'ydwa', 'ndwa', 'yol', 'nol', 'ltid'
    ])
    if d:
        print(re)
    rr = re[0]
    r = {}
    h = False
    for i in rr:
        if i[0] == '-h' or i[0] == '-?' or i[0] == '--help':
            h = True
        if i[0] == '-i' and not 'i' in r:
            r['i'] = i[1]
        if i[0] == '-d' and not 'd' in r and i[1].isnumeric() and int(
                i[1]) > 0 and int(i[1]) < 9:
            r['d'] = int(i[1])
        if i[0] == '-p' and not 'p' in r:
            r['p'] = i[1]
        if i[0] == '-m' and not 'm' in r:
            if i[1].lower() == 'true':
                r['m'] = True
            elif i[1].lower() == 'false':
                r['m'] = False
        if i[0] == '--ym' and not 'm' in r:
            r['m'] = True
        if i[0] == '--nm' and not 'm' in r:
            r['m'] = False
        if i[0] == '--ac' and not 'ac' in r:
            if i[1].lower() == 'true':
                r['ac'] = True
            elif i[1].lower() == 'false':
                r['ac'] = False
        if i[0] == '--yac' and not 'ac' in r:
            r['ac'] = True
        if i[0] == '--nac' and not 'ac' in r:
            r['ac'] = False
        if i[0] == '--dm' and not 'dm' in r:
            if i[1].lower() == 'true':
                r['dm'] = True
            elif i[1].lower() == 'false':
                r['dm'] = False
        if i[0] == '--ydm' and not 'dm' in r:
            r['dm'] = True
        if i[0] == '--ndm' and not 'dm' in r:
            r['dm'] = False
        if i[0] == '--ad' and not 'ad' in r:
            if i[1].lower() == 'true':
                r['ad'] = True
            elif i[1].lower() == 'false':
                r['ad'] = False
        if i[0] == '--yad' and not 'ad' in r:
            r['ad'] = True
        if i[0] == '--nad' and not 'ad' in r:
            r['ad'] = False
        if i[0] == '-r' and not 'r' in r:
            if i[1].lower() == 'true':
                r['r'] = True
            elif i[1].lower() == 'false':
                r['r'] = False
        if i[0] == '--yr' and not 'r' in r:
            r['r'] = True
        if i[0] == '--nr' and not 'r' in r:
            r['r'] = False
        if i[0] == '-y' and not 'y' in r:
            r['y'] = True
        if i[0] == '-n' and not 'y' in r:
            r['y'] = False
        if i[0] == '--yf' and not 'yf' in r:
            r['yf'] = True
        if i[0] == '--nf' and not 'yf' in r:
            r['yf'] = False
        if i[0] == '--mc' and not 'mc' in r:
            if i[1].lower() == 'avc':
                r['mc'] = True
            elif i[1].lower() == 'hev':
                r['mc'] = False
        if i[0] == '--ar' and not 'ar' in r:
            r['ar'] = True
        if i[0] == '--nar' and not 'ar' in r:
            r['ar'] = False
        if i[0] == '--ax' and not 'ax' in r:
            if i[1].isnumeric():
                i2 = int(i[1])
                if i2 < 17 and i2 > 0:
                    r['ax'] = i2
        if i[0] == '--as' and not 'as' in r:
            if i[1].isnumeric():
                i2 = int(i[1])
                if i2 > 0:
                    r['as'] = i2
        if i[0] == '--ak' and not 'ak' in r:
            if i[1].isnumeric():
                i2 = int(i[1])
                if i2 > 0 and i2 < 1025:
                    r['ak'] = i2
        if i[0] == '--ab' and not 'ab' in r:
            r['ab'] = True
        if i[0] == '--nab' and not 'ab' in r:
            r['ab'] = False
        if i[0] == '--fa' and not 'fa' in r:
            if i[1].lower() == 'none' or i[1].lower() == 'prealloc' or i[
                    1].lower() == 'trunc' or i[1].lower() == 'falloc':
                r['fa'] = i[1].lower()
        if i[0] == '--sv' and not 'sv' in r:
            if i[1].lower() == 'true':
                r['sv'] = True
            elif i[1].lower() == 'false':
                r['sv'] = False
        if i[0] == '--ysv' and not 'sv' in r:
            r['sv'] = True
        if i[0] == '--nsv' and not 'sv' in r:
            r['sv'] = False
        if i[0] == '--ma' and not 'ma' in r:
            if i[1].lower() == 'true':
                r['ma'] = True
            elif i[1].lower() == 'false':
                r['ma'] = False
        if i[0] == '--yma' and not 'ma' in r:
            r['ma'] = True
        if i[0] == '--nma' and not 'ma' in r:
            r['ma'] = False
        if i[0] == '--ms' and not 'ms' in r:
            t = search("^[0-9]+[MK]?$", i[1])
            if t != None:
                r['ms'] = i[1]
        if i[0] == '--da' and not 'da' in r:
            if i[1].lower() == 'true':
                r['da'] = True
            elif i[1].lower() == 'false':
                r['da'] = False
        if i[0] == '--yda' and not 'da' in r:
            r['da'] = True
        if i[0] == '--nda' and not 'da' in r:
            r['da'] = False
        if i[0] == '--httpproxy' and not 'httpproxy' in r:
            r['httpproxy'] = i[1]
        if i[0] == '--httpsproxy' and not 'httpsproxy' in r:
            r['httpsproxy'] = i[1]
        if i[0] == "--jt" and not 'jt' in r:
            if i[1].lower() == 'a' or i[1].lower() == 'b' or i[1].isnumeric():
                r['jt'] = i[1].lower()
        if i[0] == '--jts' and not 'jts' in r:
            if checktime(i[1]):
                r['jts'] = i[1]
        if i[0] == '-F' and not 'F' in r:
            r['F'] = True
        if i[0] == '-v' and not 'v' in r:
            if i[1].isnumeric():
                if int(i[1]) > 0:
                    r['v'] = i[1]
        if i[0] == '-a' and not 'a' in r:
            if i[1].isnumeric():
                if int(i[1]) > 0:
                    r['a'] = i[1]
        if i[0] == '-o' and not 'o' in r:
            r['o'] = filterd(i[1])
        if i[0] == '--af' and not 'af' in r:
            r['af'] = False
        if i[0] == '--naf' and not 'af' in r:
            r['af'] = True
        if i[0] == '--afp' and not 'afp' in r:
            r['afp'] = i[1]
        if i[0] == '-s' and not 's' in r:
            r['s'] = True
        if i[0] == '--slt' and not 'slt' in r:
            r['slt'] = True
        if i[0] == '--nslt' and not 'slt' in r:
            r['slt'] = False
        if i[0] == '--te' and not 'te' in r:
            r['te'] = True
        if i[0] == '--nte' and not 'te' in r:
            r['te'] = False
        if i[0] == '--bd' and not 'bd' in r:
            r['bd'] = True
        if i[0] == '--nbd' and not 'bd' in r:
            r['bd'] = False
        if i[0] == '--cad' and not 'cad' in r:
            r['cad'] = True
        if i[0] == '--ncad' and not 'cad' in r:
            r['cad'] = False
        if i[0] == '--lrh' and not 'lrh' in r:
            r['lrh'] = True
        if i[0] == '--nlrh' and not 'lrh' in r:
            r['lrh'] = False
        if i[0] == '--ahttpproxy' and not 'ahttpproxy' in r:
            r['ahttpproxy'] = i[1]
        if i[0] == '--ahttpsproxy' and not 'ahttpsproxy' in r:
            r['ahttpsproxy'] = i[1]
        if i[0] == '--lan' and not 'lan' in r and (i[1] == 'null'
                                                   or i[1] in lan):
            r['lan'] = i[1]
        if i[0] == '--bp' and not 'bp' in r:
            r['bp'] = True
        if i[0] == '--nbp' and not 'bp' in r:
            r['bp'] = False
        if i[0] == '--in' and not 'in' in r:
            r['in'] = True
        if i[0] == '--nin' and not 'in' in r:
            r['in'] = False
        if i[0] == '--mt' and not 'mt' in r:
            r['mt'] = True
        if i[0] == '--nmt' and not 'mt' in r:
            r['mt'] = False
        if i[0] == '--vi' and not 'vi' in r:
            if i[1].isnumeric():
                r['vi'] = int(i[1])
        if i[0] == '--uc' and not 'uc' in r:
            r['uc'] = True
        if i[0] == '--nuc' and not 'uc' in r:
            r['uc'] = False
        if i[0] == '--ass' and not 'ass' in r:
            r['ass'] = True
        if i[0] == '--nass' and not 'ass' in r:
            r['ass'] = False
        if i[0] == '--dmp' and not 'dmp' in r:
            r['dmp'] = True
        if i[0] == '--ndmp' and not 'dmp' in r:
            r['dmp'] = False
        if i[0] == '--vf' and not 'vf' in r and i[1] in ['mkv', 'mp4']:
            r['vf'] = i[1]
        if i[0] == '--lmd' and not 'lmd' in r and i[1].isnumeric():
            if int(i[1]) >= 0:
                r['lmd'] = int(i[1])
        if i[0] == '--ynal' and not 'nal' in r:
            r['nal'] = True
        if i[0] == '--nnal' and not 'nal' in r:
            r['nal'] = False
        if i[0] == '--log' and not 'log' in r:
            r['log'] = True
        if i[0] == '--nlog' and not 'log' in r:
            r['log'] = False
        if i[0] == '--yauf' and not 'auf' in r:
            r['auf'] = True
        if i[0] == '--nauf' and not 'auf' in r:
            r['auf'] = False
        if i[0] == '--ydwa' and not 'dwa' in r:
            r['dwa'] = True
        if i[0] == '--ndwa' and not 'dwa' in r:
            r['dwa'] = False
        if i[0] == '--yol' and not 'ol' in r:
            r['ol'] = True
        if i[0] == '--nol' and not 'ol' in r:
            r['ol'] = False
        if i[0] == '--ltid':
            r['ltid'] = True
    if h:
        global la
        la = getdict('command', getlan(se, r))
        ph()
        exit()
    for i in re[1]:
        if i.lower() == "show":
            r['SHOW'] = True
    return r
示例#2
0
文件: command.py 项目: copyit/bili
def gopt(args, d: bool = False):
    re = getopt(args, 'h?i:d:p:m:r:ynFv:a:o:scb:V:', [
        'help', 'ac=', 'dm=', 'ad=', 'yf', 'nf', 'mc=', 'ar', 'nar', 'ax=',
        'as=', 'ak=', 'ab', 'nab', 'fa=', 'sv=', 'ma=', 'ms=', 'da=',
        'httpproxy=', 'httpsproxy=', 'jt=', 'jts=', 'af', 'naf', 'afp=', 'slt',
        'nslt', 'te', 'nte', 'bd', 'nbd', 'cad', 'ncad', 'lrh', 'nlrh', 'ym',
        'nm', 'yac', 'nac', 'ydm', 'ndm', 'yad', 'nad', 'yr', 'nr', 'ysv',
        'nsv', 'yma', 'nma', 'yda', 'nda', 'ahttpproxy=', 'ahttpsproxy=',
        'lan=', 'bp', 'nbp', 'in', 'nin', 'mt', 'nmt', 'vi=', 'uc', 'nuc',
        'ass', 'nass', 'dmp', 'ndmp', 'vf=', 'lmd=', 'ynal', 'nnal', 'log',
        'nlog', 'yauf', 'nauf', 'ydwa', 'ndwa', 'yol', 'nol', 'ltid', 'ncc',
        'ycc', 'nfo', 'nnfo', 'anopro', 'mxd=', 'imn', 'nimn', 'nlt=', 'nsp=',
        'fnl=', 'lp', 'nlp'
    ])
    if d:
        print(re)
    rr = re[0]
    r = {}
    h = False
    for i in rr:
        if i[0] == '-h' or i[0] == '-?' or i[0] == '--help':
            h = True
        if i[0] == '-i' and 'i' not in r:
            r['i'] = i[1]
        if i[0] == '-d' and 'd' not in r and i[1].isnumeric() and int(
                i[1]) > 0 and int(i[1]) < 9:
            r['d'] = int(i[1])
        if i[0] == '-p' and 'p' not in r:
            r['p'] = i[1]
        if i[0] == '-m' and 'm' not in r:
            if i[1].lower() == 'true':
                r['m'] = True
            elif i[1].lower() == 'false':
                r['m'] = False
        if i[0] == '--ym' and 'm' not in r:
            r['m'] = True
        if i[0] == '--nm' and 'm' not in r:
            r['m'] = False
        if i[0] == '--ac' and 'ac' not in r:
            if i[1].lower() == 'true':
                r['ac'] = True
            elif i[1].lower() == 'false':
                r['ac'] = False
        if i[0] == '--yac' and 'ac' not in r:
            r['ac'] = True
        if i[0] == '--nac' and 'ac' not in r:
            r['ac'] = False
        if i[0] == '--dm' and 'dm' not in r:
            if i[1].lower() == 'true':
                r['dm'] = True
            elif i[1].lower() == 'false':
                r['dm'] = False
        if i[0] == '--ydm' and 'dm' not in r:
            r['dm'] = True
        if i[0] == '--ndm' and 'dm' not in r:
            r['dm'] = False
        if i[0] == '--ad' and 'ad' not in r:
            if i[1].lower() == 'true':
                r['ad'] = True
            elif i[1].lower() == 'false':
                r['ad'] = False
        if i[0] == '--yad' and 'ad' not in r:
            r['ad'] = True
        if i[0] == '--nad' and 'ad' not in r:
            r['ad'] = False
        if i[0] == '-r' and 'r' not in r:
            if i[1].lower() == 'true':
                r['r'] = True
            elif i[1].lower() == 'false':
                r['r'] = False
        if i[0] == '--yr' and 'r' not in r:
            r['r'] = True
        if i[0] == '--nr' and 'r' not in r:
            r['r'] = False
        if i[0] == '-y' and 'y' not in r:
            r['y'] = True
        if i[0] == '-n' and 'y' not in r:
            r['y'] = False
        if i[0] == '--yf' and 'yf' not in r:
            r['yf'] = True
        if i[0] == '--nf' and 'yf' not in r:
            r['yf'] = False
        if i[0] == '--mc' and 'mc' not in r:
            if i[1].lower() == 'avc':
                r['mc'] = True
            elif i[1].lower() == 'hev':
                r['mc'] = False
        if i[0] == '--ar' and 'ar' not in r:
            r['ar'] = True
        if i[0] == '--nar' and 'ar' not in r:
            r['ar'] = False
        if i[0] == '--ax' and 'ax' not in r:
            if i[1].isnumeric():
                i2 = int(i[1])
                if i2 < 17 and i2 > 0:
                    r['ax'] = i2
        if i[0] == '--as' and 'as' not in r:
            if i[1].isnumeric():
                i2 = int(i[1])
                if i2 > 0:
                    r['as'] = i2
        if i[0] == '--ak' and 'ak' not in r:
            if i[1].isnumeric():
                i2 = int(i[1])
                if i2 > 0 and i2 < 1025:
                    r['ak'] = i2
        if i[0] == '--ab' and 'ab' not in r:
            r['ab'] = True
        if i[0] == '--nab' and 'ab' not in r:
            r['ab'] = False
        if i[0] == '--fa' and 'fa' not in r:
            if i[1].lower() == 'none' or i[1].lower() == 'prealloc' or i[
                    1].lower() == 'trunc' or i[1].lower() == 'falloc':
                r['fa'] = i[1].lower()
        if i[0] == '--sv' and 'sv' not in r:
            if i[1].lower() == 'true':
                r['sv'] = True
            elif i[1].lower() == 'false':
                r['sv'] = False
        if i[0] == '--ysv' and 'sv' not in r:
            r['sv'] = True
        if i[0] == '--nsv' and 'sv' not in r:
            r['sv'] = False
        if i[0] == '--ma' and 'ma' not in r:
            if i[1].lower() == 'true':
                r['ma'] = True
            elif i[1].lower() == 'false':
                r['ma'] = False
        if i[0] == '--yma' and 'ma' not in r:
            r['ma'] = True
        if i[0] == '--nma' and 'ma' not in r:
            r['ma'] = False
        if i[0] == '--ms' and 'ms' not in r:
            t = search("^[0-9]+[MK]?$", i[1])
            if t is not None:
                r['ms'] = i[1]
        if i[0] == '--da' and 'da' not in r:
            if i[1].lower() == 'true':
                r['da'] = True
            elif i[1].lower() == 'false':
                r['da'] = False
        if i[0] == '--yda' and 'da' not in r:
            r['da'] = True
        if i[0] == '--nda' and 'da' not in r:
            r['da'] = False
        if i[0] == '--httpproxy' and 'httpproxy' not in r:
            r['httpproxy'] = i[1]
        if i[0] == '--httpsproxy' and 'httpsproxy' not in r:
            r['httpsproxy'] = i[1]
        if i[0] == "--jt" and 'jt' not in r:
            if i[1].lower() == 'a' or i[1].lower() == 'b' or i[1].isnumeric():
                r['jt'] = i[1].lower()
        if i[0] == '--jts' and 'jts' not in r:
            if checktime(i[1]):
                r['jts'] = i[1]
        if i[0] == '-F' and 'F' not in r:
            r['F'] = True
        if i[0] == '-v' and 'v' not in r:
            if i[1].isnumeric():
                if int(i[1]) > 0:
                    r['v'] = i[1]
        if i[0] == '-a' and 'a' not in r:
            if i[1].isnumeric():
                if int(i[1]) > 0:
                    r['a'] = i[1]
        if i[0] == '-o' and 'o' not in r:
            r['o'] = filterd(i[1])
        if i[0] == '--af' and 'af' not in r:
            r['af'] = False
        if i[0] == '--naf' and 'af' not in r:
            r['af'] = True
        if i[0] == '--afp' and 'afp' not in r:
            r['afp'] = i[1]
        if i[0] == '-s' and 's' not in r:
            r['s'] = True
        if i[0] == '--slt' and 'slt' not in r:
            r['slt'] = True
        if i[0] == '--nslt' and 'slt' not in r:
            r['slt'] = False
        if i[0] == '--te' and 'te' not in r:
            r['te'] = True
        if i[0] == '--nte' and 'te' not in r:
            r['te'] = False
        if i[0] == '--bd' and 'bd' not in r:
            r['bd'] = True
        if i[0] == '--nbd' and 'bd' not in r:
            r['bd'] = False
        if i[0] == '--cad' and 'cad' not in r:
            r['cad'] = True
        if i[0] == '--ncad' and 'cad' not in r:
            r['cad'] = False
        if i[0] == '--lrh' and 'lrh' not in r:
            r['lrh'] = True
        if i[0] == '--nlrh' and 'lrh' not in r:
            r['lrh'] = False
        if i[0] == '--ahttpproxy' and 'ahttpproxy' not in r:
            r['ahttpproxy'] = i[1]
        if i[0] == '--ahttpsproxy' and 'ahttpsproxy' not in r:
            r['ahttpsproxy'] = i[1]
        if i[0] == '--lan' and 'lan' not in r and (i[1] == 'null'
                                                   or i[1] in lan):
            r['lan'] = i[1]
        if i[0] == '--bp' and 'bp' not in r:
            r['bp'] = True
        if i[0] == '--nbp' and 'bp' not in r:
            r['bp'] = False
        if i[0] == '--in' and 'in' not in r:
            r['in'] = True
        if i[0] == '--nin' and 'in' not in r:
            r['in'] = False
        if i[0] == '--mt' and 'mt' not in r:
            r['mt'] = True
        if i[0] == '--nmt' and 'mt' not in r:
            r['mt'] = False
        if i[0] == '--vi' and 'vi' not in r:
            if i[1].isnumeric():
                r['vi'] = int(i[1])
        if i[0] == '--uc' and 'uc' not in r:
            r['uc'] = True
        if i[0] == '--nuc' and 'uc' not in r:
            r['uc'] = False
        if i[0] == '--ass' and 'ass' not in r:
            r['ass'] = True
        if i[0] == '--nass' and 'ass' not in r:
            r['ass'] = False
        if i[0] == '--dmp' and 'dmp' not in r:
            r['dmp'] = True
        if i[0] == '--ndmp' and 'dmp' not in r:
            r['dmp'] = False
        if i[0] == '--vf' and 'vf' not in r and i[1] in ['mkv', 'mp4']:
            r['vf'] = i[1]
        if i[0] == '--lmd' and 'lmd' not in r and i[1].isnumeric():
            if int(i[1]) >= 0:
                r['lmd'] = int(i[1])
        if i[0] == '--ynal' and 'nal' not in r:
            r['nal'] = True
        if i[0] == '--nnal' and 'nal' not in r:
            r['nal'] = False
        if i[0] == '--log' and 'log' not in r:
            r['log'] = True
        if i[0] == '--nlog' and 'log' not in r:
            r['log'] = False
        if i[0] == '--yauf' and 'auf' not in r:
            r['auf'] = True
        if i[0] == '--nauf' and 'auf' not in r:
            r['auf'] = False
        if i[0] == '--ydwa' and 'dwa' not in r:
            r['dwa'] = True
        if i[0] == '--ndwa' and 'dwa' not in r:
            r['dwa'] = False
        if i[0] == '--yol' and 'ol' not in r:
            r['ol'] = True
        if i[0] == '--nol' and 'ol' not in r:
            r['ol'] = False
        if i[0] == '--ltid':
            r['ltid'] = True
        if i[0] == '--ycc' and 'cc' not in r:
            r['cc'] = True
        if i[0] == '--ncc' and 'cc' not in r:
            r['cc'] = False
        if i[0] == '--nfo' and 'nfo' not in r:
            r['nfo'] = True
        if i[0] == '--nnfo' and 'nfo' not in r:
            r['nfo'] = False
        if i[0] == '-V' and 'V' not in r:
            rs = search(r'^([0-9]+)(avc|hev)?$', i[1])
            if rs is not None:
                vid = int(rs.groups()[0])
                if vid in [16, 32, 64, 74, 80, 112, 116, 120, 125]:
                    r['V'] = {'id': vid, 'codec': rs.groups()[1]}
                elif vid in range(1, 12):
                    r['V'] = {'id': vid, 'codec': rs.groups()[1]}
        if i[0] == '--anopro' and 'anopro' not in r:
            r['anopro'] = True
        if i[0] == '--mxd' and 'mxd' not in r:
            if i[1].isnumeric():
                if int(i[1]) >= 0:
                    r['mxd'] = int(i[1])
        if i[0] == '--imn' and 'imn' not in r:
            r['imn'] = True
        if i[0] == '--nimn' and 'imn' not in r:
            r['imn'] = False
        if i[0] == '--nlt' and search(r'^\+?\d+(\.\d+)?$',
                                      i[1]) and 'nlt' not in r:
            r['nlt'] = float(i[1])
        if i[0] == '--nsp' and search(r'^\+?\d+(\.\d+)?$',
                                      i[1]) and 'nsp' not in r:
            t = float(i[1])
            t = min(max(round(t * 4), 1), 8) / 4
            if t in [1, 2]:
                t = round(t)
            r['nsp'] = t
        if i[0] == '--fnl' and i[1].isnumeric() and 'fnl' not in r:
            r['fnl'] = int(i[1])
        if i[0] == '--lp' and 'lp' not in r:
            r['lp'] = True
        if i[0] == '--nlp' and 'lp' not in r:
            r['lp'] = False
        if i[0] == '-b':
            ree = urlsplit(i[1])
            if ree.scheme == "bili":
                pat = f"{ree.netloc}{ree.path}"
                if ree.path == "/" and i[1].find("://") > -1:
                    pat = ree.netloc
                argv = ['-i', unquote_plus(pat)]
                getp = parse_qs(ree.query, True)
                for key in getp.keys():
                    if key == 'b':
                        continue
                    val = getp[key]
                    if len(key) == 1:
                        key = f"-{key}"
                    elif len(key) > 1:
                        key = f"--{key}"
                    else:
                        continue
                    if len(val) == 1 and val[0] == "":
                        argv.append(key)
                    else:
                        for v in val:
                            argv.append(key)
                            argv.append(v)
                if d:
                    print(argv)
                try:
                    return gopt(argv)
                except GetoptError:
                    t = i[1][5:]
                    if t.startswith('//'):
                        t = t[2:]
                    argv = ['-i', t]
                    if d:
                        print(argv)
                    return gopt(argv)
    if h:
        global la
        la = getdict('command', getlan(se, r))
        ph()
        sys.exit(0)
    for i in re[1]:
        if i.lower() == "show":
            r['SHOW'] = True
    return r
示例#3
0
def DanmuGeta(c, data, r, t, xml, xmlc, ip: dict, se: dict, che: bool = False):
    "全弹幕处理"
    ns = True
    if 's' in ip:
        ns = False
    o = "Download/"
    read = getset(se, 'o')
    if read != None:
        o = read
    if 'o' in ip:
        o = ip['o']
    try:
        if not exists(o):
            mkdir(o)
    except:
        print(lan['ERROR3'].replace('<dirname>', o))  #创建文件夹<dirname>失败。
        return -1
    try:
        if not exists('Temp'):
            mkdir('Temp')
    except:
        print(lan['ERROR3'].replace('<dirname>', "Temp"))  #创建Temp文件夹失败
        return -1
    fin = True
    if getset(se, 'in') == False:
        fin = False
    if 'in' in ip:
        fin = ip['in']
    if t == 'av':
        bs = True
        at2 = False
        fi = True
        jt = False
        if getset(se, 'jt') == True:
            jt = True
        while bs:
            if fi and 'jt' in ip:
                fi = False
                at = ip['jt']
            elif jt:
                at = 'a'
            elif ns:
                at = input(lan['INPUT2'].replace(
                    '<value>',
                    '1-365'))  #请输入两次抓取之间的天数(有效值为<value>,a会启用自动模式(推荐)):
            else:
                print(lan['ERROR7'])  #请使用"--jt <number>|a|b"来设置两次抓取之间的天数
                return -1
            if at.isnumeric() and int(at) <= 365 and int(at) >= 1:
                at = int(at)
                bs = False
            elif len(at) > 0 and at[0].lower() == 'a':
                at2 = True
                at = 1
                bs = False
        if data['videos'] == 1:
            if fin:
                filen = o + file.filtern(data['title'] + "(AV" +
                                         str(data['aid']) + ',' +
                                         data['bvid'] + ',P' + str(c) + ',' +
                                         str(data['page'][c - 1]['cid']) +
                                         ").xml")
            else:
                filen = f"{o}{file.filtern(data['title'])}.xml"
        else:
            if fin:
                filen = o + file.filtern(data['title'] + '-' + f"{c}." +
                                         data['page'][c - 1]['part'] + "(AV" +
                                         str(data['aid']) + ',' +
                                         data['bvid'] + ',P' + str(c) + ',' +
                                         str(data['page'][c - 1]['cid']) +
                                         ").xml")
            else:
                filen = f"{o}{file.filtern(data['title'])}-{c}.{file.filtern(data['page'][c-1]['part'])}.xml"
        if exists(filen):
            fg = False
            bs = True
            if not ns:
                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'].replace('<filename>',filen)}(y/n)?"
                )  #文件"<filename>"已存在,是否覆盖?
                if inp[0].lower() == 'y':
                    bs = False
                    fg = True
                elif inp[0].lower() == 'n':
                    bs = False
            if fg:
                try:
                    remove(filen)
                except:
                    print(lan['ERROR4'])  #删除原有文件失败,跳过下载
                    return -2
            else:
                return -2
        da = int(data['pubdate'])
        zl = 0
        zg = 0
        zm = 0
        now = 1
        now2 = now
        if ns:
            print(lan['OUTPUT5'])  #正在抓取最新弹幕……
        d2 = biliDanmuDown.downloadn(data['page'][c - 1]['cid'], r)
        if d2 == -1:
            print(lan['ERROR1'])  #网络错误!
            exit()
        filen2 = "Temp/a_" + str(data['page'][c - 1]['cid']) + ".xml"
        if exists(filen2):
            remove(filen2)
        try:
            f = open(filen2, mode='w', encoding='utf8')
            f.write(d2)
            f.close()
        except:
            print(lan['ERROR2'].replace('<filename>',
                                        filen2))  #写入到文件"<filename>"时失败!
            return -3
        d3 = biliDanmuXmlParser.loadXML(filen2)
        remove(filen2)
        ma = int(d3['maxlimit'])
        allok = False
        if len(d3['list']) < ma - 10:
            bs = True
            if not ns:
                bs = False
            while bs:
                sts = input(
                    f"{lan['INPUT3'].replace('<number>',str(len(d3['list']))).replace('<limit>',str(ma))}(y/n)"
                )
                if len(sts) > 0:
                    if sts[0].lower() == 'y':
                        bs = False
                    elif sts[0].lower() == 'n':
                        allok = True
                        bs = False
        if not allok:
            d2 = d3
            if ns:
                print(lan['OUTPUT6'].replace('<number>', str(len(
                    d2['list']))))  #抓取到<number>条弹幕,最新弹幕将在最后处理
        try:
            f2 = open(filen, mode='w', encoding='utf8')
        except:
            print(lan['ERROR5'].replace('<filename>',
                                        filen))  #打开文件"<filename>"失败
            return -3
        if not allok:
            try:
                f2.write('<?xml version="1.0" encoding="UTF-8"?>')
                f2.write(
                    '<i><chatserver>%s</chatserver><chatid>%s</chatid><mission>%s</mission><maxlimit>%s</maxlimit><state>%s</state><real_name>%s</real_name><source>%s</source>'
                    % (d2['chatserver'], d2['chatid'], d2['mission'],
                       d2['maxlimit'], d2['state'], d2['real_name'],
                       d2['source']))
            except:
                print(lan['ERROR6'].replace('<filename>', filen))  #保存文件失败
                return -3
        mri = 0
        mri2 = 0
        t1 = 0
        t2 = 0
        tem = {}
        fir = True
        while not allok and biliTime.equal(
                biliTime.getDate(da), biliTime.getNowDate()) < 0 and (
                    (not at2) or
                    (at2
                     and biliTime.equal(biliTime.getDate(da + now * 24 * 3600),
                                        biliTime.getNowDate()) < 0)):
            t1 = time.time()
            if (not at2) or fir:
                if ns:
                    print(lan['OUTPUT7'].replace(
                        '<date>', biliTime.tostr(
                            biliTime.getDate(da))))  #正在抓取<date>的弹幕……
                bs = True
                ts = 300
                rec = 0
                while bs:
                    read = downloadh(filen2, r, data['page'][c - 1]['cid'], da)
                    if read == -1:
                        return -3
                    elif read == -3:
                        rec = rec + 1
                        if rec % 5 != 0:
                            time.sleep(5)
                            print(lan['OUTPUT8'].replace(
                                '<number>', str(rec)))  #正在进行第<number>次重连
                        else:
                            bss = True
                            while bss:
                                inn = input(
                                    f"{lan['INPUT4'].replace('<number>',str(rec))}(y/n)"
                                )  #是否重连?(已经失败<number>次)
                                if len(inn) > 0 and inn[0].lower() == 'y':
                                    time.sleep(5)
                                    print(lan['OUTPUT8'].replace(
                                        '<number>',
                                        str(rec)))  #正在进行第<number>次重连
                                elif len(inn) > 0 and inn[0].lower() == 'n':
                                    exit()
                    elif 'status' in read and read['status'] == -2:
                        obj = json.loads(read['d'])
                        if obj['code'] == -101:
                            if obj['message'] == '账户未登录':
                                ud = {}
                                read = biliLogin.login(r, ud, ip)
                                if read > 1:
                                    exit()
                            else:
                                print(obj)
                                print(lan['OUTPUT9'].replace(
                                    '<number>', str(ts)))  #休眠<number>s
                                time.sleep(ts)
                                ts = ts + 300
                        else:
                            print(obj)
                            print(lan['OUTPUT9'].replace(
                                '<number>', str(ts)))  #休眠<number>s
                            time.sleep(ts)
                            ts = ts + 300
                    else:
                        bs = False
                d = read
                l = 0
                g = 0
                if ns:
                    print(lan['OUTPUT10'])  #正在处理弹幕……
                for i in d['list']:
                    if mri2 < int(i['ri']):
                        mri2 = int(i['ri'])
                    if mri < int(i['ri']):
                        l = l + 1
                        if xml == 2:
                            try:
                                f2.write(biliDanmuCreate.objtoxml(i))
                            except:
                                print(lan['ERROR2'].replace(
                                    '<filename>',
                                    filen))  #写入到文件"<filename>"时失败!
                                return -3
                        elif xml == 1:
                            read = biliDanmuXmlFilter.Filter(i, xmlc)
                            if read:
                                g = g + 1
                            else:
                                try:
                                    f2.write(biliDanmuCreate.objtoxml(i))
                                except:
                                    print(lan['ERROR2'].replace(
                                        '<filename>',
                                        filen))  #写入到文件"<filename>"时失败!
                                    return -3
            else:
                rr = False
                rr2 = False
                if biliTime.tostr(biliTime.getDate(da +
                                                   now * 24 * 3600)) in tem:
                    if ns:
                        print(lan['OUTPUT11'].replace(
                            '<date>',
                            biliTime.tostr(
                                biliTime.getDate(da + now * 24 *
                                                 3600))))  #从内存中获取了<date>的弹幕。
                    read = biliDanmuAuto.reload(
                        tem.pop(
                            biliTime.tostr(
                                biliTime.getDate(da + now * 24 * 3600))), mri,
                        ns)
                    rr = True
                    if read['z'] == read[
                            'l'] and read['z'] > ma - 10 and now > 1:
                        rr2 = True
                if (not rr) or (rr and rr2):
                    if (not rr):
                        read = biliDanmuAuto.getMembers(
                            filen2, r, da + now * 24 * 3600,
                            data['page'][c - 1]['cid'], mri, ip)
                        if read == -1:
                            return -3
                    while read['z'] == read[
                            'l'] and read['z'] > ma - 10 and now > 1:
                        #if ns:
                        #print('尝试抓取了%s的弹幕,获取到%s条有效弹幕,未防止遗漏,间隔时间减半' % (biliTime.tostr(biliTime.getDate(da+now*24*3600)),read['l']))
                        tem[biliTime.tostr(
                            biliTime.getDate(da + now * 24 * 3600))] = read
                        now = now / 2
                        if now < 1:
                            now = 1
                        read = biliDanmuAuto.getMembers(
                            filen2, r, da + now * 24 * 3600,
                            data['page'][c - 1]['cid'], mri, ip)
                        if read == -1:
                            return -3
                        now2 = now
                    if read['l'] < ma * 0.5:
                        now2 = now * 2
                        if now2 > 365:
                            now2 = 365
                l = read['l']
                g = 0
                mri2 = read['m']
                if ns:
                    print(lan['OUTPUT12'])  #正在处理……
                for i in read['d']['list']:
                    if xml == 2:
                        try:
                            f2.write(biliDanmuCreate.objtoxml(i))
                        except:
                            print(lan['ERROR2'].replace(
                                '<filename>', filen))  #写入到文件"<filename>"时失败!
                            return -3
                    elif xml == 1:
                        read = biliDanmuXmlFilter.Filter(i, xmlc)
                        if read:
                            g = g + 1
                        else:
                            try:
                                f2.write(biliDanmuCreate.objtoxml(i))
                            except:
                                print(lan['ERROR2'].replace(
                                    '<filename>',
                                    filen2))  #写入到文件"<filename>"时失败!
                                return -3
                bs2 = True
                while bs2 and biliTime.equal(
                        biliTime.getDate(da + (now2 + now) * 24 * 3600),
                        biliTime.getNowDate()) >= 0:
                    if allok:
                        read = biliDanmuAuto.getnownumber(d3, mri2)
                    else:
                        read = biliDanmuAuto.getnownumber(d2, mri2)
                    if read['l'] == read['m']:
                        now2 = now2 / 2
                        if now2 < 1:
                            now2 = 1
                    else:
                        bs2 = False
            m = l - g
            zl = zl + l
            zm = zm + m
            zg = zg + g
            if ns:
                print(lan['OUTPUT13'].replace('<number>',
                                              f"{l}({zl})"))  #获取了<number>条弹幕。
            if xml == 1 and ns:
                print(lan['OUTPUT14'].replace('<number>',
                                              f"{g}({zg})"))  #过滤了<number>条弹幕。
                print(lan['OUTPUT15'].replace(
                    '<number>', f"{m}({zm})"))  #实际输出了<number>条弹幕。
            if t2 == 0 or t1 - t2 < 2:
                time.sleep(2)
            t2 = t1
            if not at2:
                da = da + at * 3600 * 24
            elif fir:
                fir = False
            else:
                da = da + now * 3600 * 24
                now = now2
            mri = mri2
        if not allok:
            if ns:
                print(lan['OUTPUT16'])  #开始处理最新的弹幕……
            l = 0
            g = 0
            for i in d2['list']:
                if int(mri) < int(i['ri']):
                    l = l + 1
                    if xml == 2:
                        try:
                            f2.write(biliDanmuCreate.objtoxml(i))
                        except:
                            print(lan['ERROR2'].replace(
                                '<filename>', filen))  #写入到文件"<filename>"时失败!
                            return -3
                    elif xml == 1:
                        read = biliDanmuXmlFilter.Filter(i, xmlc)
                        if read:
                            g = g + 1
                        else:
                            try:
                                f2.write(biliDanmuCreate.objtoxml(i))
                            except:
                                print(lan['ERROR2'].replace(
                                    '<filename>',
                                    filen))  #写入到文件"<filename>"时失败!
                                return -3
            try:
                f2.write('</i>')
                f2.close()
            except:
                print(lan['ERROR2'].replace('<filename>',
                                            filen2))  #写入到文件"<filename>"时失败!
                return -3
            m = l - g
            zl = zl + l
            zg = zg + g
            zm = zm + m
            if ns:
                print(lan['OUTPUT17'].replace('<number>',
                                              str(l)))  #在最新弹幕中获取新弹幕<number>条。
            if xml == 1 and ns:
                print(lan['OUTPUT14'].replace('<number>',
                                              str(g)))  #过滤了<number>条弹幕。
                print(lan['OUTPUT15'].replace('<number>',
                                              str(m)))  #实际输出了<number>条弹幕。
            if ns:
                print(lan['OUTPUT18'].replace('<number>',
                                              str(zl)))  #总共获取了<number>条弹幕
            if xml == 1 and ns:
                print(lan['OUTPUT3'].replace('<number>',
                                             str(zg)))  #共计过滤<number>条弹幕。
                print(lan['OUTPUT4'].replace('<number>',
                                             str(zm)))  #实际输出<number>条弹幕。
        else:
            if xml == 2:
                try:
                    f2.write(d2)
                    f2.close()
                except:
                    print(lan['ERROR2'].replace('<filename>',
                                                filen))  #写入到文件"<filename>"时失败!
                    return -3
            if xml == 1:
                z = len(d3['list'])
                g = 0
                for i in d3['list']:
                    read = biliDanmuXmlFilter.Filter(i, xmlc)
                    if read:
                        g = g + 1
                    else:
                        try:
                            f2.write(biliDanmuCreate.objtoxml(i))
                        except:
                            print(lan['ERROR2'].replace(
                                '<filename>', filen))  #写入到文件"<filename>"时失败!
                            return -3
                try:
                    f2.close()
                except:
                    print(lan['ERROR2'].replace('<filename>',
                                                filen))  #写入到文件"<filename>"时失败!
                    return -3
                m = z - g
                if ns:
                    print(lan['OUTPUT13'].replace('<number>',
                                                  str(z)))  #获取了<number>条弹幕。
                    print(lan['OUTPUT14'].replace('<number>',
                                                  str(g)))  #过滤了<number>条弹幕。
                    print(lan['OUTPUT15'].replace('<number>',
                                                  str(m)))  #实际输出了<number>条弹幕。
        return 0
    elif t == 'ss':
        bs = True
        at2 = False
        if not che:
            pubt = data['mediaInfo']['time'][0:10]
        else:
            pubt = biliTime.tostr2(c['time'])[0:10]
        fi = True
        jt = False
        if getset(se, 'jt') == True:
            jt = True
        if 'jts' in ip:
            pubt = ip['jts']
        while bs:
            if fi and 'jt' in ip:
                fi = False
                at = ip['jt']
            elif jt:
                at = 'a'
            elif ns:
                at = input(
                    lan['INPUT5'].replace('<value>', '1-365').replace(
                        '<date>', str(pubt))
                )  #请输入两次抓取之间的天数(有效值为<value>,输入a会启用自动模式(推荐),输入b可手动输入开始抓取的日期,日期目前为<date>):
            else:
                print(lan['ERROR7'])  #请使用"--jt <number>|a|b"来设置两次抓取之间的天数
                return -1
            if at.isnumeric() and int(at) <= 365 and int(at) >= 1:
                at = int(at)
                bs = False
            elif len(at) > 0 and at[0].lower() == 'a':
                at2 = True
                at = 1
                bs = False
            elif len(at) > 0 and at[0].lower() == 'b':
                if not ns:
                    print(lan['ERROR8'])  #请使用"--jts <date>"来修改抓取开始时间。
                    return -1
                at3 = input(lan['INPUT6'])  #请输入日期(格式为年-月-日,例如1989-02-25):
                if len(at3) > 0:
                    if biliTime.checktime(at3):
                        pubt = time.strftime('%Y-%m-%d',
                                             time.strptime(at3, '%Y-%m-%d'))
                    else:
                        print(lan['ERROR9'])  #输入格式有误或者该日期不存在。
        pubt = biliTime.mkt(time.strptime(pubt, '%Y-%m-%d'))
        da = int(pubt)
        pat = o + file.filtern(
            '%s(SS%s)' %
            (data['mediaInfo']['title'], data['mediaInfo']['ssId']))
        try:
            if not exists(pat):
                mkdir(pat)
        except:
            print(lan['ERROR3'].replace('<dirname>', pat))  #创建文件夹<dirname>失败。
            return -1
        if c['s'] == 'e':
            if fin:
                filen = '%s/%s' % (
                    pat,
                    file.filtern('%s.%s(%s,AV%s,%s,ID%s,%s).xml' %
                                 (c['i'] + 1, c['longTitle'], c['titleFormat'],
                                  c['aid'], c['bvid'], c['id'], c['cid'])))
            else:
                filen = '%s/%s' % (
                    pat, file.filtern(f"{c['i']+1}.{c['longTitle']}.xml"))
        else:
            if fin:
                filen = '%s/%s' % (pat,
                                   file.filtern(
                                       '%s%s.%s(%s,AV%s,%s,ID%s,%s).xml' %
                                       (c['title'], c['i'] + 1, c['longTitle'],
                                        c['titleFormat'], c['aid'], c['bvid'],
                                        c['id'], c['cid'])))
            else:
                filen = '%s/%s' % (
                    pat,
                    file.filtern(
                        f"{c['title']}{c['i']+1}.{c['longTitle']}.xml"))
        if exists(filen):
            fg = False
            bs = True
            if not ns:
                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'].replace('<filename>',filen)}(y/n)?"
                )  #文件"<filename>"已存在,是否覆盖?
                if inp[0].lower() == 'y':
                    bs = False
                    fg = True
                elif inp[0].lower() == 'n':
                    bs = False
            if fg:
                try:
                    remove(filen)
                except:
                    print(lan['ERROR4'])  #删除原有文件失败,跳过下载
                    return -2
            else:
                return -2
        zl = 0
        zg = 0
        zm = 0
        now = 1
        now2 = now
        if ns:
            print(lan['OUTPUT5'])  #正在抓取最新弹幕……
        d2 = biliDanmuDown.downloadn(c['cid'], r)
        if d2 == -1:
            print(lan['ERROR1'])  #网络错误!
            exit()
        filen2 = "Temp/a_" + str(c['cid']) + ".xml"
        if exists(filen2):
            remove(filen2)
        try:
            f = open(filen2, mode='w', encoding='utf8')
            f.write(d2)
            f.close()
        except:
            print(lan['ERROR2'].replace('<filename>',
                                        filen2))  #写入到文件"<filename>"时失败!
            return -3
        d3 = biliDanmuXmlParser.loadXML(filen2)
        remove(filen2)
        ma = int(d3['maxlimit'])
        allok = False
        if len(d3['list']) < ma - 10:
            bs = True
            if not ns:
                bs = False
            while bs:
                sts = input(
                    f"{lan['INPUT3'].replace('<number>',str(len(d3['list']))).replace('<limit>',str(ma))}(y/n)"
                )
                if len(sts) > 0:
                    if sts[0].lower() == 'y':
                        bs = False
                    elif sts[0].lower() == 'n':
                        allok = True
                        bs = False
        if not allok:
            d2 = d3
            if ns:
                print(lan['OUTPUT6'].replace('<number>', str(len(
                    d2['list']))))  #抓取到<number>条弹幕,最新弹幕将在最后处理
        try:
            f2 = open(filen, mode='w', encoding='utf8')
        except:
            print(lan['ERROR5'].replace('<filename>',
                                        filen))  #打开文件"<filename>"失败
            return -3
        if not allok:
            try:
                f2.write('<?xml version="1.0" encoding="UTF-8"?>')
                f2.write(
                    '<i><chatserver>%s</chatserver><chatid>%s</chatid><mission>%s</mission><maxlimit>%s</maxlimit><state>%s</state><real_name>%s</real_name><source>%s</source>'
                    % (d2['chatserver'], d2['chatid'], d2['mission'],
                       d2['maxlimit'], d2['state'], d2['real_name'],
                       d2['source']))
            except:
                print(lan['ERROR6'].replace('<filename>', filen))  #保存文件失败
                return -3
        mri = 0
        mri2 = 0
        t1 = 0
        t2 = 0
        tem = {}
        fir = True
        while not allok and biliTime.equal(
                biliTime.getDate(da), biliTime.getNowDate()) < 0 and (
                    (not at2) or
                    (at2
                     and biliTime.equal(biliTime.getDate(da + now * 24 * 3600),
                                        biliTime.getNowDate()) < 0)):
            t1 = time.time()
            if (not at2) or fir:
                if ns:
                    print(lan['OUTPUT7'].replace(
                        '<date>', biliTime.tostr(
                            biliTime.getDate(da))))  #正在抓取<date>的弹幕……
                bs = True
                ts = 300
                rec = 0
                while bs:
                    read = downloadh(filen2, r, c['cid'], da)
                    if read == -1:
                        return -3
                    elif read == -3:
                        rec = rec + 1
                        if rec % 5 != 0:
                            time.sleep(5)
                            print(lan['OUTPUT8'].replace(
                                '<number>', str(rec)))  #正在进行第<number>次重连
                        else:
                            bss = True
                            while bss:
                                inn = input(
                                    f"{lan['INPUT4'].replace('<number>',str(rec))}(y/n)"
                                )  #是否重连?(已经失败<number>次)
                                if len(inn) > 0 and inn[0].lower() == 'y':
                                    time.sleep(5)
                                    print(lan['OUTPUT8'].replace(
                                        '<number>',
                                        str(rec)))  #正在进行第<number>次重连
                                elif len(inn) > 0 and inn[0].lower() == 'n':
                                    exit()
                    elif 'status' in read and read['status'] == -2:
                        obj = json.loads(read['d'])
                        if obj['code'] == -101:
                            if obj['message'] == '账户未登录':
                                ud = {}
                                read = biliLogin.login(r, ud, ip)
                                if read > 1:
                                    exit()
                            else:
                                print(obj)
                                print(lan['OUTPUT9'].replace(
                                    '<number>', str(ts)))  #休眠<number>s
                                time.sleep(ts)
                                ts = ts + 300
                        else:
                            print(obj)
                            print(lan['OUTPUT9'].replace(
                                '<number>', str(ts)))  #休眠<number>s
                            time.sleep(ts)
                            ts = ts + 300
                    else:
                        bs = False
                d = read
                l = 0
                g = 0
                if ns:
                    print(lan['OUTPUT10'])  #正在处理弹幕……
                for i in d['list']:
                    if mri2 < int(i['ri']):
                        mri2 = int(i['ri'])
                    if mri < int(i['ri']):
                        l = l + 1
                        if xml == 2:
                            try:
                                f2.write(biliDanmuCreate.objtoxml(i))
                            except:
                                print(lan['ERROR2'].replace(
                                    '<filename>',
                                    filen))  #写入到文件"<filename>"时失败!
                                return -3
                        elif xml == 1:
                            read = biliDanmuXmlFilter.Filter(i, xmlc)
                            if read:
                                g = g + 1
                            else:
                                try:
                                    f2.write(biliDanmuCreate.objtoxml(i))
                                except:
                                    print(lan['ERROR2'].replace(
                                        '<filename>',
                                        filen))  #写入到文件"<filename>"时失败!
                                    return -3
            else:
                rr = False
                rr2 = False
                if biliTime.tostr(biliTime.getDate(da +
                                                   now * 24 * 3600)) in tem:
                    if ns:
                        print(lan['OUTPUT11'].replace(
                            '<date>',
                            biliTime.tostr(
                                biliTime.getDate(da + now * 24 *
                                                 3600))))  #从内存中获取了<date>的弹幕。
                    read = biliDanmuAuto.reload(
                        tem.pop(
                            biliTime.tostr(
                                biliTime.getDate(da + now * 24 * 3600))), mri,
                        ns)
                    rr = True
                    if read['z'] == read[
                            'l'] and read['z'] > ma - 10 and now > 1:
                        rr2 = True
                if (not rr) or (rr and rr2):
                    if (not rr):
                        read = biliDanmuAuto.getMembers(
                            filen2, r, da + now * 24 * 3600, c['cid'], mri, ip)
                        if read == -1:
                            return -3
                    while read['z'] == read[
                            'l'] and read['z'] > ma - 10 and now > 1:
                        #if ns:
                        #print('尝试抓取了%s的弹幕,获取到%s条有效弹幕,未防止遗漏,间隔时间减半' % (biliTime.tostr(biliTime.getDate(da+now*24*3600)),read['l']))
                        tem[biliTime.tostr(
                            biliTime.getDate(da + now * 24 * 3600))] = read
                        now = now / 2
                        if now < 1:
                            now = 1
                        read = biliDanmuAuto.getMembers(
                            filen2, r, da + now * 24 * 3600, c['cid'], mri, ip)
                        if read == -1:
                            return -3
                        now2 = now
                    if read['l'] < ma * 0.5:
                        now2 = now * 2
                        if now2 > 365:
                            now2 = 365
                l = read['l']
                g = 0
                mri2 = read['m']
                if ns:
                    print(lan['OUTPUT12'])  #正在处理……
                for i in read['d']['list']:
                    if xml == 2:
                        try:
                            f2.write(biliDanmuCreate.objtoxml(i))
                        except:
                            print(lan['ERROR2'].replace(
                                '<filename>', filen))  #写入到文件"<filename>"时失败!
                            return -3
                    elif xml == 1:
                        read = biliDanmuXmlFilter.Filter(i, xmlc)
                        if read:
                            g = g + 1
                        else:
                            try:
                                f2.write(biliDanmuCreate.objtoxml(i))
                            except:
                                print(lan['ERROR2'].replace(
                                    '<filename>',
                                    filen2))  #写入到文件"<filename>"时失败!
                                return -3
                bs2 = True
                while bs2 and biliTime.equal(
                        biliTime.getDate(da + (now2 + now) * 24 * 3600),
                        biliTime.getNowDate()) >= 0:
                    if allok:
                        read = biliDanmuAuto.getnownumber(d3, mri2)
                    else:
                        read = biliDanmuAuto.getnownumber(d2, mri2)
                    if read['l'] == read['m']:
                        now2 = now2 / 2
                        if now2 < 1:
                            now2 = 1
                    else:
                        bs2 = False
            m = l - g
            zl = zl + l
            zm = zm + m
            zg = zg + g
            if ns:
                print(lan['OUTPUT13'].replace('<number>',
                                              f"{l}({zl})"))  #获取了<number>条弹幕。
            if xml == 1 and ns:
                print(lan['OUTPUT14'].replace('<number>',
                                              f"{g}({zg})"))  #过滤了<number>条弹幕。
                print(lan['OUTPUT15'].replace(
                    '<number>', f"{m}({zm})"))  #实际输出了<number>条弹幕。
            if t2 == 0 or t1 - t2 < 2:
                time.sleep(2)
            t2 = t1
            if not at2:
                da = da + at * 3600 * 24
            elif fir:
                fir = False
            else:
                da = da + now * 3600 * 24
                now = now2
            mri = mri2
        if not allok:
            if ns:
                print(lan['OUTPUT16'])  #开始处理最新的弹幕……
            l = 0
            g = 0
            for i in d2['list']:
                if int(mri) < int(i['ri']):
                    l = l + 1
                    if xml == 2:
                        try:
                            f2.write(biliDanmuCreate.objtoxml(i))
                        except:
                            print(lan['ERROR2'].replace(
                                '<filename>', filen))  #写入到文件"<filename>"时失败!
                            return -3
                    elif xml == 1:
                        read = biliDanmuXmlFilter.Filter(i, xmlc)
                        if read:
                            g = g + 1
                        else:
                            try:
                                f2.write(biliDanmuCreate.objtoxml(i))
                            except:
                                print(lan['ERROR2'].replace(
                                    '<filename>',
                                    filen))  #写入到文件"<filename>"时失败!
                                return -3
            try:
                f2.write('</i>')
                f2.close()
            except:
                print(lan['ERROR2'].replace('<filename>',
                                            filen2))  #写入到文件"<filename>"时失败!
                return -3
            m = l - g
            zl = zl + l
            zg = zg + g
            zm = zm + m
            if ns:
                print(lan['OUTPUT17'].replace('<number>',
                                              str(l)))  #在最新弹幕中获取新弹幕<number>条。
            if xml == 1 and ns:
                print(lan['OUTPUT14'].replace('<number>',
                                              str(g)))  #过滤了<number>条弹幕。
                print(lan['OUTPUT15'].replace('<number>',
                                              str(m)))  #实际输出了<number>条弹幕。
            if ns:
                print(lan['OUTPUT18'].replace('<number>',
                                              str(zl)))  #总共获取了<number>条弹幕
            if xml == 1 and ns:
                print(lan['OUTPUT3'].replace('<number>',
                                             str(zg)))  #共计过滤<number>条弹幕。
                print(lan['OUTPUT4'].replace('<number>',
                                             str(zm)))  #实际输出<number>条弹幕。
        else:
            if xml == 2:
                try:
                    f2.write(d2)
                    f2.close()
                except:
                    print(lan['ERROR2'].replace('<filename>',
                                                filen))  #写入到文件"<filename>"时失败!
                    return -3
            if xml == 1:
                z = len(d3['list'])
                g = 0
                for i in d3['list']:
                    read = biliDanmuXmlFilter.Filter(i, xmlc)
                    if read:
                        g = g + 1
                    else:
                        try:
                            f2.write(biliDanmuCreate.objtoxml(i))
                        except:
                            print(lan['ERROR2'].replace(
                                '<filename>', filen))  #写入到文件"<filename>"时失败!
                            return -3
                try:
                    f2.close()
                except:
                    print(lan['ERROR2'].replace('<filename>',
                                                filen))  #写入到文件"<filename>"时失败!
                    return -3
                m = z - g
                if ns:
                    print(lan['OUTPUT13'].replace('<number>',
                                                  str(z)))  #获取了<number>条弹幕。
                    print(lan['OUTPUT14'].replace('<number>',
                                                  str(g)))  #过滤了<number>条弹幕。
                    print(lan['OUTPUT15'].replace('<number>',
                                                  str(m)))  #实际输出了<number>条弹幕。
        return 0
示例#4
0
def gopt(args,d:bool=False) :
    re = getopt(args, 'h?i:d:p:m:r:ynFv:a:o:scb:', ['help', 'ac=', 'dm=', 'ad=', 'yf', 'nf', 'mc=', 'ar', 'nar', 'ax=', 'as=', 'ak=', 'ab', 'nab', 'fa=', 'sv=', 'ma=', 'ms=', 'da=', 'httpproxy=', 'httpsproxy=', 'jt=', 'jts=', 'af', 'naf', 'afp=', 'slt', 'nslt', 'te', 'nte', 'bd', 'nbd', 'cad', 'ncad', 'lrh', 'nlrh', 'ym', 'nm', 'yac', 'nac', 'ydm', 'ndm', 'yad', 'nad', 'yr', 'nr', 'ysv', 'nsv', 'yma', 'nma', 'yda', 'nda', 'ahttpproxy=', 'ahttpsproxy=', 'lan=', 'bp', 'nbp', 'in', 'nin', 'mt', 'nmt', 'vi=', 'uc', 'nuc', 'ass', 'nass', 'dmp', 'ndmp', 'vf=', 'lmd=', 'ynal', 'nnal', 'log', 'nlog', 'yauf', 'nauf', 'ydwa', 'ndwa', 'yol', 'nol', 'ltid'])
    if d:
        print(re)
    rr=re[0]
    r={}
    h=False
    for i in rr:
        if i[0]=='-h' or i[0]=='-?' or i[0]=='--help':
            h=True
        if i[0]=='-i' and not 'i' in r:
            r['i']=i[1]
        if i[0]=='-d' and not 'd' in r and i[1].isnumeric() and int(i[1])>0 and int(i[1])<9 :
            r['d']=int(i[1])
        if i[0]=='-p' and not 'p' in r :
            r['p']=i[1]
        if i[0]=='-m' and not 'm' in r :
            if i[1].lower()=='true' :
                r['m']=True
            elif i[1].lower()=='false' :
                r['m']=False
        if i[0]=='--ym' and not 'm' in r:
            r['m']=True
        if i[0]=='--nm' and not 'm' in r:
            r['m']=False
        if i[0]=='--ac' and not 'ac' in r:
            if i[1].lower()=='true' :
                r['ac']=True
            elif i[1].lower()=='false' :
                r['ac']=False
        if i[0]=='--yac' and not 'ac' in r:
            r['ac']=True
        if i[0]=='--nac' and not 'ac' in r:
            r['ac']=False
        if i[0]=='--dm' and not 'dm' in r:
            if i[1].lower()=='true' :
                r['dm']=True
            elif i[1].lower()=='false' :
                r['dm']=False
        if i[0]=='--ydm' and not 'dm' in r:
            r['dm']=True
        if i[0]=='--ndm' and not 'dm' in r:
            r['dm']=False
        if i[0]=='--ad' and not 'ad' in r:
            if i[1].lower()=='true' :
                r['ad']=True
            elif i[1].lower()=='false' :
                r['ad']=False
        if i[0]=='--yad' and not 'ad' in r:
            r['ad']=True
        if i[0]=='--nad' and not 'ad' in r:
            r['ad']=False
        if i[0]=='-r' and not 'r' in r:
            if i[1].lower()=='true' :
                r['r']=True
            elif i[1].lower()=='false' :
                r['r']=False
        if i[0]=='--yr' and not 'r' in r:
            r['r']=True
        if i[0]=='--nr' and not 'r' in r:
            r['r']=False
        if i[0]=='-y' and not 'y' in r:
            r['y']=True
        if i[0]=='-n' and not 'y' in r:
            r['y']=False
        if i[0]=='--yf' and not 'yf' in r:
            r['yf']=True
        if i[0]=='--nf' and not 'yf' in r:
            r['yf']=False
        if i[0]=='--mc' and not 'mc' in r:
            if i[1].lower()=='avc' :
                r['mc']=True
            elif i[1].lower()=='hev' :
                r['mc']=False
        if i[0]=='--ar' and not 'ar' in r:
            r['ar']=True
        if i[0]=='--nar' and not 'ar' in r:
            r['ar']=False
        if i[0]=='--ax' and not 'ax' in r:
            if i[1].isnumeric() :
                i2=int(i[1])
                if i2<17 and i2>0 :
                    r['ax']=i2
        if i[0]=='--as' and not 'as' in r:
            if i[1].isnumeric() :
                i2=int(i[1])
                if i2>0 :
                    r['as']=i2
        if i[0]=='--ak' and not 'ak' in r:
            if i[1].isnumeric() :
                i2=int(i[1])
                if i2>0 and i2<1025 :
                    r['ak']=i2
        if i[0]=='--ab' and not 'ab' in r:
            r['ab']=True
        if i[0]=='--nab' and not 'ab' in r:
            r['ab']=False
        if i[0]=='--fa' and not 'fa' in r:
            if i[1].lower()=='none' or i[1].lower()=='prealloc' or i[1].lower()=='trunc' or i[1].lower()=='falloc':
                r['fa']=i[1].lower()
        if i[0]=='--sv' and not 'sv' in r:
            if i[1].lower()=='true' :
                r['sv']=True
            elif i[1].lower()=='false' :
                r['sv']=False
        if i[0]=='--ysv' and not 'sv' in r:
            r['sv']=True
        if i[0]=='--nsv' and not 'sv' in r:
            r['sv']=False
        if i[0]=='--ma' and not 'ma' in r:
            if i[1].lower()=='true' :
                r['ma']=True
            elif i[1].lower()=='false' :
                r['ma']=False
        if i[0]=='--yma' and not 'ma' in r:
            r['ma']=True
        if i[0]=='--nma' and not 'ma' in r:
            r['ma']=False
        if i[0]=='--ms' and not 'ms' in r:
            t=search("^[0-9]+[MK]?$",i[1])
            if t!=None :
                r['ms']=i[1]
        if i[0]=='--da' and not 'da' in r:
            if i[1].lower()=='true' :
                r['da']=True
            elif i[1].lower()=='false' :
                r['da']=False
        if i[0]=='--yda' and not 'da' in r:
            r['da']=True
        if i[0]=='--nda' and not 'da' in r:
            r['da']=False
        if i[0]=='--httpproxy' and not 'httpproxy' in r:
            r['httpproxy']=i[1]
        if i[0]=='--httpsproxy' and not 'httpsproxy' in r:
            r['httpsproxy']=i[1]
        if i[0]=="--jt" and not 'jt' in r:
            if i[1].lower()=='a' or i[1].lower()=='b' or i[1].isnumeric():
                r['jt']=i[1].lower()
        if i[0]=='--jts' and not 'jts' in r:
            if checktime(i[1]) :
                r['jts']=i[1]
        if i[0]=='-F' and not 'F' in r:
            r['F']=True
        if i[0]=='-v' and not 'v' in r:
            if i[1].isnumeric() :
                if int(i[1])>0 :
                    r['v']=i[1]
        if i[0]=='-a' and not 'a' in r:
            if i[1].isnumeric():
                if int(i[1])>0:
                    r['a']=i[1]
        if i[0]=='-o' and not 'o' in r:
            r['o']=filterd(i[1])
        if i[0]=='--af' and not 'af' in r:
            r['af']=False
        if i[0]=='--naf' and not 'af' in r:
            r['af']=True
        if i[0]=='--afp' and not 'afp' in r:
            r['afp']=i[1]
        if i[0]=='-s' and not 's' in r:
            r['s']=True
        if i[0]=='--slt' and not 'slt' in r:
            r['slt']=True
        if i[0]=='--nslt' and not 'slt' in r:
            r['slt']=False
        if i[0]=='--te' and not 'te' in r:
            r['te']=True
        if i[0]=='--nte' and not 'te' in r:
            r['te']=False
        if i[0]=='--bd' and not 'bd' in r:
            r['bd']=True
        if i[0]=='--nbd' and not 'bd' in r:
            r['bd']=False
        if i[0]=='--cad' and not 'cad' in r:
            r['cad']=True
        if i[0]=='--ncad' and not 'cad' in r:
            r['cad']=False
        if i[0]=='--lrh' and not 'lrh' in r:
            r['lrh']=True
        if i[0]=='--nlrh' and not 'lrh' in r:
            r['lrh']=False
        if i[0]=='--ahttpproxy' and not 'ahttpproxy' in r:
            r['ahttpproxy']=i[1]
        if i[0]=='--ahttpsproxy' and not 'ahttpsproxy' in r:
            r['ahttpsproxy']=i[1]
        if i[0]=='--lan' and not 'lan' in r and (i[1]=='null' or i[1] in lan) :
            r['lan']=i[1]
        if i[0]=='--bp' and not 'bp' in r:
            r['bp']=True
        if i[0]=='--nbp' and not 'bp' in r:
            r['bp']=False
        if i[0]=='--in' and not 'in' in r:
            r['in']=True
        if i[0]=='--nin' and not 'in' in r:
            r['in']=False
        if i[0]=='--mt' and not 'mt' in r:
            r['mt']=True
        if i[0]=='--nmt' and not 'mt' in r:
            r['mt']=False
        if i[0]=='--vi' and not 'vi' in r:
            if i[1].isnumeric():
                r['vi'] = int(i[1])
        if i[0] == '--uc' and not 'uc' in r:
            r['uc'] = True
        if i[0] == '--nuc' and not 'uc' in r:
            r['uc'] = False
        if i[0] == '--ass' and not 'ass' in r:
            r['ass'] = True
        if i[0] == '--nass' and not 'ass' in r:
            r['ass'] = False
        if i[0] == '--dmp' and not 'dmp' in r:
            r['dmp'] = True
        if i[0] == '--ndmp' and not 'dmp' in r:
            r['dmp'] = False
        if i[0] == '--vf' and not 'vf' in r and i[1] in ['mkv', 'mp4']:
            r['vf'] = i[1]
        if i[0] == '--lmd' and not 'lmd' in r and i[1].isnumeric():
            if int(i[1]) >= 0:
                r['lmd'] = int(i[1])
        if i[0] == '--ynal' and not 'nal' in r:
            r['nal'] = True
        if i[0] == '--nnal' and not 'nal' in r:
            r['nal'] = False
        if i[0] == '--log' and not 'log' in r:
            r['log'] = True
        if i[0] == '--nlog' and not 'log' in r:
            r['log'] = False
        if i[0] == '--yauf' and not 'auf' in r:
            r['auf'] = True
        if i[0] == '--nauf' and not 'auf' in r:
            r['auf'] = False
        if i[0] == '--ydwa' and not 'dwa' in r:
            r['dwa'] = True
        if i[0] == '--ndwa' and not 'dwa' in r:
            r['dwa'] = False
        if i[0] == '--yol' and not 'ol' in r:
            r['ol'] = True
        if i[0] == '--nol' and not 'ol' in r:
            r['ol'] = False
        if i[0] == '--ltid':
            r['ltid'] = True
        if i[0] == '-b':
            ree = urlsplit(i[1])
            if ree.scheme == "bili":
                pat = f"{ree.netloc}{ree.path}"
                if ree.path == "/" and i[1].find("://") > -1:
                    pat = ree.netloc
                argv = ['-i', unquote_plus(pat)]
                getp = parse_qs(ree.query, True)
                for key in getp.keys():
                    if key == 'b':
                        continue
                    val = getp[key]
                    if len(key) == 1:
                        key = f"-{key}"
                    elif len(key) > 1:
                        key = f"--{key}"
                    else:
                        continue
                    if len(val) == 1 and val[0] == "":
                        argv.append(key)
                    else:
                        for v in val:
                            argv.append(key)
                            argv.append(v)
                if d:
                    print(argv)
                try:
                    return gopt(argv)
                except GetoptError:
                    t = i[1][5:]
                    if t.startswith('//'):
                        t = t[2:]
                    argv = ['-i', t]
                    if d:
                        print(argv)
                    return gopt(argv)
    if h:
        global la
        la=getdict('command',getlan(se,r))
        ph()
        exit()
    for i in re[1] :
        if i.lower()=="show":
            r['SHOW'] = True
    return r