diff --git a/scripts/iib/dir_cover_cache.py b/scripts/iib/dir_cover_cache.py index 71b49cd..8153343 100644 --- a/scripts/iib/dir_cover_cache.py +++ b/scripts/iib/dir_cover_cache.py @@ -33,7 +33,7 @@ def get_media_files_from_folder(folder_path): """ media_files = [] with os.scandir(folder_path) as entries: - for entry in sorted(entries, key=lambda x: x.stat().st_mtime, reverse=True): + for entry in sorted(entries, key=lambda x: x.stat().st_birthtime if hasattr(x.stat(), 'st_birthtime') else x.stat().st_ctime, reverse=True): if entry.is_file() and is_valid_media_path(entry.path): name = os.path.basename(entry.path) stat = entry.stat() diff --git a/scripts/iib/tool.py b/scripts/iib/tool.py index 3d63524..520058f 100644 --- a/scripts/iib/tool.py +++ b/scripts/iib/tool.py @@ -205,6 +205,17 @@ def get_video_type(file_path): return file_extension[1:] else: return None + +def is_image_file(filename: str) -> bool: + if not isinstance(filename, str): + return False + + extensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'] + extension = filename.split('.')[-1].lower() + return f".{extension}" in extensions + +def is_video_file(filename: str) -> bool: + return isinstance(get_video_type(filename), str) def is_valid_media_path(path): """ @@ -215,9 +226,7 @@ def is_valid_media_path(path): return False if not os.path.isfile(abs_path): # 判断是否是文件 return False - if not imghdr.what(abs_path) and not get_video_type(abs_path): # 判断是否是图像文件 - return False - return True + return is_image_file(abs_path) or is_video_file(abs_path)