1111from .constants import DEFAULT_OUTPUT
1212from .constants import DEFAULT_SKIP
1313from .pathtools import listdir
14- from .pathtools import metadata_path
1514from .progress import use_progress
1615from .thumbnail import ThumbnailExistsError
1716from .thumbnail import ThumbnailFactory
@@ -36,6 +35,9 @@ def __init__(self, inputs):
3635 self .compress = DEFAULT_COMPRESS
3736 self .interval = DEFAULT_INTERVAL
3837
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+
3941 @staticmethod
4042 def worker (video , fmt , base , skip , output ):
4143 """Executes the required workflows for generating a thumbnail."""
@@ -46,21 +48,18 @@ def worker(video, fmt, base, skip, output):
4648 thumbnail .prepare_frames ()
4749 thumbnail .generate ()
4850
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
5353
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
6360
61+ @use_progress
62+ def generate (self ):
6463 with concurrent .futures .ThreadPoolExecutor () as executor :
6564 executor .map (
6665 functools .partial (
@@ -70,5 +69,5 @@ def generate(self):
7069 skip = self .skip ,
7170 output = self .output ,
7271 ),
73- videos ,
72+ self ,
7473 )
0 commit comments