2
2
from os import scandir
3
3
4
4
image_extensions = [".jpg" , ".jpeg" , ".png" , ".tif" , ".tiff" ]
5
+ video_extensions = [".mp4" , ".mov" , ".mpg" , ".wmv" , ".mkv" , ".avi" , ".avchd" , ".flv" , ".f4v" , ".swf" , "webm" ]
5
6
6
7
def write_bytes_safe (p , bytes_data ):
7
8
"""
@@ -21,7 +22,7 @@ def scantree(path):
21
22
else :
22
23
yield entry
23
24
24
- def get_image_paths (dir_path , image_extensions = image_extensions , subdirs = False , return_Path_class = False ):
25
+ def get_extension_paths (dir_path , extensions , subdirs = False , return_Path_class = False ):
25
26
dir_path = Path (dir_path )
26
27
27
28
result = []
@@ -33,10 +34,16 @@ def get_image_paths(dir_path, image_extensions=image_extensions, subdirs=False,
33
34
gen = scandir (str (dir_path ))
34
35
35
36
for x in gen :
36
- if any (x .name .lower ().endswith (ext ) for ext in image_extensions ): # listcomp is not needed, any() can handle gencomp
37
- result .append ( Path (x ) if return_Path_class else x .path ) # avoid unnecessary negative condition
37
+ if any (x .name .lower ().endswith (ext ) for ext in extensions ): # listcomp is not needed, any() can handle gencomp
38
+ result .append ( Path (x ) if return_Path_class else x .path ) # avoid unnecessary negative condition
38
39
return result # scandir should already be sorted
39
40
41
+ def get_image_paths (dir_path , image_extensions = image_extensions , subdirs = False , return_Path_class = False ):
42
+ return get_extension_paths (dir_path , image_extensions , subdirs , return_Path_class )
43
+
44
+ def get_video_paths (dir_path , video_extensions = video_extensions , subdirs = False , return_Path_class = False ):
45
+ return get_extension_paths (dir_path , video_extensions , subdirs , return_Path_class )
46
+
40
47
def get_image_unique_filestem_paths (dir_path , verbose_print_func = None ):
41
48
result = get_image_paths (dir_path )
42
49
result_dup = set ()
@@ -59,7 +66,7 @@ def get_paths(dir_path):
59
66
return [ Path (x ) for x in sorted ([ x .path for x in list (scandir (str (dir_path ))) ]) ]
60
67
else :
61
68
return []
62
-
69
+
63
70
def get_file_paths (dir_path ):
64
71
dir_path = Path (dir_path )
65
72
0 commit comments