diff --git a/CHANGELOG b/CHANGELOG index 90921e70..c871ed46 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Switched to yt-dlp instead of youtube_dl - Added fallback for subtitle languages with IDs-like suffixes (#161) - Removed a reference to ZIM namespace that would break if first video has subtitles +- Fixed expected returncodes on errors (#166) ## [2.1.17] - 2022-08-01 diff --git a/youtube2zim/__main__.py b/youtube2zim/__main__.py index d78c732a..73062bb4 100644 --- a/youtube2zim/__main__.py +++ b/youtube2zim/__main__.py @@ -12,8 +12,8 @@ def main(): from youtube2zim.entrypoint import main as entry - entry() + return entry() if __name__ == "__main__": - main() + sys.exit(main()) diff --git a/youtube2zim/entrypoint.py b/youtube2zim/entrypoint.py index 20a2fb68..7c956365 100755 --- a/youtube2zim/entrypoint.py +++ b/youtube2zim/entrypoint.py @@ -4,6 +4,7 @@ import logging import argparse +import sys from .constants import NAME, SCRAPER, CHANNEL, PLAYLIST, USER, logger, YOUTUBE from .scraper import Youtube2Zim @@ -199,13 +200,13 @@ def main(): if args.max_concurrency < 1: raise ValueError(f"Invalid concurrency value: {args.max_concurrency}") scraper = Youtube2Zim(**dict(args._get_kwargs()), youtube_store=YOUTUBE) - scraper.run() + return scraper.run() except Exception as exc: logger.error(f"FAILED. An error occurred: {exc}") if args.debug: logger.exception(exc) - raise SystemExit(1) + return 1 if __name__ == "__main__": - main() + sys.exit(main()) diff --git a/youtube2zim/playlists/__main__.py b/youtube2zim/playlists/__main__.py index 03d3d4a8..27028287 100644 --- a/youtube2zim/playlists/__main__.py +++ b/youtube2zim/playlists/__main__.py @@ -12,8 +12,8 @@ def main(): from youtube2zim.playlists.entrypoint import main as entry - entry() + return entry() if __name__ == "__main__": - main() + sys.exit(main()) diff --git a/youtube2zim/playlists/entrypoint.py b/youtube2zim/playlists/entrypoint.py index a460b6d5..70ddeb10 100644 --- a/youtube2zim/playlists/entrypoint.py +++ b/youtube2zim/playlists/entrypoint.py @@ -4,6 +4,7 @@ import logging import argparse +import sys from ..constants import NAME, SCRAPER, CHANNEL, PLAYLIST, USER, logger from ..utils import has_argument @@ -85,13 +86,13 @@ def main(): try: handler = YoutubeHandler(dict(args._get_kwargs()), extra_args=extra_args) - raise SystemExit(handler.run()) + return handler.run() except Exception as exc: logger.error(f"FAILED. An error occurred: {exc}") if args.debug: logger.exception(exc) - raise SystemExit(1) + return 1 if __name__ == "__main__": - main() + sys.exit(main()) diff --git a/youtube2zim/playlists/scraper.py b/youtube2zim/playlists/scraper.py index 971c9078..ce01eaf5 100644 --- a/youtube2zim/playlists/scraper.py +++ b/youtube2zim/playlists/scraper.py @@ -179,7 +179,7 @@ def handle_single_zim(self): ) if self.debug: args.append("--debug") - sys.exit(subprocess.run(args).returncode) + return subprocess.run(args).returncode @staticmethod def compute_format(playlist, fmt):