mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-02 11:26:41 +00:00
parent
28787f16c6
commit
b1a7cd056a
|
@ -465,19 +465,18 @@ def _dict_from_options_callback(
|
||||||
metavar='COUNT', dest='max_views', default=None, type=int,
|
metavar='COUNT', dest='max_views', default=None, type=int,
|
||||||
help=optparse.SUPPRESS_HELP)
|
help=optparse.SUPPRESS_HELP)
|
||||||
selection.add_option(
|
selection.add_option(
|
||||||
'--match-filter',
|
'--match-filters',
|
||||||
metavar='FILTER', dest='match_filter', default=None,
|
metavar='FILTER', dest='match_filter', action='append',
|
||||||
help=(
|
help=(
|
||||||
'Generic video filter. Any field (see "OUTPUT TEMPLATE") can be compared with a '
|
'Generic video filter. Any field (see "OUTPUT TEMPLATE") can be compared with a '
|
||||||
'number or a string using the operators defined in "Filtering formats". '
|
'number or a string using the operators defined in "Filtering formats". '
|
||||||
'You can also simply specify a field to match if the field is present '
|
'You can also simply specify a field to match if the field is present, '
|
||||||
'and "!field" to check if the field is not present. In addition, '
|
'use "!field" to check if the field is not present, and "&" to check multiple conditions. '
|
||||||
'Python style regular expression matching can be done using "~=", '
|
'Use a "\\" to escape "&" or quotes if needed. If used multiple times, '
|
||||||
'and multiple filters can be checked with "&". '
|
'the filter matches if atleast one of the conditions are met. Eg: --match-filter '
|
||||||
'Use a "\\" to escape "&" or quotes if needed. Eg: --match-filter '
|
'!is_live --match-filter "like_count>?100 & description~=\'(?i)\\bcats \\& dogs\\b\'" '
|
||||||
'"!is_live & like_count>?100 & description~=\'(?i)\\bcats \\& dogs\\b\'" '
|
'matches only videos that are not live OR those that have a like count more than 100 '
|
||||||
'matches only videos that are not live, has a like count more than 100 '
|
'(or the like field is not available) and also has a description '
|
||||||
'(or the like field is not available), and also has a description '
|
|
||||||
'that contains the phrase "cats & dogs" (ignoring case)'))
|
'that contains the phrase "cats & dogs" (ignoring case)'))
|
||||||
selection.add_option(
|
selection.add_option(
|
||||||
'--no-match-filter',
|
'--no-match-filter',
|
||||||
|
|
|
@ -3614,16 +3614,18 @@ def match_str(filter_str, dct, incomplete=False):
|
||||||
for filter_part in re.split(r'(?<!\\)&', filter_str))
|
for filter_part in re.split(r'(?<!\\)&', filter_str))
|
||||||
|
|
||||||
|
|
||||||
def match_filter_func(filter_str):
|
def match_filter_func(filters):
|
||||||
if filter_str is None:
|
if not filters:
|
||||||
return None
|
return None
|
||||||
|
filters = variadic(filters)
|
||||||
|
|
||||||
def _match_func(info_dict, *args, **kwargs):
|
def _match_func(info_dict, *args, **kwargs):
|
||||||
if match_str(filter_str, info_dict, *args, **kwargs):
|
if any(match_str(f, info_dict, *args, **kwargs) for f in filters):
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
video_title = info_dict.get('title', info_dict.get('id', 'video'))
|
video_title = info_dict.get('title') or info_dict.get('id') or 'video'
|
||||||
return '%s does not pass filter %s, skipping ..' % (video_title, filter_str)
|
filter_str = ') | ('.join(map(str.strip, filters))
|
||||||
|
return f'{video_title} does not pass filter ({filter_str}), skipping ..'
|
||||||
return _match_func
|
return _match_func
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue