Integrated reverse playlist feature with internals
This commit is contained in:
parent
97b2409fde
commit
82f521272c
@ -529,7 +529,7 @@ class YoutubeDL(object):
|
|||||||
info_dict.setdefault(key, value)
|
info_dict.setdefault(key, value)
|
||||||
|
|
||||||
def extract_info(self, url, download=True, ie_key=None, extra_info={},
|
def extract_info(self, url, download=True, ie_key=None, extra_info={},
|
||||||
process=True, reverse=False):
|
process=True):
|
||||||
'''
|
'''
|
||||||
Returns a list with a dictionary for each video we find.
|
Returns a list with a dictionary for each video we find.
|
||||||
If 'download', also downloads the videos.
|
If 'download', also downloads the videos.
|
||||||
@ -561,8 +561,7 @@ class YoutubeDL(object):
|
|||||||
self.add_default_extra_info(ie_result, ie, url)
|
self.add_default_extra_info(ie_result, ie, url)
|
||||||
if process:
|
if process:
|
||||||
return self.process_ie_result(
|
return self.process_ie_result(
|
||||||
ie_result, download=download, extra_info=extra_info,
|
ie_result, download=download, extra_info=extra_info)
|
||||||
reverse=reverse)
|
|
||||||
else:
|
else:
|
||||||
return ie_result
|
return ie_result
|
||||||
except ExtractorError as de: # An error we somewhat expected
|
except ExtractorError as de: # An error we somewhat expected
|
||||||
@ -587,8 +586,7 @@ class YoutubeDL(object):
|
|||||||
'extractor_key': ie.ie_key(),
|
'extractor_key': ie.ie_key(),
|
||||||
})
|
})
|
||||||
|
|
||||||
def process_ie_result(self, ie_result, download=True, reverse=False,
|
def process_ie_result(self, ie_result, download=True, extra_info={}):
|
||||||
extra_info={}):
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Take the result of the ie(may be modified) and resolve all unresolved
|
Take the result of the ie(may be modified) and resolve all unresolved
|
||||||
@ -643,8 +641,7 @@ class YoutubeDL(object):
|
|||||||
make_result(e) for e in new_result['entries']]
|
make_result(e) for e in new_result['entries']]
|
||||||
|
|
||||||
return self.process_ie_result(
|
return self.process_ie_result(
|
||||||
new_result, download=download, extra_info=extra_info,
|
new_result, download=download, extra_info=extra_info)
|
||||||
reverse=False)
|
|
||||||
elif result_type == 'playlist' or result_type == 'multi_video':
|
elif result_type == 'playlist' or result_type == 'multi_video':
|
||||||
# We process each entry in the playlist
|
# We process each entry in the playlist
|
||||||
playlist = ie_result.get('title', None) or ie_result.get('id', None)
|
playlist = ie_result.get('title', None) or ie_result.get('id', None)
|
||||||
@ -668,7 +665,7 @@ class YoutubeDL(object):
|
|||||||
else:
|
else:
|
||||||
assert isinstance(ie_result['entries'], PagedList)
|
assert isinstance(ie_result['entries'], PagedList)
|
||||||
entries = ie_result['entries']
|
entries = ie_result['entries']
|
||||||
if reverse:
|
if self.params.get('reverse_playlist'):
|
||||||
entries = entries.getslice(0, None)
|
entries = entries.getslice(0, None)
|
||||||
entries = entries[::-1]
|
entries = entries[::-1]
|
||||||
entries = entries[playliststart:playlistend]
|
entries = entries[playliststart:playlistend]
|
||||||
@ -702,8 +699,7 @@ class YoutubeDL(object):
|
|||||||
|
|
||||||
entry_result = self.process_ie_result(entry,
|
entry_result = self.process_ie_result(entry,
|
||||||
download=download,
|
download=download,
|
||||||
extra_info=extra,
|
extra_info=extra)
|
||||||
reverse=reverse)
|
|
||||||
playlist_results.append(entry_result)
|
playlist_results.append(entry_result)
|
||||||
ie_result['entries'] = playlist_results
|
ie_result['entries'] = playlist_results
|
||||||
return ie_result
|
return ie_result
|
||||||
@ -725,7 +721,7 @@ class YoutubeDL(object):
|
|||||||
return r
|
return r
|
||||||
ie_result['entries'] = [
|
ie_result['entries'] = [
|
||||||
self.process_ie_result(_fixup(r), download=download,
|
self.process_ie_result(_fixup(r), download=download,
|
||||||
extra_info=extra_info, reverse=reverse)
|
extra_info=extra_info)
|
||||||
for r in ie_result['entries']
|
for r in ie_result['entries']
|
||||||
]
|
]
|
||||||
return ie_result
|
return ie_result
|
||||||
@ -1116,7 +1112,7 @@ class YoutubeDL(object):
|
|||||||
|
|
||||||
self.record_download_archive(info_dict)
|
self.record_download_archive(info_dict)
|
||||||
|
|
||||||
def download(self, url_list, reverse=True):
|
def download(self, url_list):
|
||||||
"""Download a given list of URLs."""
|
"""Download a given list of URLs."""
|
||||||
outtmpl = self.params.get('outtmpl', DEFAULT_OUTTMPL)
|
outtmpl = self.params.get('outtmpl', DEFAULT_OUTTMPL)
|
||||||
if (len(url_list) > 1 and
|
if (len(url_list) > 1 and
|
||||||
@ -1127,7 +1123,7 @@ class YoutubeDL(object):
|
|||||||
for url in url_list:
|
for url in url_list:
|
||||||
try:
|
try:
|
||||||
# It also downloads the videos
|
# It also downloads the videos
|
||||||
res = self.extract_info(url, reverse=reverse)
|
res = self.extract_info(url)
|
||||||
except UnavailableVideoError:
|
except UnavailableVideoError:
|
||||||
self.report_error('unable to download video')
|
self.report_error('unable to download video')
|
||||||
except MaxDownloadsReached:
|
except MaxDownloadsReached:
|
||||||
@ -1139,11 +1135,11 @@ class YoutubeDL(object):
|
|||||||
|
|
||||||
return self._download_retcode
|
return self._download_retcode
|
||||||
|
|
||||||
def download_with_info_file(self, info_filename, reverse=False):
|
def download_with_info_file(self, info_filename):
|
||||||
with io.open(info_filename, 'r', encoding='utf-8') as f:
|
with io.open(info_filename, 'r', encoding='utf-8') as f:
|
||||||
info = json.load(f)
|
info = json.load(f)
|
||||||
try:
|
try:
|
||||||
self.process_ie_result(info, download=True, reverse=reverse)
|
self.process_ie_result(info, download=True)
|
||||||
except DownloadError:
|
except DownloadError:
|
||||||
webpage_url = info.get('webpage_url')
|
webpage_url = info.get('webpage_url')
|
||||||
if webpage_url is not None:
|
if webpage_url is not None:
|
||||||
|
@ -247,6 +247,7 @@ def _real_main(argv=None):
|
|||||||
'continuedl': opts.continue_dl,
|
'continuedl': opts.continue_dl,
|
||||||
'noprogress': opts.noprogress,
|
'noprogress': opts.noprogress,
|
||||||
'progress_with_newline': opts.progress_with_newline,
|
'progress_with_newline': opts.progress_with_newline,
|
||||||
|
'reverse_playlist': opts.reverse_playlist,
|
||||||
'playliststart': opts.playliststart,
|
'playliststart': opts.playliststart,
|
||||||
'playlistend': opts.playlistend,
|
'playlistend': opts.playlistend,
|
||||||
'noplaylist': opts.noplaylist,
|
'noplaylist': opts.noplaylist,
|
||||||
@ -342,7 +343,7 @@ def _real_main(argv=None):
|
|||||||
if opts.load_info_filename is not None:
|
if opts.load_info_filename is not None:
|
||||||
retcode = ydl.download_with_info_file(opts.load_info_filename)
|
retcode = ydl.download_with_info_file(opts.load_info_filename)
|
||||||
else:
|
else:
|
||||||
retcode = ydl.download(all_urls, reverse=opts.reverse_playlist)
|
retcode = ydl.download(all_urls)
|
||||||
except MaxDownloadsReached:
|
except MaxDownloadsReached:
|
||||||
ydl.to_screen('--max-download limit reached, aborting.')
|
ydl.to_screen('--max-download limit reached, aborting.')
|
||||||
retcode = 101
|
retcode = 101
|
||||||
|
@ -237,7 +237,8 @@ def parseOpts(overrideArguments=None):
|
|||||||
help='Download advertisements as well (experimental)')
|
help='Download advertisements as well (experimental)')
|
||||||
selection.add_option(
|
selection.add_option(
|
||||||
'--reverse-playlist',
|
'--reverse-playlist',
|
||||||
dest='reverse_playlist', action='store_true', help='Reverse playlists')
|
help='Reverse playlists',
|
||||||
|
dest='reverse_playlist', action='store_true', default=False)
|
||||||
|
|
||||||
authentication = optparse.OptionGroup(parser, 'Authentication Options')
|
authentication = optparse.OptionGroup(parser, 'Authentication Options')
|
||||||
authentication.add_option(
|
authentication.add_option(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user