mirror of
https://github.com/ytdl-org/youtube-dl.git
synced 2024-11-24 15:50:26 +01:00
Add --min-views / --max-views (Fixes #1979)
This commit is contained in:
parent
dca02c80bc
commit
5fe18bdbde
@ -127,6 +127,15 @@ class YoutubeDL(object):
|
|||||||
noplaylist: Download single video instead of a playlist if in doubt.
|
noplaylist: Download single video instead of a playlist if in doubt.
|
||||||
age_limit: An integer representing the user's age in years.
|
age_limit: An integer representing the user's age in years.
|
||||||
Unsuitable videos for the given age are skipped.
|
Unsuitable videos for the given age are skipped.
|
||||||
|
min_views: An integer representing the minimum view count the video
|
||||||
|
must have in order to not be skipped.
|
||||||
|
Videos without view count information are always
|
||||||
|
downloaded. None for no limit.
|
||||||
|
max_views: An integer representing the maximum view count.
|
||||||
|
Videos that are more popular than that are not
|
||||||
|
downloaded.
|
||||||
|
Videos without view count information are always
|
||||||
|
downloaded. None for no limit.
|
||||||
download_archive: File name of a file where all downloads are recorded.
|
download_archive: File name of a file where all downloads are recorded.
|
||||||
Videos already present in the file are not downloaded
|
Videos already present in the file are not downloaded
|
||||||
again.
|
again.
|
||||||
@ -415,13 +424,14 @@ class YoutubeDL(object):
|
|||||||
def _match_entry(self, info_dict):
|
def _match_entry(self, info_dict):
|
||||||
""" Returns None iff the file should be downloaded """
|
""" Returns None iff the file should be downloaded """
|
||||||
|
|
||||||
|
video_title = info_dict.get('title', info_dict.get('id', u'video'))
|
||||||
if 'title' in info_dict:
|
if 'title' in info_dict:
|
||||||
# This can happen when we're just evaluating the playlist
|
# This can happen when we're just evaluating the playlist
|
||||||
title = info_dict['title']
|
title = info_dict['title']
|
||||||
matchtitle = self.params.get('matchtitle', False)
|
matchtitle = self.params.get('matchtitle', False)
|
||||||
if matchtitle:
|
if matchtitle:
|
||||||
if not re.search(matchtitle, title, re.IGNORECASE):
|
if not re.search(matchtitle, title, re.IGNORECASE):
|
||||||
return u'[download] "' + title + '" title did not match pattern "' + matchtitle + '"'
|
return u'"' + title + '" title did not match pattern "' + matchtitle + '"'
|
||||||
rejecttitle = self.params.get('rejecttitle', False)
|
rejecttitle = self.params.get('rejecttitle', False)
|
||||||
if rejecttitle:
|
if rejecttitle:
|
||||||
if re.search(rejecttitle, title, re.IGNORECASE):
|
if re.search(rejecttitle, title, re.IGNORECASE):
|
||||||
@ -430,14 +440,21 @@ class YoutubeDL(object):
|
|||||||
if date is not None:
|
if date is not None:
|
||||||
dateRange = self.params.get('daterange', DateRange())
|
dateRange = self.params.get('daterange', DateRange())
|
||||||
if date not in dateRange:
|
if date not in dateRange:
|
||||||
return u'[download] %s upload date is not in range %s' % (date_from_str(date).isoformat(), dateRange)
|
return u'%s upload date is not in range %s' % (date_from_str(date).isoformat(), dateRange)
|
||||||
|
view_count = info_dict.get('view_count', None)
|
||||||
|
if view_count is not None:
|
||||||
|
min_views = self.params.get('min_views')
|
||||||
|
if min_views is not None and view_count < min_views:
|
||||||
|
return u'Skipping %s, because it has not reached minimum view count (%d/%d)' % (video_title, view_count, min_views)
|
||||||
|
max_views = self.params.get('max_views')
|
||||||
|
if max_views is not None and view_count > max_views:
|
||||||
|
return u'Skipping %s, because it has exceeded the maximum view count (%d/%d)' % (video_title, view_count, max_views)
|
||||||
age_limit = self.params.get('age_limit')
|
age_limit = self.params.get('age_limit')
|
||||||
if age_limit is not None:
|
if age_limit is not None:
|
||||||
if age_limit < info_dict.get('age_limit', 0):
|
if age_limit < info_dict.get('age_limit', 0):
|
||||||
return u'Skipping "' + title + '" because it is age restricted'
|
return u'Skipping "' + title + '" because it is age restricted'
|
||||||
if self.in_download_archive(info_dict):
|
if self.in_download_archive(info_dict):
|
||||||
return (u'%s has already been recorded in archive'
|
return u'%s has already been recorded in archive' % video_title
|
||||||
% info_dict.get('title', info_dict.get('id', u'video')))
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -210,6 +210,14 @@ def parseOpts(overrideArguments=None):
|
|||||||
selection.add_option('--date', metavar='DATE', dest='date', help='download only videos uploaded in this date', default=None)
|
selection.add_option('--date', metavar='DATE', dest='date', help='download only videos uploaded in this date', default=None)
|
||||||
selection.add_option('--datebefore', metavar='DATE', dest='datebefore', help='download only videos uploaded before this date', default=None)
|
selection.add_option('--datebefore', metavar='DATE', dest='datebefore', help='download only videos uploaded before this date', default=None)
|
||||||
selection.add_option('--dateafter', metavar='DATE', dest='dateafter', help='download only videos uploaded after this date', default=None)
|
selection.add_option('--dateafter', metavar='DATE', dest='dateafter', help='download only videos uploaded after this date', default=None)
|
||||||
|
selection.add_option(
|
||||||
|
'--min-views', metavar='COUNT', dest='min_views',
|
||||||
|
default=None, type=int,
|
||||||
|
help="Do not download any videos with less than COUNT views",)
|
||||||
|
selection.add_option(
|
||||||
|
'--max-views', metavar='COUNT', dest='max_views',
|
||||||
|
default=None, type=int,
|
||||||
|
help="Do not download any videos with more than COUNT views",)
|
||||||
selection.add_option('--no-playlist', action='store_true', dest='noplaylist', help='download only the currently playing video', default=False)
|
selection.add_option('--no-playlist', action='store_true', dest='noplaylist', help='download only the currently playing video', default=False)
|
||||||
selection.add_option('--age-limit', metavar='YEARS', dest='age_limit',
|
selection.add_option('--age-limit', metavar='YEARS', dest='age_limit',
|
||||||
help='download only videos suitable for the given age',
|
help='download only videos suitable for the given age',
|
||||||
@ -668,6 +676,8 @@ def _real_main(argv=None):
|
|||||||
'keepvideo': opts.keepvideo,
|
'keepvideo': opts.keepvideo,
|
||||||
'min_filesize': opts.min_filesize,
|
'min_filesize': opts.min_filesize,
|
||||||
'max_filesize': opts.max_filesize,
|
'max_filesize': opts.max_filesize,
|
||||||
|
'min_views': opts.min_views,
|
||||||
|
'max_views': opts.max_views,
|
||||||
'daterange': date,
|
'daterange': date,
|
||||||
'cachedir': opts.cachedir,
|
'cachedir': opts.cachedir,
|
||||||
'youtube_print_sig_code': opts.youtube_print_sig_code,
|
'youtube_print_sig_code': opts.youtube_print_sig_code,
|
||||||
|
Loading…
Reference in New Issue
Block a user