started extracting UI logic from coub_dl class

This commit is contained in:
Kjistóf 2017-10-30 11:54:33 +01:00
parent a881bdaaf6
commit 093bcb5567

View File

@ -31,6 +31,10 @@ class File(Enum):
OUTPUT = 4 OUTPUT = 4
class DownloadFailure(RuntimeError):
pass
class coub_dl: class coub_dl:
default_files = {Stream.AUDIO: 'audio', Stream.VIDEO: 'video', default_files = {Stream.AUDIO: 'audio', Stream.VIDEO: 'video',
File.LIST: 'list.txt', File.LOOP: 'loop', File.FRACTION: 'fraction', File.LIST: 'list.txt', File.LOOP: 'loop', File.FRACTION: 'fraction',
@ -49,8 +53,7 @@ class coub_dl:
self.download_audio_stream() self.download_audio_stream()
self.download_video_stream() self.download_video_stream()
self.read_extensions() self.read_extensions()
try: self.check_downloads() self.check_downloads()
except RuntimeError: exit('Failed to download streams! This usually happens when Coub changes something.')
self.fix_video_stream() self.fix_video_stream()
# get stream lengths via ffprobe # get stream lengths via ffprobe
@ -108,7 +111,7 @@ class coub_dl:
def check_downloads(self): def check_downloads(self):
check = {Stream.VIDEO, Stream.AUDIO} check = {Stream.VIDEO, Stream.AUDIO}
if not all({exists(self._files_dict[item]) for item in check}): if not all({exists(self._files_dict[item]) for item in check}):
raise RuntimeError('Download failed!') raise DownloadFailure()
def fix_video_stream(self): def fix_video_stream(self):
@ -222,4 +225,5 @@ if __name__ == '__main__':
for url in set(args.URLs): for url in set(args.URLs):
print_opt('\nCreating video from {}'.format(url)) 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.')