]> gitweb @ CieloNegro.org - youtube-dl.git/blobdiff - youtube-dl
Improve temporary filename handling of special cases
[youtube-dl.git] / youtube-dl
index 0e96998072446b8895b9f307c828c034ebe82114..64c590fbfc30e954bde63cbde74d55af7997a308 100755 (executable)
@@ -3,6 +3,7 @@
 # Author: Ricardo Garcia Gonzalez
 # Author: Danny Colligan
 # Author: Benjamin Johnson
+# Author: Vasyl' Vavrychuk
 # License: Public domain code
 import cookielib
 import datetime
@@ -237,7 +238,9 @@ class FileDownloader(object):
        @staticmethod
        def temp_name(filename):
                """Returns a temporary filename for the given filename."""
-               return filename + '.part'
+               if filename == u'-' or (os.path.exists(filename) and not os.path.isfile(filename)):
+                       return filename
+               return filename + u'.part'
        
        @staticmethod
        def format_bytes(bytes):
@@ -360,6 +363,8 @@ class FileDownloader(object):
        
        def try_rename(self, old_filename, new_filename):
                try:
+                       if old_filename == new_filename:
+                               return
                        os.rename(old_filename, new_filename)
                except (IOError, OSError), err:
                        self.trouble(u'ERROR: unable to rename file')
@@ -954,9 +959,9 @@ class YoutubeIE(InfoExtractor):
                                self._downloader.trouble(u'ERROR: no known formats available for video')
                                return
                        if requested_format is None:
-                               video_url_list = [(existing_formats[0], get_video_template % existing_formats[0])] # Best quality
+                               video_url_list = [(existing_formats[0], url_map[existing_formats[0]])] # Best quality
                        elif requested_format == '-1':
-                               video_url_list = [(f, get_video_template % f) for f in existing_formats] # All formats
+                               video_url_list = [(f, url_map[f]) for f in existing_formats] # All formats
                        else:
                                video_url_list = [(requested_format, get_video_template % requested_format)] # Specific format