|
|
|
@ -17,8 +17,9 @@ class SponSkrubPP(PostProcessor):
|
|
|
|
|
_def_args = []
|
|
|
|
|
_exe_name = 'sponskrub'
|
|
|
|
|
|
|
|
|
|
def __init__(self, downloader, path='', args=None, ignoreerror=False, cut=False):
|
|
|
|
|
def __init__(self, downloader, path='', args=None, ignoreerror=False, cut=False, force=False):
|
|
|
|
|
PostProcessor.__init__(self, downloader)
|
|
|
|
|
self.force = force
|
|
|
|
|
self.cutout = cut
|
|
|
|
|
self.args = ['-chapter'] if not cut else []
|
|
|
|
|
self.args += self._def_args if args is None else compat_shlex_split(args)
|
|
|
|
@ -42,15 +43,19 @@ class SponSkrubPP(PostProcessor):
|
|
|
|
|
return [], information
|
|
|
|
|
|
|
|
|
|
if information['extractor_key'].lower() != 'youtube':
|
|
|
|
|
self._downloader.to_screen('[sponskrub] Skipping SponSkrub since it is not a YouTube video')
|
|
|
|
|
self._downloader.to_screen('[sponskrub] Skipping sponskrub since it is not a YouTube video')
|
|
|
|
|
return [], information
|
|
|
|
|
if self.cutout and not self.force and not information.get('__real_download', False):
|
|
|
|
|
self._downloader.to_screen(
|
|
|
|
|
'[sponskrub] Skipping sponskrub since the video was already downloaded. '
|
|
|
|
|
'Use --sponskrub-force to run sponskrub anyway')
|
|
|
|
|
return [], information
|
|
|
|
|
|
|
|
|
|
self._downloader.to_screen('[sponskrub] Trying to %s sponsor sections' % ('remove' if self.cutout else 'mark'))
|
|
|
|
|
if self.cutout:
|
|
|
|
|
self._downloader.to_screen(
|
|
|
|
|
'WARNING: The sponsor segments are cut out from the video based on timestamp. '
|
|
|
|
|
'This will cause the subtitles to go out of sync. '
|
|
|
|
|
'Also, if run multiple times, unintended parts of the video could be cut out.')
|
|
|
|
|
self._downloader.to_screen('WARNING: Cutting out sponsor segments will cause the subtitles to go out of sync.')
|
|
|
|
|
if not information.get('__real_download', False):
|
|
|
|
|
self._downloader.to_screen('WARNING: If sponskrub is run multiple times, unintended parts of the video could be cut out.')
|
|
|
|
|
|
|
|
|
|
filename = information['filepath']
|
|
|
|
|
temp_filename = filename + '.' + self._temp_ext + os.path.splitext(filename)[1]
|
|
|
|
@ -64,7 +69,7 @@ class SponSkrubPP(PostProcessor):
|
|
|
|
|
cmd = [encodeArgument(i) for i in cmd]
|
|
|
|
|
|
|
|
|
|
if self._downloader.params.get('verbose', False):
|
|
|
|
|
self._downloader.to_screen('[debug] SponSkrub command line: %s' % shell_quote(cmd))
|
|
|
|
|
self._downloader.to_screen('[debug] sponskrub command line: %s' % shell_quote(cmd))
|
|
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
|
|
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
|
|
|
|
|
@ -75,7 +80,7 @@ class SponSkrubPP(PostProcessor):
|
|
|
|
|
elif p.returncode != 3: # error code 3 means there was no info about the video
|
|
|
|
|
stderr = stderr.decode('utf-8', 'replace')
|
|
|
|
|
msg = stderr.strip().split('\n')[-1]
|
|
|
|
|
raise PostProcessingError(msg if msg else 'Sponskrub failed with error code %s!' % p.returncode)
|
|
|
|
|
raise PostProcessingError(msg if msg else 'sponskrub failed with error code %s!' % p.returncode)
|
|
|
|
|
else:
|
|
|
|
|
self._downloader.to_screen('[sponskrub] No segments in the SponsorBlock database')
|
|
|
|
|
return [], information
|
|
|
|
|