jhj0517 commited on
Commit
f3cdbdc
1 Parent(s): 3fcd292

Add `clean_image_files()`

Browse files
Files changed (1) hide show
  1. modules/video_utils.py +15 -2
modules/video_utils.py CHANGED
@@ -1,6 +1,6 @@
1
  import subprocess
2
  import os
3
- from typing import List, Optional
4
 
5
  from modules.logger_util import get_logger
6
  from modules.paths import TEMP_DIR
@@ -36,7 +36,7 @@ def extract_frames(
36
 
37
 
38
  def get_frames_from_dir(vid_dir: str,
39
- available_extensions: Optional[List, str] = None) -> List:
40
  if available_extensions is None:
41
  available_extensions = [".jpg", ".jpeg", ".JPG", ".JPEG"]
42
 
@@ -51,3 +51,16 @@ def get_frames_from_dir(vid_dir: str,
51
  return []
52
  frame_names.sort(key=lambda x: int(os.path.splitext(x)[0]))
53
  return frame_names
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import subprocess
2
  import os
3
+ from typing import List, Optional, Union
4
 
5
  from modules.logger_util import get_logger
6
  from modules.paths import TEMP_DIR
 
36
 
37
 
38
  def get_frames_from_dir(vid_dir: str,
39
+ available_extensions: Optional[Union[List, str]] = None) -> List:
40
  if available_extensions is None:
41
  available_extensions = [".jpg", ".jpeg", ".JPG", ".JPEG"]
42
 
 
51
  return []
52
  frame_names.sort(key=lambda x: int(os.path.splitext(x)[0]))
53
  return frame_names
54
+
55
+
56
+ def clean_image_files(image_dir: str):
57
+ image_extensions = ('.jpg', '.jpeg', '.png', '.gif', '.bmp', '.tiff', '.webp')
58
+
59
+ for filename in os.listdir(image_dir):
60
+ if filename.lower().endswith(image_extensions):
61
+ file_path = os.path.join(image_dir, filename)
62
+ try:
63
+ os.remove(file_path)
64
+ except Exception as e:
65
+ logger.exception("Error while removing image files")
66
+ raise f"Error removing {str(e)}"