allow multiple --reject-title and --match-title options

This commit is contained in:
Carl Harris 2015-12-01 17:49:20 -05:00
parent 4c6b4764f0
commit 2c72a8b489
4 changed files with 18 additions and 10 deletions

View File

@ -596,12 +596,15 @@ class YoutubeDL(object):
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): for pattern in matchtitle:
return '"' + title + '" title did not match pattern "' + matchtitle + '"' if re.search(patten, title, re.IGNORECASE):
rejecttitle = self.params.get('rejecttitle', False) break
if rejecttitle: else:
if re.search(rejecttitle, title, re.IGNORECASE): return '"' + title + '" title did not match patterns "' + ', '.join(matchtitle) + '"'
return '"' + title + '" title matched reject pattern "' + rejecttitle + '"' rejecttitle = self.params.get('rejecttitle', [])
for pattern in rejecttitle:
if re.search(pattern, title, re.IGNORECASE):
return '"' + title + '" title matched reject pattern "' + pattern + '"'
date = info_dict.get('upload_date', None) date = info_dict.get('upload_date', None)
if date is not None: if date is not None:
dateRange = self.params.get('daterange', DateRange()) dateRange = self.params.get('daterange', DateRange())

View File

@ -25,6 +25,7 @@ from .compat import (
from .utils import ( from .utils import (
DateRange, DateRange,
decodeOption, decodeOption,
decodeOptions,
DEFAULT_OUTTMPL, DEFAULT_OUTTMPL,
DownloadError, DownloadError,
match_filter_func, match_filter_func,
@ -324,8 +325,8 @@ def _real_main(argv=None):
'listsubtitles': opts.listsubtitles, 'listsubtitles': opts.listsubtitles,
'subtitlesformat': opts.subtitlesformat, 'subtitlesformat': opts.subtitlesformat,
'subtitleslangs': opts.subtitleslangs, 'subtitleslangs': opts.subtitleslangs,
'matchtitle': decodeOption(opts.matchtitle), 'matchtitle': decodeOptions(opts.matchtitle),
'rejecttitle': decodeOption(opts.rejecttitle), 'rejecttitle': decodeOptions(opts.rejecttitle),
'max_downloads': opts.max_downloads, 'max_downloads': opts.max_downloads,
'prefer_free_formats': opts.prefer_free_formats, 'prefer_free_formats': opts.prefer_free_formats,
'verbose': opts.verbose, 'verbose': opts.verbose,

View File

@ -222,11 +222,11 @@ def parseOpts(overrideArguments=None):
help='Playlist video items to download. Specify indices of the videos in the playlist separated by commas like: "--playlist-items 1,2,5,8" if you want to download videos indexed 1, 2, 5, 8 in the playlist. You can specify range: "--playlist-items 1-3,7,10-13", it will download the videos at index 1, 2, 3, 7, 10, 11, 12 and 13.') help='Playlist video items to download. Specify indices of the videos in the playlist separated by commas like: "--playlist-items 1,2,5,8" if you want to download videos indexed 1, 2, 5, 8 in the playlist. You can specify range: "--playlist-items 1-3,7,10-13", it will download the videos at index 1, 2, 3, 7, 10, 11, 12 and 13.')
selection.add_option( selection.add_option(
'--match-title', '--match-title',
dest='matchtitle', metavar='REGEX', action='append', dest='matchtitle', metavar='REGEX',
help='Download only matching titles (regex or caseless sub-string)') help='Download only matching titles (regex or caseless sub-string)')
selection.add_option( selection.add_option(
'--reject-title', '--reject-title',
dest='rejecttitle', metavar='REGEX', action='append', dest='rejecttitle', metavar='REGEX',
help='Skip download for matching titles (regex or caseless sub-string)') help='Skip download for matching titles (regex or caseless sub-string)')
selection.add_option( selection.add_option(
'--max-downloads', '--max-downloads',

View File

@ -487,6 +487,10 @@ def decodeOption(optval):
assert isinstance(optval, compat_str) assert isinstance(optval, compat_str)
return optval return optval
def decodeOptions(optvals):
if optvals is None:
return optvals
return list(filter(lambda o: o, map(decodeOption, optvals)))
def formatSeconds(secs): def formatSeconds(secs):
if secs > 3600: if secs > 3600: