Abort download in case of error writing file data to disk
[youtube-dl] / youtube-dl
index 266ed585424b684ed8ca5cecb5213e9657b7a0c2..fb231ae400d7e32cb70407395d48c940564bcf76 100755 (executable)
@@ -27,7 +27,7 @@ except ImportError:
        from cgi import parse_qs
 
 std_headers = {
-       'User-Agent': 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.7) Gecko/20100720 Firefox/3.6.7',
+       'User-Agent': 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100723 Firefox/3.6.8',
        'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language': 'en-us,en;q=0.5',
@@ -353,7 +353,7 @@ class FileDownloader(object):
                                (percent_str, data_len_str, speed_str, eta_str), skip_eol=True)
 
        def report_resuming_byte(self, resume_len):
-               """Report attemtp to resume at given byte."""
+               """Report attempt to resume at given byte."""
                self.to_stdout(u'[download] Resuming download at byte %s' % resume_len)
        
        def report_retry(self, count, retries):
@@ -404,7 +404,8 @@ class FileDownloader(object):
                        template_dict['ord'] = unicode('%05d' % self._num_downloads)
                        filename = self.params['outtmpl'] % template_dict
                except (ValueError, KeyError), err:
-                       self.trouble('ERROR: invalid output template or system charset: %s' % str(err))
+                       self.trouble(u'ERROR: invalid system charset or erroneous output template')
+                       return
                if self.params.get('nooverwrites', False) and os.path.exists(filename):
                        self.to_stderr(u'WARNING: file exists: %s; skipping' % filename)
                        return
@@ -593,7 +594,8 @@ class FileDownloader(object):
                        try:
                                stream.write(data_block)
                        except (IOError, OSError), err:
-                               self.trouble('\nERROR: unable to write data: %s' % str(err))
+                               self.trouble(u'\nERROR: unable to write data: %s' % str(err))
+                               return False
                        block_size = self.best_block_size(after - before, data_block_len)
 
                        # Progress message
@@ -1039,15 +1041,15 @@ class MetacafeIE(InfoExtractor):
                        return
                mediaURL = urllib.unquote(mobj.group(1))
 
-               #mobj = re.search(r'(?m)&gdaKey=(.*?)&', webpage)
-               #if mobj is None:
-               #       self._downloader.trouble(u'ERROR: unable to extract gdaKey')
-               #       return
-               #gdaKey = mobj.group(1)
-               #
-               #video_url = '%s?__gda__=%s' % (mediaURL, gdaKey)
-
-               video_url = mediaURL
+               # Extract gdaKey if available
+               mobj = re.search(r'(?m)&gdaKey=(.*?)&', webpage)
+               if mobj is None:
+                       video_url = mediaURL
+                       #self._downloader.trouble(u'ERROR: unable to extract gdaKey')
+                       #return
+               else:
+                       gdaKey = mobj.group(1)
+                       video_url = '%s?__gda__=%s' % (mediaURL, gdaKey)
 
                mobj = re.search(r'(?im)<title>(.*) - Video</title>', webpage)
                if mobj is None:
@@ -2087,7 +2089,7 @@ if __name__ == '__main__':
                # Parse command line
                parser = optparse.OptionParser(
                        usage='Usage: %prog [options] url...',
-                       version='2010.07.24',
+                       version='2010.08.04',
                        conflict_handler='resolve',
                )