aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/YoutubeDL.py
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2014-01-20 11:36:47 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2014-01-20 11:36:47 +0100
commitb7ab05908440915c6c5faa541abe00c62a88bc27 (patch)
tree3b7e87361b7dce60ff7bdbe13bd33844fcb7d18e /youtube_dl/YoutubeDL.py
parentc91778f8c0ba120378cb806f694fdc3f94a5634c (diff)
Add infrastructure for paged lists
This commit allows to download pages in playlists as needed instead of all at once. Before this commit, youtube-dl http://www.youtube.com/user/ANNnewsCH/videos --playlist-end 2 --skip-download took quite some time - now it's almost instantaneous. As an example, the youtube:user extractor has been converted. Fixes #2175
Diffstat (limited to 'youtube_dl/YoutubeDL.py')
-rw-r--r--youtube_dl/YoutubeDL.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py
index a0ab89b3d..2ad6f1028 100644
--- a/youtube_dl/YoutubeDL.py
+++ b/youtube_dl/YoutubeDL.py
@@ -39,6 +39,7 @@ from .utils import (
locked_file,
make_HTTPS_handler,
MaxDownloadsReached,
+ PagedList,
PostProcessingError,
platform_name,
preferredencoding,
@@ -575,19 +576,27 @@ class YoutubeDL(object):
playlist_results = []
- n_all_entries = len(ie_result['entries'])
playliststart = self.params.get('playliststart', 1) - 1
playlistend = self.params.get('playlistend', None)
# For backwards compatibility, interpret -1 as whole list
if playlistend == -1:
playlistend = None
- entries = ie_result['entries'][playliststart:playlistend]
- n_entries = len(entries)
-
- self.to_screen(
- "[%s] playlist '%s': Collected %d video ids (downloading %d of them)" %
- (ie_result['extractor'], playlist, n_all_entries, n_entries))
+ if isinstance(ie_result['entries'], list):
+ n_all_entries = len(ie_result['entries'])
+ entries = ie_result['entries'][playliststart:playlistend]
+ n_entries = len(entries)
+ self.to_screen(
+ "[%s] playlist %s: Collected %d video ids (downloading %d of them)" %
+ (ie_result['extractor'], playlist, n_all_entries, n_entries))
+ else:
+ assert isinstance(ie_result['entries'], PagedList)
+ entries = ie_result['entries'].getslice(
+ playliststart, playlistend)
+ n_entries = len(entries)
+ self.to_screen(
+ "[%s] playlist %s: Downloading %d videos" %
+ (ie_result['extractor'], playlist, n_entries))
for i, entry in enumerate(entries, 1):
self.to_screen('[download] Downloading video #%s of %s' % (i, n_entries))