From f2c22d9f3ff2fde6179f07343b2708b753eada6d Mon Sep 17 00:00:00 2001 From: brotherBox Date: Fri, 28 Nov 2014 11:25:48 +0100 Subject: [PATCH] Fixed --playlist-start feature --- youtube_dl/YoutubeDL.py | 15 +++++++++------ youtube_dl/utils.py | 7 +++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index acec87d5e..13488d55e 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -548,7 +548,6 @@ class YoutubeDL(object): if not ie.working(): self.report_warning('The program functionality for this site has been marked as broken, ' 'and will probably not work.') - try: ie_result = ie.extract(url) if ie_result is None: # Finished already (backwards compatibility; listformats and friends should be moved here) @@ -668,16 +667,20 @@ class YoutubeDL(object): (ie_result['extractor'], playlist, n_all_entries, n_entries)) else: assert isinstance(ie_result['entries'], PagedList) - entries = ie_result['entries'].getslice( - playliststart, playlistend) + entries = ie_result['entries'] + if reverse: + entries = entries.getslice(0, None) + entries = entries[::-1] + entries = entries[playliststart:playlistend] + else: + entries = entries.getslice( + playliststart, playlistend) + n_entries = len(entries) self.to_screen( "[%s] playlist %s: Downloading %d videos" % (ie_result['extractor'], playlist, n_entries)) - if reverse: - entries = reversed(entries) - for i, entry in enumerate(entries, 1): self.to_screen('[download] Downloading video #%s of %s' % (i, n_entries)) extra = { diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 4d3cbac74..b685e9a93 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1265,16 +1265,19 @@ class OnDemandPagedList(PagedList): self._pagefunc = pagefunc self._pagesize = pagesize - def getslice(self, start=0, end=None): + def getslice(self, start=0, end=None, reverse=False): res = [] + + # r = list(itertools.count(start // self._pagesize)) + # for pagenum in r: for pagenum in itertools.count(start // self._pagesize): + # absolute videos before current page; page 2 * 50 v/p = 100 firstid = pagenum * self._pagesize nextfirstid = pagenum * self._pagesize + self._pagesize if start >= nextfirstid: continue page_results = list(self._pagefunc(pagenum)) - startv = ( start % self._pagesize if firstid <= start < nextfirstid