X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2F__init__.py;h=84b972d5128e6fddf16da6eadff9ff6ef4f63def;hb=b5809a68bf94e5aa1172e5415be8d7fb91877de8;hp=6d2b0ce8552734cee8d9aa1c0b9a01c4f70f82e3;hpb=58ca755f4062146fbb9ce9d4383f033b8a631ed0;p=youtube-dl diff --git a/youtube_dl/__init__.py b/youtube_dl/__init__.py index 6d2b0ce85..84b972d51 100644 --- a/youtube_dl/__init__.py +++ b/youtube_dl/__init__.py @@ -22,6 +22,8 @@ __license__ = 'Public Domain' __version__ = '2012.02.27' UPDATE_URL = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl' +UPDATE_URL_VERSION = 'https://raw.github.com/rg3/youtube-dl/master/LATEST_VERSION' +UPDATE_URL_EXE = 'https://raw.github.com/rg3/youtube-dl/master/youtube-dl.exe' import cookielib @@ -36,41 +38,72 @@ import sys import urllib2 import warnings -from Utils import * +from utils import * from FileDownloader import * from InfoExtractors import * -from PostProcessing import * +from PostProcessor import * def updateSelf(downloader, filename): ''' Update the program file with the latest version from the repository ''' # Note: downloader only used for options + if not os.access(filename, os.W_OK): sys.exit('ERROR: no write permissions on %s' % filename) downloader.to_screen(u'Updating to latest version...') - try: + urlv = urllib2.urlopen(UPDATE_URL_VERSION) + newversion = urlv.read().strip() + if newversion == __version__: + downloader.to_screen(u'youtube-dl is up-to-date (' + __version__ + ')') + return + urlv.close() + + if hasattr(sys, "frozen"): #py2exe + exe = os.path.abspath(filename) + directory = os.path.dirname(exe) + if not os.access(directory, os.W_OK): + sys.exit('ERROR: no write permissions on %s' % directory) + try: - urlh = urllib2.urlopen(UPDATE_URL) + urlh = urllib2.urlopen(UPDATE_URL_EXE) newcontent = urlh.read() + urlh.close() + with open(exe + '.new', 'wb') as outf: + outf.write(newcontent) + except (IOError, OSError), err: + sys.exit('ERROR: unable to download latest version') - vmatch = re.search("__version__ = '([^']+)'", newcontent) - if vmatch is not None and vmatch.group(1) == __version__: - downloader.to_screen(u'youtube-dl is up-to-date (' + __version__ + ')') - return - finally: + try: + bat = os.path.join(directory, 'youtube-dl-updater.bat') + b = open(bat, 'w') + + print >> b, """ +echo Updating youtube-dl... +ping 127.0.0.1 -n 5 -w 1000 > NUL +move /Y "%s.new" "%s" +del "%s" + """ %(exe, exe, bat) + + b.close() + + os.startfile(bat) + except (IOError, OSError), err: + sys.exit('ERROR: unable to overwrite current version') + + else: + try: + urlh = urllib2.urlopen(UPDATE_URL) + newcontent = urlh.read() urlh.close() - except (IOError, OSError), err: - sys.exit('ERROR: unable to download latest version') + except (IOError, OSError), err: + sys.exit('ERROR: unable to download latest version') - try: - outf = open(filename, 'wb') try: - outf.write(newcontent) - finally: - outf.close() - except (IOError, OSError), err: - sys.exit('ERROR: unable to overwrite current version') + with open(filename, 'wb') as outf: + outf.write(newcontent) + except (IOError, OSError), err: + sys.exit('ERROR: unable to overwrite current version') downloader.to_screen(u'Updated youtube-dl. Restart youtube-dl to use the new version.') @@ -260,11 +293,11 @@ 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)') + help='convert video files to audio-only files (requires ffmpeg or avconv and ffprobe or avprobe)') postproc.add_option('--audio-format', metavar='FORMAT', dest='audioformat', default='best', help='"best", "aac", "vorbis", "mp3", "m4a", or "wav"; best by default') postproc.add_option('--audio-quality', metavar='QUALITY', dest='audioquality', default='128K', - help='ffmpeg audio bitrate specification, 128k by default') + help='ffmpeg/avconv audio bitrate specification, 128k by default') postproc.add_option('-k', '--keep-video', action='store_true', dest='keepvideo', default=False, help='keeps the video file on disk after the post-processing; the video is erased by default') @@ -305,6 +338,7 @@ def gen_extractors(): YahooSearchIE(), DepositFilesIE(), FacebookIE(), + BlipTVUserIE(), BlipTVIE(), VimeoIE(), MyVideoIE(), @@ -317,6 +351,7 @@ def gen_extractors(): MixcloudIE(), StanfordOpenClassroomIE(), MTVIE(), + YoukuIE(), GenericIE() ] @@ -363,9 +398,6 @@ def _real_main(): urllib2.install_opener(opener) socket.setdefaulttimeout(300) # 5 minutes should be enough (famous last words) - if opts.verbose: - print(u'[debug] Proxy map: ' + str(proxy_handler.proxies)) - extractors = gen_extractors() if opts.list_extractors: @@ -463,6 +495,10 @@ def _real_main(): 'prefer_free_formats': opts.prefer_free_formats, 'verbose': opts.verbose, }) + + if opts.verbose: + fd.to_screen(u'[debug] Proxy map: ' + str(proxy_handler.proxies)) + for extractor in extractors: fd.add_info_extractor(extractor)