From c2ff7f3bba41e15f640efbfbaae3b9109a63cc2e Mon Sep 17 00:00:00 2001 From: Philipp Mandler Date: Fri, 8 Dec 2023 17:41:12 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20reencode=20progress=20calc?= =?UTF-8?q?ulation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- worker/transcribee_worker/worker.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/worker/transcribee_worker/worker.py b/worker/transcribee_worker/worker.py index f77c6789..1ecefa67 100644 --- a/worker/transcribee_worker/worker.py +++ b/worker/transcribee_worker/worker.py @@ -88,6 +88,10 @@ def media_has_video(path: Path): return False +def is_video_profile(profile_name: str): + return profile_name.startswith("video:") + + class Worker: base_url: str token: str @@ -269,17 +273,17 @@ async def reencode( duration = get_duration(document_audio) self.set_duration(task, duration) - n_profiles = len(settings.REENCODE_PROFILES) - has_video = media_has_video(document_audio) - - for i, (profile, parameters) in enumerate(settings.REENCODE_PROFILES.items()): + applicable_profiles = { + profile_name: parameters + for profile_name, parameters in settings.REENCODE_PROFILES.items() + if has_video or not is_video_profile(profile_name) + } + n_profiles = len(applicable_profiles) + + for i, (profile, parameters) in enumerate(applicable_profiles.items()): output_path = self._get_tmpfile(f"reencode_{profile.replace(':', '_')}") - - video_profile = profile.startswith("video:") - - if video_profile and not has_video: - continue + video_profile = is_video_profile(profile) await reencode( document_audio,