Merge pull request #823 from zanllp/feat/handle-missing-filetype

add fallback for uninstalled filetype handlers
pull/825/head
zanllp 2025-06-09 00:52:09 +08:00 committed by GitHub
commit 22d51a4e6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 3 deletions

View File

@ -14,7 +14,6 @@ import zipfile
from PIL import Image
import shutil
# import magic
import filetype
sd_img_dirs = [
"outdir_txt2img_samples",
@ -203,8 +202,14 @@ def convert_to_bytes(file_size_str):
def is_video_simple(filepath):
kind = filetype.guess(filepath)
return kind and kind.mime.startswith('video/')
try:
import filetype
kind = filetype.guess(filepath)
# print(f"File type guessed: {kind}")
return kind and kind.mime.startswith('video/')
except:
# 如果 filetype 模块不可用,使用简单的文件扩展名检查
return isinstance(get_video_type(filepath), str)
def get_video_type(file_path):
video_extensions = ['.mp4', '.m4v', '.avi', '.mkv', '.mov', '.wmv', '.flv', '.ts']