Merge 5bdc10661f
into 48c5663c5f
This commit is contained in:
commit
337575fc54
|
@ -237,6 +237,8 @@ Alternatively, refer to the [developer instructions](#developer-instructions) fo
|
||||||
characters, and avoid "&" and spaces in
|
characters, and avoid "&" and spaces in
|
||||||
filenames
|
filenames
|
||||||
-w, --no-overwrites Do not overwrite files
|
-w, --no-overwrites Do not overwrite files
|
||||||
|
--yes-overwrites Overwrite all video and metadata files.
|
||||||
|
This option includes --no-continue.
|
||||||
-c, --continue Force resume of partially downloaded files.
|
-c, --continue Force resume of partially downloaded files.
|
||||||
By default, youtube-dl will resume
|
By default, youtube-dl will resume
|
||||||
downloads if possible.
|
downloads if possible.
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Keep this list in sync with the `offlinetest` target in Makefile
|
# Keep this list in sync with the `offlinetest` target in Makefile
|
||||||
DOWNLOAD_TESTS="age_restriction|download|iqiyi_sdk_interpreter|socks|subtitles|write_annotations|youtube_lists|youtube_signature"
|
DOWNLOAD_TESTS="age_restriction|download|iqiyi_sdk_interpreter|overwrites|socks|subtitles|write_annotations|youtube_lists|youtube_signature"
|
||||||
|
|
||||||
test_set=""
|
test_set=""
|
||||||
multiprocess_args=""
|
multiprocess_args=""
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import os
|
||||||
|
from os.path import join
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
|
from test.helper import try_rm
|
||||||
|
|
||||||
|
|
||||||
|
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
download_file = join(root_dir, 'test.webm')
|
||||||
|
|
||||||
|
|
||||||
|
class TestOverwrites(unittest.TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
# create an empty file
|
||||||
|
open(download_file, 'a').close()
|
||||||
|
|
||||||
|
def test_default_overwrites(self):
|
||||||
|
outp = subprocess.Popen(
|
||||||
|
[
|
||||||
|
sys.executable, 'youtube_dl/__main__.py',
|
||||||
|
'-o', 'test.webm',
|
||||||
|
'https://www.youtube.com/watch?v=jNQXAC9IVRw'
|
||||||
|
], cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
sout, serr = outp.communicate()
|
||||||
|
self.assertTrue(b'has already been downloaded' in sout)
|
||||||
|
# if the file has no content, it has not been redownloaded
|
||||||
|
self.assertTrue(os.path.getsize(download_file) < 1)
|
||||||
|
|
||||||
|
def test_yes_overwrites(self):
|
||||||
|
outp = subprocess.Popen(
|
||||||
|
[
|
||||||
|
sys.executable, 'youtube_dl/__main__.py', '--yes-overwrites',
|
||||||
|
'-o', 'test.webm',
|
||||||
|
'https://www.youtube.com/watch?v=jNQXAC9IVRw'
|
||||||
|
], cwd=root_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
sout, serr = outp.communicate()
|
||||||
|
self.assertTrue(b'has already been downloaded' not in sout)
|
||||||
|
# if the file has no content, it has not been redownloaded
|
||||||
|
self.assertTrue(os.path.getsize(download_file) > 1)
|
||||||
|
|
||||||
|
def tearDown(self):
|
||||||
|
try_rm(join(root_dir, 'test.webm'))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
|
@ -166,6 +166,7 @@ class YoutubeDL(object):
|
||||||
restrictfilenames: Do not allow "&" and spaces in file names
|
restrictfilenames: Do not allow "&" and spaces in file names
|
||||||
ignoreerrors: Do not stop on download errors.
|
ignoreerrors: Do not stop on download errors.
|
||||||
force_generic_extractor: Force downloader to use the generic extractor
|
force_generic_extractor: Force downloader to use the generic extractor
|
||||||
|
overwrites: Overwrite all video and metadata files.
|
||||||
nooverwrites: Prevent overwriting files.
|
nooverwrites: Prevent overwriting files.
|
||||||
playliststart: Playlist item to start at.
|
playliststart: Playlist item to start at.
|
||||||
playlistend: Playlist item to end at.
|
playlistend: Playlist item to end at.
|
||||||
|
@ -631,6 +632,13 @@ class YoutubeDL(object):
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
self.to_screen('[download] The file has already been downloaded')
|
self.to_screen('[download] The file has already been downloaded')
|
||||||
|
|
||||||
|
def report_file_delete(self, file_name):
|
||||||
|
"""Report that existing file will be deleted."""
|
||||||
|
try:
|
||||||
|
self.to_screen('Deleting already existent file %s' % file_name)
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
self.to_screen('Deleting already existent file')
|
||||||
|
|
||||||
def prepare_filename(self, info_dict):
|
def prepare_filename(self, info_dict):
|
||||||
"""Generate the output filename."""
|
"""Generate the output filename."""
|
||||||
try:
|
try:
|
||||||
|
@ -1903,11 +1911,15 @@ class YoutubeDL(object):
|
||||||
'Requested formats are incompatible for merge and will be merged into mkv.')
|
'Requested formats are incompatible for merge and will be merged into mkv.')
|
||||||
# Ensure filename always has a correct extension for successful merge
|
# Ensure filename always has a correct extension for successful merge
|
||||||
filename = '%s.%s' % (filename_wo_ext, info_dict['ext'])
|
filename = '%s.%s' % (filename_wo_ext, info_dict['ext'])
|
||||||
if os.path.exists(encodeFilename(filename)):
|
file_exists = os.path.exists(encodeFilename(filename))
|
||||||
|
if not self.params.get('overwrites', False) and file_exists:
|
||||||
self.to_screen(
|
self.to_screen(
|
||||||
'[download] %s has already been downloaded and '
|
'[download] %s has already been downloaded and '
|
||||||
'merged' % filename)
|
'merged' % filename)
|
||||||
else:
|
else:
|
||||||
|
if file_exists:
|
||||||
|
self.report_file_delete(filename)
|
||||||
|
os.remove(encodeFilename(filename))
|
||||||
for f in requested_formats:
|
for f in requested_formats:
|
||||||
new_info = dict(info_dict)
|
new_info = dict(info_dict)
|
||||||
new_info.update(f)
|
new_info.update(f)
|
||||||
|
@ -1922,6 +1934,11 @@ class YoutubeDL(object):
|
||||||
info_dict['__postprocessors'] = postprocessors
|
info_dict['__postprocessors'] = postprocessors
|
||||||
info_dict['__files_to_merge'] = downloaded
|
info_dict['__files_to_merge'] = downloaded
|
||||||
else:
|
else:
|
||||||
|
# Delete existing file with --yes-overwrites
|
||||||
|
if self.params.get('overwrites', False):
|
||||||
|
if os.path.exists(encodeFilename(filename)):
|
||||||
|
self.report_file_delete(filename)
|
||||||
|
os.remove(encodeFilename(filename))
|
||||||
# Just a single file
|
# Just a single file
|
||||||
success = dl(filename, info_dict)
|
success = dl(filename, info_dict)
|
||||||
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:
|
||||||
|
|
|
@ -174,6 +174,11 @@ def _real_main(argv=None):
|
||||||
opts.max_sleep_interval = opts.sleep_interval
|
opts.max_sleep_interval = opts.sleep_interval
|
||||||
if opts.ap_mso and opts.ap_mso not in MSO_INFO:
|
if opts.ap_mso and opts.ap_mso not in MSO_INFO:
|
||||||
parser.error('Unsupported TV Provider, use --ap-list-mso to get a list of supported TV Providers')
|
parser.error('Unsupported TV Provider, use --ap-list-mso to get a list of supported TV Providers')
|
||||||
|
if opts.overwrites:
|
||||||
|
if opts.nooverwrites:
|
||||||
|
parser.error('--yes-overwrites conflicts with --no-overwrites')
|
||||||
|
# --yes-overwrites implies --no-continue
|
||||||
|
opts.continue_dl = False
|
||||||
|
|
||||||
def parse_retries(retries):
|
def parse_retries(retries):
|
||||||
if retries in ('inf', 'infinite'):
|
if retries in ('inf', 'infinite'):
|
||||||
|
@ -347,6 +352,7 @@ def _real_main(argv=None):
|
||||||
'force_generic_extractor': opts.force_generic_extractor,
|
'force_generic_extractor': opts.force_generic_extractor,
|
||||||
'ratelimit': opts.ratelimit,
|
'ratelimit': opts.ratelimit,
|
||||||
'nooverwrites': opts.nooverwrites,
|
'nooverwrites': opts.nooverwrites,
|
||||||
|
'overwrites': opts.overwrites,
|
||||||
'retries': opts.retries,
|
'retries': opts.retries,
|
||||||
'fragment_retries': opts.fragment_retries,
|
'fragment_retries': opts.fragment_retries,
|
||||||
'skip_unavailable_fragments': opts.skip_unavailable_fragments,
|
'skip_unavailable_fragments': opts.skip_unavailable_fragments,
|
||||||
|
|
|
@ -717,6 +717,10 @@ def parseOpts(overrideArguments=None):
|
||||||
'-w', '--no-overwrites',
|
'-w', '--no-overwrites',
|
||||||
action='store_true', dest='nooverwrites', default=False,
|
action='store_true', dest='nooverwrites', default=False,
|
||||||
help='Do not overwrite files')
|
help='Do not overwrite files')
|
||||||
|
filesystem.add_option(
|
||||||
|
'--yes-overwrites',
|
||||||
|
action='store_true', dest='overwrites', default=False,
|
||||||
|
help='Overwrite all video and metadata files. This option includes --no-continue.')
|
||||||
filesystem.add_option(
|
filesystem.add_option(
|
||||||
'-c', '--continue',
|
'-c', '--continue',
|
||||||
action='store_true', dest='continue_dl', default=True,
|
action='store_true', dest='continue_dl', default=True,
|
||||||
|
|
Loading…
Reference in New Issue