Spaces:
Sleeping
Sleeping
rogerxavier
commited on
Commit
•
e4fd7b8
1
Parent(s):
f254425
Update utils.py
Browse files
utils.py
CHANGED
@@ -63,31 +63,37 @@ def delete_file(delete_dir:str)->str:
|
|
63 |
return "message:"+ "成功删除{delete_dir}目录下的所有文件".format(delete_dir=delete_dir)
|
64 |
|
65 |
|
|
|
66 |
def random_chapter():
|
67 |
# for root, info in configData.data['file_info'].items():
|
68 |
-
|
69 |
file_info = update_file_info(configData.data['current_dir'])
|
70 |
configData.data['file_info'] = file_info
|
|
|
|
|
71 |
for root, info in configData.data['file_info'].items():
|
72 |
if root.startswith(configData.data['manga_abs_dir']):
|
73 |
for directory in info["directories"]:
|
74 |
-
if any(file.endswith('.jpg') or file.endswith('.png')
|
|
|
75 |
chapter_path = os.path.join(root, directory)
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
|
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
chapter_title = chapter_path # 如果目录层级不足2层,直接使用路径作为标题
|
86 |
|
87 |
-
|
88 |
-
return chapter_title,chapter_path#返回章节标题和章节目录给任务-1批量顺序上传原始图片到服务器manga.
|
89 |
|
90 |
-
return None,None
|
91 |
|
92 |
def list_files():
|
93 |
#查看files信息的时候需要更新configData
|
|
|
63 |
return "message:"+ "成功删除{delete_dir}目录下的所有文件".format(delete_dir=delete_dir)
|
64 |
|
65 |
|
66 |
+
#随机返回一个章节,而不是第一个
|
67 |
def random_chapter():
|
68 |
# for root, info in configData.data['file_info'].items():
|
69 |
+
# 手动更新避免引入旧值-成功
|
70 |
file_info = update_file_info(configData.data['current_dir'])
|
71 |
configData.data['file_info'] = file_info
|
72 |
+
chapters = []
|
73 |
+
|
74 |
for root, info in configData.data['file_info'].items():
|
75 |
if root.startswith(configData.data['manga_abs_dir']):
|
76 |
for directory in info["directories"]:
|
77 |
+
if any(file.endswith('.jpg') or file.endswith('.png') for file in
|
78 |
+
os.listdir(os.path.join(root, directory))):
|
79 |
chapter_path = os.path.join(root, directory)
|
80 |
+
chapters.append(chapter_path)
|
81 |
+
|
82 |
+
if chapters:
|
83 |
+
# 随机选择一个章节
|
84 |
+
random_chapter_path = random.choice(chapters)
|
85 |
+
print("章节目录是:",random_chapter_path)
|
86 |
|
87 |
+
# 将路径转换为标题
|
88 |
+
folders = random_chapter_path.split(os.sep)
|
89 |
+
if len(folders) >= 2:
|
90 |
+
chapter_title = " ".join([folders[-2], folders[-1]]) # 获取倒数第二个和倒数第一个目录名作为标题
|
91 |
+
else:
|
92 |
+
chapter_title = random_chapter_path # 如果目录层级不足2层,直接使用路径作为标题
|
|
|
93 |
|
94 |
+
return chapter_title, random_chapter_path
|
|
|
95 |
|
96 |
+
return None, None
|
97 |
|
98 |
def list_files():
|
99 |
#查看files信息的时候需要更新configData
|