name = '' rssinfo= url + 'api/tag/fetch' data = {"_ids": rss} info = requests.post(rssinfo, json=data, headers=headers) infostr = json.loads(info.text) for i inrange(0, len(infostr)): if infostr[i]['type'] == 'bangumi': names = infostr[i]['locale'] if'zh_cn'in names.keys(): name = names['zh_cn'] elif'zh_tw'in names.keys(): name = names['zh_tw'] else: name = infostr[i]['name'] return name return name
defmake_yml(rsstr, name): in_aria2 = ' server: '+aria_ip+'\n port: '+str(aria_port)+'\n secret: "'+aria_secret+'"\n path: "'+aria_path+name+'"\n\n' rss = url + 'rss/tags/' + '+'.join(rsstr) f = open(flexget_path+'config.yml', 'a+', encoding = 'utf-8') f.writelines(' '+name+':\n') f.writelines(' rss: '+rss+'\n') f.writelines(' if:\n') for i in rej_reg: f.writelines(' - "\'' + i + '\' in title": reject\n') f.writelines(' - "\'[\'": accept\n') # f.writelines(' accept_all: yes\n') f.writelines(' aria2:\n') f.writelines(in_aria2) f.close()
deffind_ep(file): for pattern in patternlist: ep = re.findall(pattern, file) iflen(ep) == 1: returnint(ep[0])
return -1
deffind_maxep(path3): maxep = -1 for root, dirs, files in os.walk(path3): for file in files: ep = find_ep(file) if ep > maxep: maxep = ep maxep = str(maxep).zfill(2) return maxep
deffind_season(path): maxss = 1 fordirin os.listdir(path): if os.path.isfile(path+dir): continue seasonn = re.findall(pattern0, dir) iflen(seasonn) == 1and seasonn[0].isdigit() andint(seasonn[0]) > maxss: maxss = int(seasonn[0]) season = str(maxss).zfill(2) return season
defrename(title, bgminfo): list1 = ['.mkv', '.MKV', '.mp4'] season = bgminfo['season'].zfill(2) path2 = path + title + '/Season ' + season ifnot os.path.exists(path2): os.mkdir(path2) for file in os.listdir(path+title): if os.path.isdir(path+title+file): continue ext = os.path.splitext(file)[1] if ext in list1: ep = find_ep(file) ifnot ep == -1: desfile = title + ' - S' + season + 'E' + str(ep).zfill(2) +ext
bgm_info = {} data = json.loads(json.dumps(bgm_info)) fordirin os.listdir(path): if os.path.isfile(path+dir): continue maxep = find_maxep(path+dir) info = {'title': dir, 'year': '', 'maxep': maxep, 'season': ''} if os.path.exists(path+'bgminfo.json'): withopen(path+'bgminfo.json','r') as g: bginfo = json.load(g) ifnotdirin bginfo: season = find_season(path+dir) info['season'] = season data[dir] = info continue
info['season'] = bginfo[dir]['season']
ifnot bginfo[dir]['year'] == '': info['year'] = bginfo[dir]['year'] # if not dir == newtitle: # src = os.path.join(path, dir) # des = os.path.join(path, newtitle) # os.rename(src,des) # flag = 1 # data[newtitle] = info # if not flag == 1: data[dir] = info result = json.dumps(data, ensure_ascii=False, indent=4) withopen(path+'bgminfo.json', 'w', newline='\n') as f: f.write(result) iflen(sys.argv) == 1: for title in data: rename(title, data[title]) else: title = sys.argv[1] rename(title,data[title])