From 2c72a8b489a2285484dd90ccf04ed2111ab826b7 Mon Sep 17 00:00:00 2001 From: Carl Harris Date: Tue, 1 Dec 2015 17:49:20 -0500 Subject: [PATCH] allow multiple --reject-title and --match-title options --- youtube_dl/YoutubeDL.py | 15 +++++++++------ youtube_dl/__init__.py | 5 +++-- youtube_dl/options.py | 4 ++-- youtube_dl/utils.py | 4 ++++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 9a8c7da05..baf6b2d1a 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -596,12 +596,15 @@ class YoutubeDL(object): title = info_dict['title'] matchtitle = self.params.get('matchtitle', False) if matchtitle: - if not re.search(matchtitle, title, re.IGNORECASE): - return '"' + title + '" title did not match pattern "' + matchtitle + '"' - rejecttitle = self.params.get('rejecttitle', False) - if rejecttitle: - if re.search(rejecttitle, title, re.IGNORECASE): - return '"' + title + '" title matched reject pattern "' + rejecttitle + '"' + for pattern in matchtitle: + if re.search(patten, title, re.IGNORECASE): + break + else: + return '"' + title + '" title did not match patterns "' + ', '.join(matchtitle) + '"' + 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) if date is not None: dateRange = self.params.get('daterange', DateRange()) diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 9f131f5db..d2e885c84 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -25,6 +25,7 @@ from .compat import ( from .utils import ( DateRange, decodeOption, + decodeOptions, DEFAULT_OUTTMPL, DownloadError, match_filter_func, @@ -324,8 +325,8 @@ def _real_main(argv=None): 'listsubtitles': opts.listsubtitles, 'subtitlesformat': opts.subtitlesformat, 'subtitleslangs': opts.subtitleslangs, - 'matchtitle': decodeOption(opts.matchtitle), - 'rejecttitle': decodeOption(opts.rejecttitle), + 'matchtitle': decodeOptions(opts.matchtitle), + 'rejecttitle': decodeOptions(opts.rejecttitle), 'max_downloads': opts.max_downloads, 'prefer_free_formats': opts.prefer_free_formats, 'verbose': opts.verbose, diff --git a/youtube_dl/options.py b/youtube_dl/options.py index c46e136bf..91a084443 100644 --- a/youtube_dl/options.py +++ b/youtube_dl/options.py @@ -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.') selection.add_option( '--match-title', - dest='matchtitle', metavar='REGEX', + action='append', dest='matchtitle', metavar='REGEX', help='Download only matching titles (regex or caseless sub-string)') selection.add_option( '--reject-title', - dest='rejecttitle', metavar='REGEX', + action='append', dest='rejecttitle', metavar='REGEX', help='Skip download for matching titles (regex or caseless sub-string)') selection.add_option( '--max-downloads', diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index d0606b4bc..2a95a5647 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -487,6 +487,10 @@ def decodeOption(optval): assert isinstance(optval, compat_str) return optval +def decodeOptions(optvals): + if optvals is None: + return optvals + return list(filter(lambda o: o, map(decodeOption, optvals))) def formatSeconds(secs): if secs > 3600: