From c543a5a191fbf0c641451295a9a624439b66c68d Mon Sep 17 00:00:00 2001 From: glubsy Date: Tue, 24 May 2022 21:44:55 +0200 Subject: [PATCH] Fix blank output_dir crash Workaround for #42. If output_dir is initialized to None (for whatever reason, could be from a CLI argument, or bogus config file override) fall back to using current working directory to store the concat file. --- livestream_saver/merge.py | 6 ++++++ livestream_saver/util.py | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/livestream_saver/merge.py b/livestream_saver/merge.py index c80e3e6..518222a 100644 --- a/livestream_saver/merge.py +++ b/livestream_saver/merge.py @@ -70,6 +70,12 @@ def __init__( ext = "mp4" else: ext = "m4a" if datatype == "audio" else "mp4" + + if not output_dir: + logger.warning( + f"{__class__.name} got empty output_dir arg! Falling back to CWD." + ) + output_dir = Path() self._final_file: Path = output_dir / \ f"{video_id}_{datatype}_ffmpeg.{ext}" diff --git a/livestream_saver/util.py b/livestream_saver/util.py index a995f26..65b1907 100644 --- a/livestream_saver/util.py +++ b/livestream_saver/util.py @@ -54,6 +54,7 @@ def create_output_dir(output_dir: Path, video_id: Optional[str]) -> Path: return capture_dirpath def get_system_ua(): + # TODO dynamically generate instead of static strings SYSTEM = system() if SYSTEM == 'Windows': return 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0' @@ -63,8 +64,8 @@ def get_system_ua(): def is_wanted_based_on_metadata( data: Iterable[Optional[str]], - allow_re: re.Pattern = None, - block_re: re.Pattern = None + allow_re: Optional[re.Pattern] = None, + block_re: Optional[re.Pattern] = None ) -> bool: """Test each RE against each item in data (title, description...)""" if allow_re is None and block_re is None: