From 093bcb556772a52ed2a4e68be0b9c440fa88a269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Mon, 30 Oct 2017 11:54:33 +0100 Subject: [PATCH] started extracting UI logic from coub_dl class --- coub-dl.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/coub-dl.py b/coub-dl.py index 12048ef..80a2c83 100755 --- a/coub-dl.py +++ b/coub-dl.py @@ -31,6 +31,10 @@ class File(Enum): OUTPUT = 4 +class DownloadFailure(RuntimeError): + pass + + class coub_dl: default_files = {Stream.AUDIO: 'audio', Stream.VIDEO: 'video', File.LIST: 'list.txt', File.LOOP: 'loop', File.FRACTION: 'fraction', @@ -49,8 +53,7 @@ class coub_dl: self.download_audio_stream() self.download_video_stream() self.read_extensions() - try: self.check_downloads() - except RuntimeError: exit('Failed to download streams! This usually happens when Coub changes something.') + self.check_downloads() self.fix_video_stream() # get stream lengths via ffprobe @@ -108,7 +111,7 @@ class coub_dl: def check_downloads(self): check = {Stream.VIDEO, Stream.AUDIO} if not all({exists(self._files_dict[item]) for item in check}): - raise RuntimeError('Download failed!') + raise DownloadFailure() def fix_video_stream(self): @@ -222,4 +225,5 @@ if __name__ == '__main__': for url in set(args.URLs): print_opt('\nCreating video from {}'.format(url)) - run(url, args.output, args.extension) + try: run(url, args.output, args.extension) + except DownloadFailure: exit('Failed to download streams! This usually happens when Coub changes something.')