From 14da409e8fe9729173938558f00dee92cd509bd7 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 25 Mar 2017 21:09:32 -0400 Subject: [PATCH 01/13] dramatically upgrade function of --dateafter option with regards to certain (bulk video) IEs known to return date-sorted playlists --- youtube_dl/YoutubeDL.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 21586f0f4..67a6c92d4 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -757,6 +757,15 @@ class YoutubeDL(object): self.report_warning('The program functionality for this site has been marked as broken, ' 'and will probably not work.') + try: + if self.original_ie: + pass # self.original_ie already exists + except AttributeError: + try: + self.original_ie = re.search("\.([^\.]+)'>", str(type(ie))).group(1) + except: + self.original_ie = None + try: ie_result = ie.extract(url) if ie_result is None: # Finished already (backwards compatibility; listformats and friends should be moved here) @@ -922,6 +931,8 @@ class YoutubeDL(object): x_forwarded_for = ie_result.get('__x_forwarded_for_ip') + reliably_date_ordered_IEs = ('YoutubeChannelIE, YoutubeUserIE') + for i, entry in enumerate(entries, 1): self.to_screen('[download] Downloading video %s of %s' % (i, n_entries)) # This __x_forwarded_for_ip thing is a bit ugly but requires @@ -948,7 +959,20 @@ class YoutubeDL(object): entry_result = self.process_ie_result(entry, download=download, extra_info=extra) - playlist_results.append(entry_result) + + try: + entry_result_date = entry_result['upload_date'] + entry_result_date_year = int(entry_result_date[0:4]) + entry_result_date_month = int(entry_result_date[4:6]) + entry_result_date_day = int(entry_result_date[6:8]) + entry_result_date = datetime.date(year=entry_result_date_year, month=entry_result_date_month, day=entry_result_date_day) + if self.original_ie in reliably_date_ordered_IEs and entry_result_date not in self.params['daterange']: + break + else: + playlist_results.append(entry_result) + except: # I don't really know what to expect, so in case of error just fall back to the previous, default, behavior + playlist_results.append(entry_result) + ie_result['entries'] = playlist_results self.to_screen('[download] Finished downloading playlist: %s' % playlist) return ie_result From e4e47f02031eb2efdf7485da642dfac316653e7f Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 25 Mar 2017 21:47:12 -0400 Subject: [PATCH 02/13] added a comment, probably unnecessary --- youtube_dl/YoutubeDL.py | 1 + 1 file changed, 1 insertion(+) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 67a6c92d4..ab72bdd4f 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -966,6 +966,7 @@ class YoutubeDL(object): entry_result_date_month = int(entry_result_date[4:6]) entry_result_date_day = int(entry_result_date[6:8]) entry_result_date = datetime.date(year=entry_result_date_year, month=entry_result_date_month, day=entry_result_date_day) + # if the entries originate with an info extractor known to return date-sorted results, simply break after we meet the first date out of range if self.original_ie in reliably_date_ordered_IEs and entry_result_date not in self.params['daterange']: break else: From 60f4c8d1ba76b5d7bb6c46b3593389e64999dc16 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 26 Mar 2017 14:11:59 -0400 Subject: [PATCH 03/13] much improved --- youtube_dl/YoutubeDL.py | 33 ++++++++++++--------------------- youtube_dl/options.py | 4 ++++ 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index ab72bdd4f..29c010e68 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -757,15 +757,6 @@ class YoutubeDL(object): self.report_warning('The program functionality for this site has been marked as broken, ' 'and will probably not work.') - try: - if self.original_ie: - pass # self.original_ie already exists - except AttributeError: - try: - self.original_ie = re.search("\.([^\.]+)'>", str(type(ie))).group(1) - except: - self.original_ie = None - try: ie_result = ie.extract(url) if ie_result is None: # Finished already (backwards compatibility; listformats and friends should be moved here) @@ -960,19 +951,19 @@ class YoutubeDL(object): download=download, extra_info=extra) - try: - entry_result_date = entry_result['upload_date'] - entry_result_date_year = int(entry_result_date[0:4]) - entry_result_date_month = int(entry_result_date[4:6]) - entry_result_date_day = int(entry_result_date[6:8]) - entry_result_date = datetime.date(year=entry_result_date_year, month=entry_result_date_month, day=entry_result_date_day) - # if the entries originate with an info extractor known to return date-sorted results, simply break after we meet the first date out of range - if self.original_ie in reliably_date_ordered_IEs and entry_result_date not in self.params['daterange']: + # import pudb; pudb.set_trace() + entry_result_uploaddate = entry_result.get('upload_date') + if entry_result_uploaddate: + entry_result_uploaddate_dateobject = datetime.date( + year=int(entry_result_uploaddate[0:4]), + month=int(entry_result_uploaddate[4:6]), + day=int(entry_result_uploaddate[6:8]) + ) + + if self.params.get('date_ordered_playlist') and entry_result_uploaddate_dateobject not in self.params.get('daterange'): break - else: - playlist_results.append(entry_result) - except: # I don't really know what to expect, so in case of error just fall back to the previous, default, behavior - playlist_results.append(entry_result) + + playlist_results.append(entry_result) ie_result['entries'] = playlist_results self.to_screen('[download] Finished downloading playlist: %s' % playlist) diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 6b811535f..9c7c1a795 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -297,6 +297,10 @@ def parseOpts(overrideArguments=None): '--dateafter', metavar='DATE', dest='dateafter', default=None, help='Download only videos uploaded on or after this date (i.e. inclusive)') + selection.add_option( + '--date-ordered-playlist', + metavar='DATE', dest='date_ordered_playlist', default=None, action='store_true', + help='Playlist is known to be in chronologically descending order') selection.add_option( '--min-views', metavar='COUNT', dest='min_views', default=None, type=int, From 991789b3cdca2da2ecbdc9007eab2940071faf2c Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 26 Mar 2017 14:13:52 -0400 Subject: [PATCH 04/13] removed debug line --- youtube_dl/YoutubeDL.py | 1 - 1 file changed, 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 29c010e68..6982f06bf 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -951,7 +951,6 @@ class YoutubeDL(object): download=download, extra_info=extra) - # import pudb; pudb.set_trace() entry_result_uploaddate = entry_result.get('upload_date') if entry_result_uploaddate: entry_result_uploaddate_dateobject = datetime.date( From 5d268cfe59c13338d2a6c902965ca220b46a1cd8 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 26 Mar 2017 14:31:01 -0400 Subject: [PATCH 05/13] apparently it's completely unnecessary to manually construct a date object --- youtube_dl/YoutubeDL.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 6982f06bf..07247010a 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -951,16 +951,11 @@ class YoutubeDL(object): download=download, extra_info=extra) - entry_result_uploaddate = entry_result.get('upload_date') - if entry_result_uploaddate: - entry_result_uploaddate_dateobject = datetime.date( - year=int(entry_result_uploaddate[0:4]), - month=int(entry_result_uploaddate[4:6]), - day=int(entry_result_uploaddate[6:8]) - ) - - if self.params.get('date_ordered_playlist') and entry_result_uploaddate_dateobject not in self.params.get('daterange'): + try: + if self.params.get('date_ordered_playlist') and entry_result.get('upload_date') not in self.params.get('daterange'): break + except TypeError: + pass playlist_results.append(entry_result) From 900fd59355f468a307d1c15734359f135613dada Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 26 Mar 2017 14:34:11 -0400 Subject: [PATCH 06/13] got rid of try-except --- youtube_dl/YoutubeDL.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 07247010a..6e9e0cb82 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -951,11 +951,9 @@ class YoutubeDL(object): download=download, extra_info=extra) - try: - if self.params.get('date_ordered_playlist') and entry_result.get('upload_date') not in self.params.get('daterange'): - break - except TypeError: - pass + entry_result_uploaddate = entry_result.get('upload_date') + if self.params.get('date_ordered_playlist') and entry_result_uploaddate not in self.params.get('daterange'): + break playlist_results.append(entry_result) From 6a2fa7a8cf0ac2d50ea4d9080e8fbc2657467e14 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 26 Mar 2017 15:12:08 -0400 Subject: [PATCH 07/13] oops --- youtube_dl/YoutubeDL.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 6e9e0cb82..89663cc81 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -952,8 +952,9 @@ class YoutubeDL(object): extra_info=extra) entry_result_uploaddate = entry_result.get('upload_date') - if self.params.get('date_ordered_playlist') and entry_result_uploaddate not in self.params.get('daterange'): - break + if entry_result_uploaddate: + if self.params.get('date_ordered_playlist') and entry_result_uploaddate not in self.params.get('daterange'): + break playlist_results.append(entry_result) From 27fe09dfcc9a1a5c036c50f4ad81fdbbb914ceb0 Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 26 Mar 2017 22:54:55 -0400 Subject: [PATCH 08/13] again --- youtube_dl/YoutubeDL.py | 7 +++++-- youtube_dl/options.py | 11 ++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 89663cc81..1836c58cd 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -922,7 +922,10 @@ class YoutubeDL(object): x_forwarded_for = ie_result.get('__x_forwarded_for_ip') - reliably_date_ordered_IEs = ('YoutubeChannelIE, YoutubeUserIE') + if self.params.get('date_playlist_order') == 'asc' and not self.params.get('start_from_earliest'): + entries.reverse() + if self.params.get('date_playlist_order') == 'desc' and self.params.get('start_from_earliest'): + entries.reverse() for i, entry in enumerate(entries, 1): self.to_screen('[download] Downloading video %s of %s' % (i, n_entries)) @@ -953,7 +956,7 @@ class YoutubeDL(object): entry_result_uploaddate = entry_result.get('upload_date') if entry_result_uploaddate: - if self.params.get('date_ordered_playlist') and entry_result_uploaddate not in self.params.get('daterange'): + if self.params.get('date_playlist_order') in ('desc', 'asc') and entry_result_uploaddate not in self.params.get('daterange'): break playlist_results.append(entry_result) diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 9c7c1a795..918022a57 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -298,9 +298,14 @@ def parseOpts(overrideArguments=None): metavar='DATE', dest='dateafter', default=None, help='Download only videos uploaded on or after this date (i.e. inclusive)') selection.add_option( - '--date-ordered-playlist', - metavar='DATE', dest='date_ordered_playlist', default=None, action='store_true', - help='Playlist is known to be in chronologically descending order') + '--date-playlist-order', + metavar='ORDER', dest='date_playlist_order', default='none', + type='choice', choices=['asc', 'desc', 'none'], + help='Specify whether a playlist is known to be listed in chronological order. "Asc", "desc" or "none". Descending order is most recent to least, and is the most useful. Default is "none", and is like not using this option at all. Automatically stops after encountering the first video date outside of the date range configured by --date, --datebefore, and --dateafter.') + selection.add_option( + '--start-from-earliest', + metavar='FROM', dest='start_from_earliest', + action='store_true', help='In conjunction with --date-playlist-order, specify whether to start from the earliest videos or the latest. The default behavior is to start from the latest.') selection.add_option( '--min-views', metavar='COUNT', dest='min_views', default=None, type=int, From b2dd1983a46d00cfde07f233f21bf3bde9d5cfbd Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 27 Mar 2017 10:55:55 -0400 Subject: [PATCH 09/13] help messages --- youtube_dl/options.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 918022a57..6e29ec11d 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -301,11 +301,11 @@ def parseOpts(overrideArguments=None): '--date-playlist-order', metavar='ORDER', dest='date_playlist_order', default='none', type='choice', choices=['asc', 'desc', 'none'], - help='Specify whether a playlist is known to be listed in chronological order. "Asc", "desc" or "none". Descending order is most recent to least, and is the most useful. Default is "none", and is like not using this option at all. Automatically stops after encountering the first video date outside of the date range configured by --date, --datebefore, and --dateafter.') + help='Specify whether a playlist is known to be listed in chronological order. "Asc", "desc" or "none". Descending order is most recent to least, and is useful for batch-downloading the new videos from a Youtube channel. Default is "none", and is like not using this option at all. Causes youtube-dl to automatically stop after encountering the first video date outside of the date range configured by --date, --datebefore, and/or --dateafter.') selection.add_option( '--start-from-earliest', - metavar='FROM', dest='start_from_earliest', - action='store_true', help='In conjunction with --date-playlist-order, specify whether to start from the earliest videos or the latest. The default behavior is to start from the latest.') + metavar='FROM', dest='start_from_earliest', action='store_true', + help='Specify to start from the earliest rather than from the latest, the default behavior. This option doesn\'t have any effect without --date-playlist-order.') selection.add_option( '--min-views', metavar='COUNT', dest='min_views', default=None, type=int, From 611058327fd4ebb8c6fe13b62bf6603cc15d2c1f Mon Sep 17 00:00:00 2001 From: Mark Date: Sun, 2 Apr 2017 17:27:36 -0400 Subject: [PATCH 10/13] requested changes --- youtube_dl/YoutubeDL.py | 4 ++-- youtube_dl/options.py | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 1836c58cd..4ff1ca13c 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -922,9 +922,9 @@ class YoutubeDL(object): x_forwarded_for = ie_result.get('__x_forwarded_for_ip') - if self.params.get('date_playlist_order') == 'asc' and not self.params.get('start_from_earliest'): + if self.params.get('date_playlist_order') == 'desc' and self.params.get('playlist_reverse'): entries.reverse() - if self.params.get('date_playlist_order') == 'desc' and self.params.get('start_from_earliest'): + elif self.params.get('date_playlist_order') == 'asc' and not self.params.get('playlist_reverse'): entries.reverse() for i, entry in enumerate(entries, 1): diff --git a/youtube_dl/options.py b/youtube_dl/options.py index 6e29ec11d..f351d9fd7 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -301,11 +301,9 @@ def parseOpts(overrideArguments=None): '--date-playlist-order', metavar='ORDER', dest='date_playlist_order', default='none', type='choice', choices=['asc', 'desc', 'none'], - help='Specify whether a playlist is known to be listed in chronological order. "Asc", "desc" or "none". Descending order is most recent to least, and is useful for batch-downloading the new videos from a Youtube channel. Default is "none", and is like not using this option at all. Causes youtube-dl to automatically stop after encountering the first video date outside of the date range configured by --date, --datebefore, and/or --dateafter.') - selection.add_option( - '--start-from-earliest', - metavar='FROM', dest='start_from_earliest', action='store_true', - help='Specify to start from the earliest rather than from the latest, the default behavior. This option doesn\'t have any effect without --date-playlist-order.') + help='The playlist is known to be sorted in chronological order. ' + 'One of desc (most recent first), asc (least recent first), or none (no effect, the default). ' + 'Causes youtube-dl to stop downloading the playlist after encountering a video outside the specified date restrictions.') selection.add_option( '--min-views', metavar='COUNT', dest='min_views', default=None, type=int, @@ -491,11 +489,11 @@ def parseOpts(overrideArguments=None): help=optparse.SUPPRESS_HELP) downloader.add_option( '--playlist-reverse', - action='store_true', + dest='playlist_reverse', action='store_true', help='Download playlist videos in reverse order') downloader.add_option( '--playlist-random', - action='store_true', + dest='playlist_random', action='store_true', help='Download playlist videos in random order') downloader.add_option( '--xattr-set-filesize', From 21e8ffb8c7e651de8b0e07dff65fe6e447b5cebd Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 5 Apr 2017 18:19:50 -0400 Subject: [PATCH 11/13] stuff and stuff --- youtube_dl/YoutubeDL.py | 13 +++++++------ youtube_dl/__init__.py | 1 + youtube_dl/options.py | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 4ff1ca13c..bffa3b824 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -922,9 +922,9 @@ class YoutubeDL(object): x_forwarded_for = ie_result.get('__x_forwarded_for_ip') - if self.params.get('date_playlist_order') == 'desc' and self.params.get('playlist_reverse'): + if self.params.get('date_playlist_order') == 'desc' and self.params.get('playlistreverse'): entries.reverse() - elif self.params.get('date_playlist_order') == 'asc' and not self.params.get('playlist_reverse'): + elif self.params.get('date_playlist_order') == 'asc' and not self.params.get('playlistreverse'): entries.reverse() for i, entry in enumerate(entries, 1): @@ -954,10 +954,11 @@ class YoutubeDL(object): download=download, extra_info=extra) - entry_result_uploaddate = entry_result.get('upload_date') - if entry_result_uploaddate: - if self.params.get('date_playlist_order') in ('desc', 'asc') and entry_result_uploaddate not in self.params.get('daterange'): - break + if entry_result is not None: # backwards compatibility, lol + entry_result_uploaddate = entry_result.get('upload_date') + if entry_result_uploaddate: + if self.params.get('date_playlist_order') in ('desc', 'asc') and entry_result_uploaddate not in self.params.get('daterange'): + break playlist_results.append(entry_result) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index f15606568..b715bd69c 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -352,6 +352,7 @@ def _real_main(argv=None): 'playlistend': opts.playlistend, 'playlistreverse': opts.playlist_reverse, 'playlistrandom': opts.playlist_random, + 'date_playlist_order': opts.date_playlist_order, 'noplaylist': opts.noplaylist, 'logtostderr': opts.outtmpl == '-', 'consoletitle': opts.consoletitle, diff --git a/youtube_dl/options.py b/youtube_dl/options.py index f351d9fd7..d4c2fd971 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -489,11 +489,11 @@ def parseOpts(overrideArguments=None): help=optparse.SUPPRESS_HELP) downloader.add_option( '--playlist-reverse', - dest='playlist_reverse', action='store_true', + action='store_true', help='Download playlist videos in reverse order') downloader.add_option( '--playlist-random', - dest='playlist_random', action='store_true', + action='store_true', help='Download playlist videos in random order') downloader.add_option( '--xattr-set-filesize', From 4f4410d68fc4aa94cde17ff01aa05fe9ce473ae4 Mon Sep 17 00:00:00 2001 From: Mark Date: Fri, 7 Apr 2017 12:59:05 -0400 Subject: [PATCH 12/13] https://www.youtube.com/watch\?v\=jHPOzQzk9Qo --- youtube_dl/YoutubeDL.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index bffa3b824..50ed09742 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -922,11 +922,12 @@ class YoutubeDL(object): x_forwarded_for = ie_result.get('__x_forwarded_for_ip') - if self.params.get('date_playlist_order') == 'desc' and self.params.get('playlistreverse'): - entries.reverse() - elif self.params.get('date_playlist_order') == 'asc' and not self.params.get('playlistreverse'): + if ((self.params.get('date_playlist_order') == 'desc' and self.params.get('playlistreverse')) or + (self.params.get('date_playlist_order') == 'asc' and not self.params.get('playlistreverse'))): entries.reverse() + one_vid_within_range = False + for i, entry in enumerate(entries, 1): self.to_screen('[download] Downloading video %s of %s' % (i, n_entries)) # This __x_forwarded_for_ip thing is a bit ugly but requires @@ -954,11 +955,17 @@ class YoutubeDL(object): download=download, extra_info=extra) - if entry_result is not None: # backwards compatibility, lol + if entry_result is not None: # backwards compatibility entry_result_uploaddate = entry_result.get('upload_date') if entry_result_uploaddate: - if self.params.get('date_playlist_order') in ('desc', 'asc') and entry_result_uploaddate not in self.params.get('daterange'): - break + if self.params.get('date_playlist_order') in ('desc', 'asc'): + # we've come across at least one video within the specified daterange + if (entry_result_uploaddate in self.params.get('daterange') and + one_vid_within_range == False): + one_vid_within_range = True + elif (entry_result_uploaddate not in self.params.get('daterange') and + one_vid_within_range == True): + break playlist_results.append(entry_result) From cae6d1950f1a9012f26575ce10ce9f7b9e5a4ae5 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 8 Apr 2017 22:47:54 -0400 Subject: [PATCH 13/13] better --- youtube_dl/YoutubeDL.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 50ed09742..44c006e9f 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -922,12 +922,7 @@ class YoutubeDL(object): x_forwarded_for = ie_result.get('__x_forwarded_for_ip') - if ((self.params.get('date_playlist_order') == 'desc' and self.params.get('playlistreverse')) or - (self.params.get('date_playlist_order') == 'asc' and not self.params.get('playlistreverse'))): - entries.reverse() - - one_vid_within_range = False - + has_seen_withinrange_vid = False for i, entry in enumerate(entries, 1): self.to_screen('[download] Downloading video %s of %s' % (i, n_entries)) # This __x_forwarded_for_ip thing is a bit ugly but requires @@ -955,17 +950,20 @@ class YoutubeDL(object): download=download, extra_info=extra) - if entry_result is not None: # backwards compatibility - entry_result_uploaddate = entry_result.get('upload_date') - if entry_result_uploaddate: - if self.params.get('date_playlist_order') in ('desc', 'asc'): - # we've come across at least one video within the specified daterange - if (entry_result_uploaddate in self.params.get('daterange') and - one_vid_within_range == False): - one_vid_within_range = True - elif (entry_result_uploaddate not in self.params.get('daterange') and - one_vid_within_range == True): - break + entry_result_uploaddate = date_from_str(entry_result.get('upload_date')) + date_playlist_order = self.params.get('date_playlist_order') + daterangeobj = self.params.get('daterange') + dateafter = daterangeobj.start + datebefore = daterangeobj.end + if entry_result and entry_result_uploaddate and date_playlist_order in ('desc', 'asc'): + if not has_seen_withinrange_vid: + if entry_result_uploaddate in daterangeobj: + has_seen_withinrange_vid = True + elif ((date_playlist_order == 'desc' and entry_result_uploaddate < dateafter) or + (date_playlist_order == 'asc' and entry_result_uploaddate > datebefore)): + break + elif has_seen_withinrange_vid and entry_result_uploaddate not in daterangeobj: + break playlist_results.append(entry_result)