Spaces:
Sleeping
Sleeping
rogerxavier
commited on
Commit
•
9d4219f
1
Parent(s):
1517ac0
Update utils.py
Browse files
utils.py
CHANGED
@@ -119,7 +119,25 @@ def update_config_json(newConfig:str):
|
|
119 |
return content
|
120 |
|
121 |
|
122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
def remove_different_size_images(chapter_path:str):
|
124 |
image_dir = chapter_path
|
125 |
# 获取目录下所有图片文件名
|
@@ -142,6 +160,8 @@ def remove_different_size_images(chapter_path:str):
|
|
142 |
if image_size != most_common_size:
|
143 |
print("发现图片:",image_file,"大小不同于章节其他图片,认为是杂类图片,进行删除")
|
144 |
os.remove(os.path.join(image_dir, image_file))
|
|
|
|
|
145 |
|
146 |
def is_asp_task_valid()->bool:
|
147 |
# 启动状态检测 ->
|
|
|
119 |
return content
|
120 |
|
121 |
|
122 |
+
|
123 |
+
def zero_pad(s, length):
|
124 |
+
return s.zfill(length)
|
125 |
+
|
126 |
+
# 按照排序删除广告文件和片头
|
127 |
+
def delete_first_and_last_image_in_subdirectories(root_dir:str,deleted_list:list):
|
128 |
+
for root, dirs, files in os.walk(root_dir):
|
129 |
+
for dir_name in dirs:
|
130 |
+
dir_path = os.path.join(root, dir_name)
|
131 |
+
images = [f for f in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path, f))]
|
132 |
+
images.sort(
|
133 |
+
key=lambda x: zero_pad(''.join(filter(str.isdigit, os.path.splitext(os.path.basename(x))[0])), 3))
|
134 |
+
for index in deleted_list:
|
135 |
+
if index < len(images) and index >= -len(images):
|
136 |
+
image_path = os.path.join(dir_path, images[index])
|
137 |
+
print("依据默认config,删除章节片头和结尾广告,可修改默认配置[0,1,-1]",image_path)
|
138 |
+
os.remove(image_path)
|
139 |
+
|
140 |
+
#void 删除当前chapter中部分size不同的少类图片,还有就是删除片头和广告,默认配置[0,1,-1],这个只对cur_chapter执行就不会多删了
|
141 |
def remove_different_size_images(chapter_path:str):
|
142 |
image_dir = chapter_path
|
143 |
# 获取目录下所有图片文件名
|
|
|
160 |
if image_size != most_common_size:
|
161 |
print("发现图片:",image_file,"大小不同于章节其他图片,认为是杂类图片,进行删除")
|
162 |
os.remove(os.path.join(image_dir, image_file))
|
163 |
+
# 按照默认配置删除片头和广告
|
164 |
+
delete_first_and_last_image_in_subdirectories(root_dir=chapter_path,deleted_list=configData.data['default_chapter_delete'])
|
165 |
|
166 |
def is_asp_task_valid()->bool:
|
167 |
# 启动状态检测 ->
|