Skip to content

Commit 4953f86

Browse files
committed
GH-49: Enable progress using a decorator
1 parent e8072ad commit 4953f86

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/thumbnails/generator.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .constants import DEFAULT_SKIP
1313
from .pathtools import listdir
1414
from .pathtools import metadata_path
15-
from .progress import Progress
15+
from .progress import use_progress
1616
from .thumbnail import ThumbnailExistsError
1717
from .thumbnail import ThumbnailFactory
1818
from .video import Video
@@ -46,9 +46,8 @@ def worker(video, fmt, base, skip, output):
4646
thumbnail.prepare_frames()
4747
thumbnail.generate()
4848

49+
@use_progress
4950
def generate(self):
50-
Progress.stop()
51-
5251
self.inputs = [file for file in self.inputs if re.match(r"^.*\.(?:(?!png|vtt|json).)+$", file)]
5352
self.inputs = dict(zip(map(lambda i: metadata_path(i, self.output, self.format), self.inputs), self.inputs))
5453

@@ -73,5 +72,3 @@ def generate(self):
7372
),
7473
videos,
7574
)
76-
77-
Progress.stop()

src/thumbnails/progress.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@ def __exit__(self, exc_type, exc_val, _):
3838
if exc_type is not None:
3939
return self.update(exc_val, status=" ... [red]failure")
4040
self.update(self.done_description, status=" ... [green]success")
41+
42+
43+
def use_progress(func):
44+
"""Decorator for using the progress bar."""
45+
46+
@functools.wraps(func)
47+
def wrapper(*args, **kwargs):
48+
Progress.start()
49+
func(*args, **kwargs)
50+
Progress.stop()
51+
52+
return wrapper

0 commit comments

Comments
 (0)