X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube-dl;h=d5ca2d4bac8239de1e11d4d89739365dfa35788f;hb=4b618047cee2250f141fb58dbfbc20be892c8035;hp=fc3cc8ad88902fa25910777cd8a0959688079623;hpb=caaa47d37215f498c033afb42972c135be8138d4;p=youtube-dl diff --git a/youtube-dl b/youtube-dl index fc3cc8ad8..d5ca2d4ba 100755 --- a/youtube-dl +++ b/youtube-dl @@ -1,6 +1,40 @@ #!/usr/bin/env python -import youtube_dl +import sys, os -if __name__ == '__main__': - youtube_dl.main() +try: + import urllib.request as compat_urllib_request +except ImportError: # Python 2 + import urllib2 as compat_urllib_request + +sys.stderr.write(u'Hi! We changed distribution method and now youtube-dl needs to update itself one more time.\n') +sys.stderr.write(u'This will only happen once. Simply press enter to go on. Sorry for the trouble!\n') +sys.stderr.write(u'The new location of the binaries is https://github.com/rg3/youtube-dl/downloads, not the git repository.\n\n') + +try: + raw_input() +except NameError: # Python 3 + input() + +filename = sys.argv[0] + +API_URL = "https://api.github.com/repos/rg3/youtube-dl/downloads" +BIN_URL = "https://github.com/downloads/rg3/youtube-dl/youtube-dl" + +if not os.access(filename, os.W_OK): + sys.exit('ERROR: no write permissions on %s' % filename) + +try: + urlh = compat_urllib_request.urlopen(BIN_URL) + newcontent = urlh.read() + urlh.close() +except (IOError, OSError) as err: + sys.exit('ERROR: unable to download latest version') + +try: + with open(filename, 'wb') as outf: + outf.write(newcontent) +except (IOError, OSError) as err: + sys.exit('ERROR: unable to overwrite current version') + +sys.stderr.write(u'Done! Now you can run youtube-dl.\n')