Переглянути джерело

Fix --match-title and --reject-title decoding (Closes #690)

Philipp Hagemeister 12 роки тому
батько
коміт
8271226a55
3 змінених файлів з 11 додано та 4 видалено
  1. 0 2
      youtube_dl/FileDownloader.py
  2. 3 2
      youtube_dl/__init__.py
  3. 8 0
      youtube_dl/utils.py

+ 0 - 2
youtube_dl/FileDownloader.py

@@ -370,12 +370,10 @@ class FileDownloader(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:
-            matchtitle = matchtitle.decode('utf8')
             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'[download] "' + title + '" title did not match pattern "' + matchtitle + '"'
         rejecttitle = self.params.get('rejecttitle', False)
         rejecttitle = self.params.get('rejecttitle', False)
         if rejecttitle:
         if rejecttitle:
-            rejecttitle = rejecttitle.decode('utf8')
             if re.search(rejecttitle, title, re.IGNORECASE):
             if re.search(rejecttitle, title, re.IGNORECASE):
                 return u'"' + title + '" title matched reject pattern "' + rejecttitle + '"'
                 return u'"' + title + '" title matched reject pattern "' + rejecttitle + '"'
         return None
         return None

+ 3 - 2
youtube_dl/__init__.py

@@ -412,6 +412,7 @@ def _real_main():
             or (opts.useid and u'%(id)s.%(ext)s')
             or (opts.useid and u'%(id)s.%(ext)s')
             or (opts.autonumber and u'%(autonumber)s-%(id)s.%(ext)s')
             or (opts.autonumber and u'%(autonumber)s-%(id)s.%(ext)s')
             or u'%(id)s.%(ext)s')
             or u'%(id)s.%(ext)s')
+
     # File downloader
     # File downloader
     fd = FileDownloader({
     fd = FileDownloader({
         'usenetrc': opts.usenetrc,
         'usenetrc': opts.usenetrc,
@@ -450,8 +451,8 @@ def _real_main():
         'writeinfojson': opts.writeinfojson,
         'writeinfojson': opts.writeinfojson,
         'writesubtitles': opts.writesubtitles,
         'writesubtitles': opts.writesubtitles,
         'subtitleslang': opts.subtitleslang,
         'subtitleslang': opts.subtitleslang,
-        'matchtitle': opts.matchtitle,
-        'rejecttitle': opts.rejecttitle,
+        'matchtitle': decodeOption(opts.matchtitle),
+        'rejecttitle': decodeOption(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,

+ 8 - 0
youtube_dl/utils.py

@@ -420,6 +420,14 @@ def encodeFilename(s):
             encoding = 'utf-8'
             encoding = 'utf-8'
         return s.encode(encoding, 'ignore')
         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):
 class ExtractorError(Exception):
     """Error during info extraction."""
     """Error during info extraction."""