11
11
from .constants import DEFAULT_OUTPUT
12
12
from .constants import DEFAULT_SKIP
13
13
from .pathtools import listdir
14
- from .pathtools import metadata_path
15
14
from .progress import use_progress
16
15
from .thumbnail import ThumbnailExistsError
17
16
from .thumbnail import ThumbnailFactory
@@ -36,6 +35,9 @@ def __init__(self, inputs):
36
35
self .compress = DEFAULT_COMPRESS
37
36
self .interval = DEFAULT_INTERVAL
38
37
38
+ # Remove non-video files in case of input directory already contains other generated files.
39
+ self .inputs = [file for file in self .inputs if re .match (r"^.*\.(?:(?!png|vtt|json).)+$" , file )]
40
+
39
41
@staticmethod
40
42
def worker (video , fmt , base , skip , output ):
41
43
"""Executes the required workflows for generating a thumbnail."""
@@ -46,21 +48,18 @@ def worker(video, fmt, base, skip, output):
46
48
thumbnail .prepare_frames ()
47
49
thumbnail .generate ()
48
50
49
- @use_progress
50
- def generate (self ):
51
- self .inputs = [file for file in self .inputs if re .match (r"^.*\.(?:(?!png|vtt|json).)+$" , file )]
52
- self .inputs = dict (zip (map (lambda i : metadata_path (i , self .output , self .format ), self .inputs ), self .inputs ))
51
+ def __iter__ (self ):
52
+ return self
53
53
54
- with concurrent .futures .ThreadPoolExecutor () as executor :
55
- videos = executor .map (
56
- functools .partial (
57
- Video ,
58
- compress = self .compress ,
59
- interval = self .interval ,
60
- ),
61
- self .inputs .values (),
62
- )
54
+ def __next__ (self ):
55
+ """Returns the next video to be processed."""
56
+ try :
57
+ return Video (self .inputs .pop (), self .compress , self .interval )
58
+ except IndexError :
59
+ raise StopIteration
63
60
61
+ @use_progress
62
+ def generate (self ):
64
63
with concurrent .futures .ThreadPoolExecutor () as executor :
65
64
executor .map (
66
65
functools .partial (
@@ -70,5 +69,5 @@ def generate(self):
70
69
skip = self .skip ,
71
70
output = self .output ,
72
71
),
73
- videos ,
72
+ self ,
74
73
)
0 commit comments