Detect when file was already downloaded

pull/212/head
pukkandan 5 years ago
parent a719e8df70
commit b7b623ac4d

@ -497,7 +497,9 @@ I will add some memorable short links to the binaries so you can download them e
with the data available in SponsorBlock API with the data available in SponsorBlock API
(Youtube only) (Youtube only)
--sponskrub-cut Cut out the sponsor sections instead of --sponskrub-cut Cut out the sponsor sections instead of
simply marking them (Experimental) simply marking them
--sponskrub-force Run sponskrub even if the video was
already downloaded. Use with caution
--sponskrub-location Location of the sponskrub binary; --sponskrub-location Location of the sponskrub binary;
either the path to the binary or its either the path to the binary or its
containing directory containing directory

@ -2002,13 +2002,16 @@ class YoutubeDL(object):
if not ensure_dir_exists(fname): if not ensure_dir_exists(fname):
return return
downloaded.append(fname) downloaded.append(fname)
partial_success = dl(fname, new_info) partial_success, real_download = dl(fname, new_info)
success = success and partial_success success = success and partial_success
info_dict['__postprocessors'] = postprocessors info_dict['__postprocessors'] = postprocessors
info_dict['__files_to_merge'] = downloaded info_dict['__files_to_merge'] = downloaded
# Even if there were no downloads, it is being merged only now
info_dict['__real_download'] = True
else: else:
# Just a single file # Just a single file
success = dl(filename, info_dict) success, real_download = dl(filename, info_dict)
info_dict['__real_download'] = real_download
except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err: except (compat_urllib_error.URLError, compat_http_client.HTTPException, socket.error) as err:
self.report_error('unable to download video data: %s' % error_to_compat_str(err)) self.report_error('unable to download video data: %s' % error_to_compat_str(err))
return return

@ -313,6 +313,7 @@ def _real_main(argv=None):
'path': opts.sponskrub_path, 'path': opts.sponskrub_path,
'args': opts.sponskrub_args, 'args': opts.sponskrub_args,
'cut': opts.sponskrub_cut, 'cut': opts.sponskrub_cut,
'force': opts.sponskrub_force,
'ignoreerror': opts.sponskrub is None, 'ignoreerror': opts.sponskrub is None,
}) })
# Please keep ExecAfterDownload towards the bottom as it allows the user to modify the final file in any way. # Please keep ExecAfterDownload towards the bottom as it allows the user to modify the final file in any way.

@ -351,7 +351,7 @@ class FileDownloader(object):
'status': 'finished', 'status': 'finished',
'total_bytes': os.path.getsize(encodeFilename(filename)), 'total_bytes': os.path.getsize(encodeFilename(filename)),
}) })
return True return True, False
if subtitle is False: if subtitle is False:
min_sleep_interval = self.params.get('sleep_interval') min_sleep_interval = self.params.get('sleep_interval')
@ -372,7 +372,7 @@ class FileDownloader(object):
'[download] Sleeping %s seconds...' % ( '[download] Sleeping %s seconds...' % (
sleep_interval_sub)) sleep_interval_sub))
time.sleep(sleep_interval_sub) time.sleep(sleep_interval_sub)
return self.real_download(filename, info_dict) return self.real_download(filename, info_dict), True
def real_download(self, filename, info_dict): def real_download(self, filename, info_dict):
"""Real download process. Redefine in subclasses.""" """Real download process. Redefine in subclasses."""

@ -890,7 +890,11 @@ def parseOpts(overrideArguments=None):
extractor.add_option( extractor.add_option(
'--sponskrub-cut', default=False, '--sponskrub-cut', default=False,
action='store_true', dest='sponskrub_cut', action='store_true', dest='sponskrub_cut',
help='Cut out the sponsor sections instead of simply marking them (Experimental)') help='Cut out the sponsor sections instead of simply marking them')
extractor.add_option(
'--sponskrub-force', default=False,
action='store_true', dest='sponskrub_force',
help='Run sponskrub even if the video was already downloaded')
extractor.add_option( extractor.add_option(
'--sponskrub-location', metavar='PATH', '--sponskrub-location', metavar='PATH',
dest='sponskrub_path', default='', dest='sponskrub_path', default='',

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

Loading…
Cancel
Save