You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.1 KiB

import os
import sys
import re
import shutil
import time
download_dir = "/downloads/Default"
save_dir = "/downloads/Anime"
permission_code = 511
number_map = {
"": 0,
"": 1,
"": 2,
"": 3,
"": 4,
"": 5,
"": 6,
"": 7,
"": 8,
"": 9,
"": 10
}
def delete(path):
f = list(os.listdir(path))
for i in range(len(f)):
date = os.path.getmtime(os.path.join(path,f[i]))
currdate = time.time()
num1 =(currdate - date)/60/60/24
if num1 >= 1:
try:
os.remove(path + f[i])
except Exception as e:
print(e)
name = sys.argv[1]
save_name = name
name_title = name.split(".")[0]
name_re = re.match("(.*) - \d\d (.*)",name_title)
if name_re:
sub_name = name_re.group(1) + " " + name_re.group(2)
else:
name_re = re.match("(.*) \[(\d\d)\](.*)", name_title)
if name_re:
sub_name = name_re.group(1) + " " + name_re.group(3)
save_name = name.replace(" [{}]".format(name_re.group(2)), " - {} ".format(name_re.group(2)))
#删除保存文件夹路径的字幕修改标识、地区限制标识
sub_name = re.sub("\[v\d\]", "", sub_name)
sub_name = re.sub("(僅限.*地區)", "", sub_name)
#多季整合
season_re = re.match(".*第(.)季.*", sub_name)
season = 1 #默认季
season_dir = "Season "
if season_re:
season = number_map[season_re.group(1)]
sub_name = re.sub("第(.)季","", sub_name)
sub_name = sub_name.replace(" "," ")
season_dir += "{:0>2d}".format(season)
series_save_dir = os.path.join(save_dir, sub_name)
season_save_dir = os.path.join(series_save_dir, season_dir)
if not os.path.exists(series_save_dir):
os.makedirs(series_save_dir)
os.chmod(series_save_dir, permission_code)
if not os.path.exists(season_save_dir):
os.makedirs(season_save_dir)
os.chmod(season_save_dir, permission_code)
shutil.copyfile(os.path.join(download_dir, name), os.path.join(season_save_dir, save_name))
os.chmod(os.path.join(season_save_dir, save_name), permission_code)
#delete(download_dir)