From 9ea4eb242c514b1c837367f574697165518f7dc9 Mon Sep 17 00:00:00 2001 From: MrS0m30n3 Date: Wed, 25 Mar 2015 21:46:04 +0200 Subject: [PATCH] Add Warning status #33 --- youtube_dl_gui/downloaders.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/youtube_dl_gui/downloaders.py b/youtube_dl_gui/downloaders.py index 378d244..e7fb11f 100644 --- a/youtube_dl_gui/downloaders.py +++ b/youtube_dl_gui/downloaders.py @@ -25,8 +25,8 @@ class YoutubeDLDownloader(object): """Python class for downloading videos using youtube-dl & subprocess. Attributes: - OK, ERROR, STOPPED, ALREADY, FILESIZE_ABORT (int): 'Random' integers - that describe the return code from the download() method. + OK, ERROR, STOPPED, ALREADY, FILESIZE_ABORT, WARNING (int): 'Random' + integers that describe the return code from the download() method. Args: youtubedl_path (string): Absolute path to youtube-dl binary. @@ -59,6 +59,7 @@ class YoutubeDLDownloader(object): STOPPED = 2 ALREADY = 3 FILESIZE_ABORT = 4 + WARNING = 5 def __init__(self, youtubedl_path, data_hook=None, log_manager=None): self.youtubedl_path = youtubedl_path @@ -95,6 +96,7 @@ class YoutubeDLDownloader(object): ALREADY (3): The given url is already downloaded. FILESIZE_ABORT (4): The corresponding url video file was larger or smaller from the given options filesize limit. + WARNING (5): A warning occured during the download process. """ self._reset() @@ -106,7 +108,12 @@ class YoutubeDLDownloader(object): stdout, stderr = self._read() if stderr: - self._return_code = self.ERROR + + if self._is_warning(stderr): + self._return_code = self.WARNING + else: + self._return_code = self.ERROR + self._log(stderr) if stdout: @@ -123,6 +130,9 @@ class YoutubeDLDownloader(object): self._proc.kill() self._return_code = self.STOPPED + def _is_warning(self, stderr): + return stderr.split(':')[0] == 'WARNING' + def _last_data_hook(self): """Set the last data information based on the return code. """ if self._return_code == self.OK: @@ -131,6 +141,10 @@ class YoutubeDLDownloader(object): self._data['status'] = 'Error' self._data['speed'] = '' self._data['eta'] = '' + elif self._return_code == self.WARNING: + self._data['status'] = 'Warning' + self._data['speed'] = '' + self._data['eta'] = '' elif self._return_code == self.STOPPED: self._data['status'] = 'Stopped' self._data['speed'] = ''