From fbced7341df3e596ec1017346efecb5e433ba9ee Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 21 Jan 2021 01:37:02 +0530 Subject: [PATCH] [sponskrub] Better debug output and error message --- youtube_dlc/extractor/trovolive.py | 2 +- youtube_dlc/postprocessor/common.py | 10 ++++++---- youtube_dlc/postprocessor/sponskrub.py | 11 +++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/youtube_dlc/extractor/trovolive.py b/youtube_dlc/extractor/trovolive.py index 8ad3ebeca..174edfc51 100644 --- a/youtube_dlc/extractor/trovolive.py +++ b/youtube_dlc/extractor/trovolive.py @@ -108,4 +108,4 @@ def _extract_format_data(format_dict): 'is_live': try_get(player_info, lambda x: x['isLive'], bool), 'thumbnail': url_or_none(vod_info.get('coverUrl')), 'uploader_id': str_or_none(try_get(vod_details, lambda x: x['json'][video_id]['streamerInfo']['uid'])), - } \ No newline at end of file + } diff --git a/youtube_dlc/postprocessor/common.py b/youtube_dlc/postprocessor/common.py index a4f8ca63e..5b777fad1 100644 --- a/youtube_dlc/postprocessor/common.py +++ b/youtube_dlc/postprocessor/common.py @@ -40,9 +40,10 @@ def pp_key(cls): name = cls.__name__[:-2] return compat_str(name[6:]) if name[:6].lower() == 'ffmpeg' else name - def to_screen(self, text, *args, **kwargs): + def to_screen(self, text, prefix=True, *args, **kwargs): + tag = '[%s] ' % self.PP_NAME if prefix else '' if self._downloader: - return self._downloader.to_screen('[%s] %s' % (self.PP_NAME, text), *args, **kwargs) + return self._downloader.to_screen('%s%s' % (tag, text), *args, **kwargs) def report_warning(self, text, *args, **kwargs): if self._downloader: @@ -52,9 +53,10 @@ def report_error(self, text, *args, **kwargs): if self._downloader: return self._downloader.report_error(text, *args, **kwargs) - def write_debug(self, text, *args, **kwargs): + def write_debug(self, text, prefix=True, *args, **kwargs): + tag = '[debug] ' if prefix else '' if self.get_param('verbose', False): - return self._downloader.to_screen('[debug] %s' % text, *args, **kwargs) + return self._downloader.to_screen('%s%s' % (tag, text), *args, **kwargs) def get_param(self, name, default=None, *args, **kwargs): if self._downloader: diff --git a/youtube_dlc/postprocessor/sponskrub.py b/youtube_dlc/postprocessor/sponskrub.py index 4320b7c02..c8c83d0a9 100644 --- a/youtube_dlc/postprocessor/sponskrub.py +++ b/youtube_dlc/postprocessor/sponskrub.py @@ -63,7 +63,7 @@ def run(self, information): if os.path.exists(encodeFilename(temp_filename)): os.remove(encodeFilename(temp_filename)) - cmd = [self.path] + cmd = [self.path] if not self.cutout: cmd += ['-chapter'] cmd += compat_shlex_split(self.args) # For backward compatibility @@ -82,9 +82,8 @@ def run(self, information): elif p.returncode == 3: self.to_screen('No segments in the SponsorBlock database') else: - stderr = stderr.decode('utf-8', 'replace') - msg = stderr.strip() - if not self.get_param('verbose', False): - msg = msg.split('\n')[-1] - raise PostProcessingError(msg if msg else 'sponskrub failed with error code %s!' % p.returncode) + msg = stderr.decode('utf-8', 'replace').strip() or stdout.decode('utf-8', 'replace').strip() + self.write_debug(msg, prefix=False) + msg = msg.split('\n')[-1] + raise PostProcessingError(msg if msg else 'sponskrub failed with error code %s' % p.returncode) return [], information