73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
from pathlib import Path
|
||
import shutil
|
||
|
||
BOMTOON = {
|
||
# "漫画名": (判断目录是否不为temp,起始index,修正index)
|
||
"鄰居是公會成員": (True, 0, 1),
|
||
"PAYBACK": (True, 0, 0),
|
||
"1995青春報告": (True, 0, 0),
|
||
"Unsleep": (True, 0, 1),
|
||
"Backlight": (True, 0, 1),
|
||
"鬼夜曲": (True, 65, -3),
|
||
"披薩外送員與黃金宮": (True, 0, -1),
|
||
"No Moral": (True, 87, 0),
|
||
# "No Moral": (True, 0, 1),
|
||
"易地思之": (True, 0, 1),
|
||
"監禁倉庫": (True, 0, 1),
|
||
"棋子的世界": (True, 0, 1),
|
||
"夢龍傳": (True, 0, 1),
|
||
"融冰曲線": (True, 0, 1),
|
||
}
|
||
|
||
# current = "鄰居是公會成員"
|
||
# current = "Unsleep"
|
||
# current = "Backlight"
|
||
# current = "1995青春報告"
|
||
current = "鬼夜曲"
|
||
# current = "No Moral"
|
||
# current = "易地思之"
|
||
# current = "監禁倉庫"
|
||
# current = "披薩外送員與黃金宮"
|
||
# current = "PAYBACK"
|
||
# current = "夢龍傳"
|
||
# current = "棋子的世界"
|
||
# current = "融冰曲線"
|
||
|
||
bomtoon_path = Path('E:/') / 'Webtoon' / current if BOMTOON[current][0] else Path('E:/') / 'Temp_Webtoon' / current
|
||
|
||
def find_next_index(index_list, start_index):
|
||
if len(index_list) == 0:
|
||
return 0
|
||
index_list = sorted(set(index_list)) # 先去重并排序
|
||
for i in range(index_list[0], index_list[-1]): # 遍历从最小值到最大值
|
||
if i not in index_list and i > start_index:
|
||
return i # 返回第一个缺失的数字
|
||
return index_list[-1] + 1
|
||
|
||
def create_dir(index, bomtoon_name):
|
||
name = str(index) + '.' + '第' + str(index + BOMTOON[bomtoon_name][2]) + '話'
|
||
# name = str(index) + '.' + '外傳 第' + str(index - 86) + '話'
|
||
path = Path(bomtoon_path) / name
|
||
path.mkdir(parents=True, exist_ok=True)
|
||
print(f"create {path}")
|
||
return path
|
||
|
||
def move_all_webps(dest_dir: Path):
|
||
download_dir = Path('C:/') / 'Users' / 'ithil' / 'Downloads'
|
||
if not dest_dir.exists():
|
||
dest_dir.mkdir(parents=True) # 如果目标目录不存在,则创建
|
||
|
||
for file in download_dir.iterdir():
|
||
if file.is_file() and file.suffix.lower() == ".webp": # 只移动webp文件
|
||
shutil.move(str(file), str(dest_dir)) # 移动文件
|
||
|
||
index_list = []
|
||
for first_level_path in bomtoon_path.iterdir():
|
||
if first_level_path.is_dir():
|
||
index_list.append(int(first_level_path.name.split(".")[0]))
|
||
|
||
index = find_next_index(index_list, BOMTOON[current][1])
|
||
new_dir = create_dir(index, current)
|
||
move_all_webps(new_dir)
|
||
|