recursively process dirs
This commit is contained in:
@@ -156,33 +156,28 @@ class VideoCleaner:
|
|||||||
|
|
||||||
print(f"Scanning {input_path}...")
|
print(f"Scanning {input_path}...")
|
||||||
|
|
||||||
while True:
|
# 逐个目录递归处理,避免一次性加载所有文件到内存
|
||||||
all_videos = []
|
|
||||||
# 每次循环都获取最新列表
|
|
||||||
for root, dirs, files in os.walk(input_path):
|
for root, dirs, files in os.walk(input_path):
|
||||||
if "processed" in dirs: dirs.remove("processed")
|
if "processed" in dirs:
|
||||||
|
dirs.remove("processed")
|
||||||
|
|
||||||
|
# 筛选当前目录下的视频文件
|
||||||
|
current_dir_videos = []
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.lower().endswith(self.supported_extensions):
|
if file.lower().endswith(self.supported_extensions):
|
||||||
full_path = Path(root) / file
|
current_dir_videos.append(Path(root) / file)
|
||||||
all_videos.append(full_path)
|
|
||||||
|
|
||||||
if not all_videos:
|
if not current_dir_videos:
|
||||||
print("No more files to process. Exiting.")
|
continue
|
||||||
break
|
|
||||||
|
|
||||||
# 按修改时间排序,取最旧的一个
|
# 对当前目录的文件按时间排序处理
|
||||||
all_videos.sort(key=lambda x: os.path.getmtime(x))
|
current_dir_videos.sort(key=lambda x: os.path.getmtime(x))
|
||||||
|
|
||||||
processed_in_this_loop = False
|
print(f"Processing directory: {root} ({len(current_dir_videos)} files)")
|
||||||
for target_file in all_videos:
|
for target_file in current_dir_videos:
|
||||||
if self.process_video_file(target_file, processed_dir, input_path):
|
# 处理文件。如果 process_video_file 返回 False,
|
||||||
processed_in_this_loop = True
|
# 通常是因为文件太新(未到 30 天),则跳过当前文件
|
||||||
break # 处理了一个,重新获取列表
|
self.process_video_file(target_file, processed_dir, input_path)
|
||||||
|
|
||||||
if not processed_in_this_loop:
|
|
||||||
# 如果列表里剩下的所有文件都还没到 30 天,那就退出
|
|
||||||
print("All remaining files are newer than the age limit. Exiting.")
|
|
||||||
break
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import argparse
|
import argparse
|
||||||
|
|||||||
Reference in New Issue
Block a user