Update README with new options
[youtube-dl.git] / youtube-dl
index 7483fcf..0e7f5d6 100755 (executable)
@@ -15,7 +15,7 @@ __author__  = (
        )
 
 __license__ = 'Public Domain'
-__version__ = '2011.09.15'
+__version__ = '2011.09.18c'
 
 UPDATE_URL = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl'
 
@@ -775,8 +775,7 @@ class FileDownloader(object):
 
                if not self.params.get('skip_download', False):
                        try:
-                               success,add_data = self._do_download(filename, info_dict['url'].encode('utf-8'), info_dict.get('player_url', None))
-                               info_dict.update(add_data)
+                               success = self._do_download(filename, info_dict)
                        except (OSError, IOError), err:
                                raise UnavailableVideoError
                        except (urllib2.URLError, httplib.HTTPException, socket.error), err:
@@ -865,7 +864,10 @@ class FileDownloader(object):
                        self.trouble(u'\nERROR: rtmpdump exited with code %d' % retval)
                        return False
 
-       def _do_download(self, filename, url, player_url):
+       def _do_download(self, filename, info_dict):
+               url = info_dict['url']
+               player_url = info_dict.get('player_url', None)
+
                # Check file already present
                if self.params.get('continuedl', False) and os.path.isfile(filename) and not self.params.get('nopart', False):
                        self.report_file_already_downloaded(filename)
@@ -877,7 +879,6 @@ class FileDownloader(object):
 
                tmpfilename = self.temp_name(filename)
                stream = None
-               open_mode = 'wb'
 
                # Do not include the Accept-Encoding header
                headers = {'Youtubedl-no-compression': 'True'}
@@ -890,11 +891,14 @@ class FileDownloader(object):
                else:
                        resume_len = 0
 
-               # Request parameters in case of being able to resume
-               if self.params.get('continuedl', False) and resume_len != 0:
-                       self.report_resuming_byte(resume_len)
-                       request.add_header('Range', 'bytes=%d-' % resume_len)
-                       open_mode = 'ab'
+               open_mode = 'wb'
+               if resume_len != 0:
+                       if self.params.get('continuedl', False):
+                               self.report_resuming_byte(resume_len)
+                               request.add_header('Range','bytes=%d-' % resume_len)
+                               open_mode = 'ab'
+                       else:
+                               resume_len = 0
 
                count = 0
                retries = self.params.get('retries', 0)
@@ -978,10 +982,13 @@ class FileDownloader(object):
                        block_size = self.best_block_size(after - before, len(data_block))
 
                        # Progress message
-                       percent_str = self.calc_percent(byte_counter, data_len)
-                       eta_str = self.calc_eta(start, time.time(), data_len - resume_len, byte_counter - resume_len)
                        speed_str = self.calc_speed(start, time.time(), byte_counter - resume_len)
-                       self.report_progress(percent_str, data_len_str, speed_str, eta_str)
+                       if data_len is None:
+                               self.report_progress('Unknown %', data_len_str, speed_str, 'Unknown ETA')
+                       else:
+                               percent_str = self.calc_percent(byte_counter, data_len)
+                               eta_str = self.calc_eta(start, time.time(), data_len - resume_len, byte_counter - resume_len)
+                               self.report_progress(percent_str, data_len_str, speed_str, eta_str)
 
                        # Apply rate limit
                        self.slow_down(start, byte_counter - resume_len)
@@ -996,11 +1003,10 @@ class FileDownloader(object):
                self.try_rename(tmpfilename, filename)
 
                # Update file modification time
-               filetime = None
                if self.params.get('updatetime', True):
-                       filetime = self.try_utime(filename, data.info().get('last-modified', None))
+                       info_dict['filetime'] = self.try_utime(filename, data.info().get('last-modified', None))
 
-               return True, {'filetime': filetime}
+               return True
 
 
 class InfoExtractor(object):
@@ -1076,13 +1082,13 @@ class InfoExtractor(object):
 class YoutubeIE(InfoExtractor):
        """Information extractor for youtube.com."""
 
-       _VALID_URL = r'^((?:https?://)?(?:youtu\.be/|(?:\w+\.)?youtube(?:-nocookie)?\.com/)(?:(?:(?:v|embed|e)/)|(?:(?:watch(?:_popup)?(?:\.php)?)?(?:\?|#!?)(?:.+&)?v=))?)?([0-9A-Za-z_-]+)(?(1).+)?$'
+       _VALID_URL = r'^((?:https?://)?(?:youtu\.be/|(?:\w+\.)?youtube(?:-nocookie)?\.com/)(?!view_play_list|my_playlists|artist|playlist)(?:(?:(?:v|embed|e)/)|(?:(?:watch(?:_popup)?(?:\.php)?)?(?:\?|#!?)(?:.+&)?v=))?)?([0-9A-Za-z_-]+)(?(1).+)?$'
        _LANG_URL = r'http://www.youtube.com/?hl=en&persist_hl=1&gl=US&persist_gl=1&opt_out_ackd=1'
        _LOGIN_URL = 'https://www.youtube.com/signup?next=/&gl=US&hl=en'
        _AGE_URL = 'http://www.youtube.com/verify_age?next_url=/&gl=US&hl=en'
        _NETRC_MACHINE = 'youtube'
        # Listed in order of quality
-       _available_formats = ['38', '37', '45', '22', '43', '35', '34', '18', '6', '5', '17', '13']
+       _available_formats = ['38', '37', '22', '45', '35', '44', '34', '18', '43', '6', '5', '17', '13']
        _video_extensions = {
                '13': '3gp',
                '17': 'mp4',
@@ -1091,6 +1097,7 @@ class YoutubeIE(InfoExtractor):
                '37': 'mp4',
                '38': 'video', # You actually don't know if this will be MOV, AVI or whatever
                '43': 'webm',
+               '44': 'webm',
                '45': 'webm',
        }
        IE_NAME = u'youtube'
@@ -3169,7 +3176,7 @@ class ComedyCentralIE(InfoExtractor):
 class EscapistIE(InfoExtractor):
        """Information extractor for The Escapist """
 
-       _VALID_URL = r'^(https?://)?(www\.)escapistmagazine.com/videos/view/(?P<showname>[^/]+)/(?P<episode>[^/?]+)[/?].*$'
+       _VALID_URL = r'^(https?://)?(www\.)?escapistmagazine.com/videos/view/(?P<showname>[^/]+)/(?P<episode>[^/?]+)[/?]?.*$'
        IE_NAME = u'escapist'
 
        def report_extraction(self, showName):
@@ -3344,12 +3351,14 @@ class FFmpegExtractAudioPP(PostProcessor):
 
                more_opts = []
                if self._preferredcodec == 'best' or self._preferredcodec == filecodec:
-                       if filecodec == 'aac' or filecodec == 'mp3':
+                       if filecodec == 'aac' or filecodec == 'mp3' or filecodec == 'vorbis':
                                # Lossless if possible
                                acodec = 'copy'
                                extension = filecodec
                                if filecodec == 'aac':
                                        more_opts = ['-f', 'adts']
+                               if filecodec == 'vorbis':
+                                       extension = 'ogg'
                        else:
                                # MP3 otherwise.
                                acodec = 'libmp3lame'
@@ -3359,13 +3368,15 @@ class FFmpegExtractAudioPP(PostProcessor):
                                        more_opts += ['-ab', self._preferredquality]
                else:
                        # We convert the audio (lossy)
-                       acodec = {'mp3': 'libmp3lame', 'aac': 'aac'}[self._preferredcodec]
+                       acodec = {'mp3': 'libmp3lame', 'aac': 'aac', 'vorbis': 'libvorbis'}[self._preferredcodec]
                        extension = self._preferredcodec
                        more_opts = []
                        if self._preferredquality is not None:
                                more_opts += ['-ab', self._preferredquality]
                        if self._preferredcodec == 'aac':
                                more_opts += ['-f', 'adts']
+                       if self._preferredcodec == 'vorbis':
+                               extension = 'ogg'
 
                (prefix, ext) = os.path.splitext(path)
                new_path = prefix + '.' + extension
@@ -3406,6 +3417,11 @@ def updateSelf(downloader, filename):
                try:
                        urlh = urllib.urlopen(UPDATE_URL)
                        newcontent = urlh.read()
+                       
+                       vmatch = re.search("__version__ = '([^']+)'", newcontent)
+                       if vmatch is not None and vmatch.group(1) == __version__:
+                               downloader.to_screen('youtube-dl is up-to-date (' + __version__ + ')')
+                               return
                finally:
                        urlh.close()
        except (IOError, OSError), err:
@@ -3420,7 +3436,7 @@ def updateSelf(downloader, filename):
        except (IOError, OSError), err:
                sys.exit('ERROR: unable to overwrite current version')
 
-       downloader.to_screen('Updated youtube-dl. Restart to use the new version.')
+       downloader.to_screen('Updated youtube-dl. Restart youtube-dl to use the new version.')
 
 def parseOpts():
        # Deferred imports
@@ -3567,8 +3583,11 @@ def parseOpts():
                        action='store_true', dest='nooverwrites', help='do not overwrite files', default=False)
        filesystem.add_option('-c', '--continue',
                        action='store_true', dest='continue_dl', help='resume partially downloaded files', default=False)
+       filesystem.add_option('--no-continue',
+                       action='store_false', dest='continue_dl',
+                       help='do not resume partially downloaded files (restart from beginning)')
        filesystem.add_option('--cookies',
-                       dest='cookiefile', metavar='FILE', help='file to dump cookie jar to')
+                       dest='cookiefile', metavar='FILE', help='file to read cookies from and dump cookie jar in')
        filesystem.add_option('--no-part',
                        action='store_true', dest='nopart', help='do not use .part files', default=False)
        filesystem.add_option('--no-mtime',
@@ -3585,7 +3604,7 @@ def parseOpts():
        postproc.add_option('--extract-audio', action='store_true', dest='extractaudio', default=False,
                        help='convert video files to audio-only files (requires ffmpeg and ffprobe)')
        postproc.add_option('--audio-format', metavar='FORMAT', dest='audioformat', default='best',
-                       help='"best", "aac" or "mp3"; best by default')
+                       help='"best", "aac", "vorbis" or "mp3"; best by default')
        postproc.add_option('--audio-quality', metavar='QUALITY', dest='audioquality', default='128K',
                        help='ffmpeg audio bitrate specification, 128k by default')
        postproc.add_option('-k', '--keep-video', action='store_true', dest='keepvideo', default=False,
@@ -3612,12 +3631,12 @@ def gen_extractors():
        google_ie = GoogleIE()
        yahoo_ie = YahooIE()
        return [
-               youtube_ie,
-               MetacafeIE(youtube_ie),
-               DailymotionIE(),
                YoutubePlaylistIE(youtube_ie),
                YoutubeUserIE(youtube_ie),
                YoutubeSearchIE(youtube_ie),
+               youtube_ie,
+               MetacafeIE(youtube_ie),
+               DailymotionIE(),
                google_ie,
                GoogleSearchIE(google_ie),
                PhotobucketIE(),
@@ -3719,7 +3738,7 @@ def main():
        except (TypeError, ValueError), err:
                parser.error(u'invalid playlist end number specified')
        if opts.extractaudio:
-               if opts.audioformat not in ['best', 'aac', 'mp3']:
+               if opts.audioformat not in ['best', 'aac', 'mp3', 'vorbis']:
                        parser.error(u'invalid audio format specified')
 
        # File downloader