Skip to content

Commit

Permalink
Fixed #166: better returncode on error
Browse files Browse the repository at this point in the history
  • Loading branch information
rgaudin committed Nov 7, 2022
1 parent 444744b commit bb2d85a
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions youtube2zim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def main():

from youtube2zim.entrypoint import main as entry

entry()
return entry()


if __name__ == "__main__":
main()
sys.exit(main())
7 changes: 4 additions & 3 deletions youtube2zim/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import argparse
import sys

from .constants import NAME, SCRAPER, CHANNEL, PLAYLIST, USER, logger, YOUTUBE
from .scraper import Youtube2Zim
Expand Down Expand Up @@ -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())
4 changes: 2 additions & 2 deletions youtube2zim/playlists/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def main():

from youtube2zim.playlists.entrypoint import main as entry

entry()
return entry()


if __name__ == "__main__":
main()
sys.exit(main())
7 changes: 4 additions & 3 deletions youtube2zim/playlists/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import logging
import argparse
import sys

from ..constants import NAME, SCRAPER, CHANNEL, PLAYLIST, USER, logger
from ..utils import has_argument
Expand Down Expand Up @@ -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())
2 changes: 1 addition & 1 deletion youtube2zim/playlists/scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit bb2d85a

Please sign in to comment.