Use determine_ext when saving the thumbnail
authorJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Fri, 12 Jul 2013 19:52:59 +0000 (21:52 +0200)
committerJaime Marquínez Ferrándiz <jaime.marquinez.ferrandiz@gmail.com>
Fri, 12 Jul 2013 20:08:49 +0000 (22:08 +0200)
Urls that contain a query produced filenames with wrong extensions

youtube_dl/YoutubeDL.py
youtube_dl/utils.py

index e2470611512698745181dcf45cebbebc67acdb65..cc5f761577cf946dd6824663c76bc298bb71fe23 100644 (file)
@@ -530,9 +530,7 @@ class YoutubeDL(object):
 
         if self.params.get('writethumbnail', False):
             if 'thumbnail' in info_dict:
-                thumb_format = info_dict['thumbnail'].rpartition(u'/')[2].rpartition(u'.')[2]
-                if not thumb_format:
-                    thumb_format = 'jpg'
+                thumb_format = determine_ext(info_dict['thumbnail'], u'jpg')
                 thumb_filename = filename.rpartition('.')[0] + u'.' + thumb_format
                 self.to_screen(u'[%s] %s: Downloading thumbnail ...' %
                                (info_dict['extractor'], info_dict['id']))
index 532ca585d295b2dadd40b4f84333751a64286d56..cf2ea654e892c5f8882a4ecaae19bdcb5afbbbfd 100644 (file)
@@ -650,12 +650,12 @@ def unified_strdate(date_str):
             pass
     return upload_date
 
-def determine_ext(url):
+def determine_ext(url, default_ext=u'unknown_video'):
     guess = url.partition(u'?')[0].rpartition(u'.')[2]
     if re.match(r'^[A-Za-z0-9]+$', guess):
         return guess
     else:
-        return u'unknown_video'
+        return default_ext
 
 def date_from_str(date_str):
     """