about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2013-02-21 17:09:39 +0100
committerPhilipp Hagemeister <phihag@phihag.de>2013-02-21 17:09:39 +0100
commit8271226a55bd3daa7eddfe2efc243892de02ccf4 (patch)
treec7135d07183cbba75f2f44fb6fb305d4c8223979
parent1013186a172a05d57e87857604719cae6b8d7049 (diff)
downloadyoutube-dl-8271226a55bd3daa7eddfe2efc243892de02ccf4.tar.gz
youtube-dl-8271226a55bd3daa7eddfe2efc243892de02ccf4.tar.xz
youtube-dl-8271226a55bd3daa7eddfe2efc243892de02ccf4.zip
Fix --match-title and --reject-title decoding (Closes #690)
-rw-r--r--youtube_dl/FileDownloader.py2
-rw-r--r--youtube_dl/__init__.py5
-rw-r--r--youtube_dl/utils.py8
3 files changed, 11 insertions, 4 deletions
diff --git a/youtube_dl/FileDownloader.py b/youtube_dl/FileDownloader.py
index 0ac526389..53c2d1dce 100644
--- a/youtube_dl/FileDownloader.py
+++ b/youtube_dl/FileDownloader.py
@@ -370,12 +370,10 @@ class FileDownloader(object):
         title = info_dict['title']
         matchtitle = self.params.get('matchtitle', False)
         if matchtitle:
-            matchtitle = matchtitle.decode('utf8')
             if not re.search(matchtitle, title, re.IGNORECASE):
                 return u'[download] "' + title + '" title did not match pattern "' + matchtitle + '"'
         rejecttitle = self.params.get('rejecttitle', False)
         if rejecttitle:
-            rejecttitle = rejecttitle.decode('utf8')
             if re.search(rejecttitle, title, re.IGNORECASE):
                 return u'"' + title + '" title matched reject pattern "' + rejecttitle + '"'
         return None
diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py
index f05331644..23e3c2ac2 100644
--- a/youtube_dl/__init__.py
+++ b/youtube_dl/__init__.py
@@ -412,6 +412,7 @@ def _real_main():
             or (opts.useid and u'%(id)s.%(ext)s')
             or (opts.autonumber and u'%(autonumber)s-%(id)s.%(ext)s')
             or u'%(id)s.%(ext)s')
+
     # File downloader
     fd = FileDownloader({
         'usenetrc': opts.usenetrc,
@@ -450,8 +451,8 @@ def _real_main():
         'writeinfojson': opts.writeinfojson,
         'writesubtitles': opts.writesubtitles,
         'subtitleslang': opts.subtitleslang,
-        'matchtitle': opts.matchtitle,
-        'rejecttitle': opts.rejecttitle,
+        'matchtitle': decodeOption(opts.matchtitle),
+        'rejecttitle': decodeOption(opts.rejecttitle),
         'max_downloads': opts.max_downloads,
         'prefer_free_formats': opts.prefer_free_formats,
         'verbose': opts.verbose,
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py
index e6ce028d6..95bd94843 100644
--- a/youtube_dl/utils.py
+++ b/youtube_dl/utils.py
@@ -420,6 +420,14 @@ def encodeFilename(s):
             encoding = 'utf-8'
         return s.encode(encoding, 'ignore')
 
+def decodeOption(optval):
+    if optval is None:
+        return optval
+    if isinstance(optval, bytes):
+        optval = optval.decode(preferredencoding())
+
+    assert isinstance(optval, compat_str)
+    return optval
 
 class ExtractorError(Exception):
     """Error during info extraction."""