6 import urllib.request as compat_urllib_request
7 except ImportError: # Python 2
8 import urllib2 as compat_urllib_request
10 sys.stderr.write(u'Hi! We changed distribution method and now youtube-dl needs to update itself one more time.\n')
11 sys.stderr.write(u'This will only happen once. Simply press enter to go on. Sorry for the trouble!\n')
12 sys.stderr.write(u'The new location of the binaries is https://github.com/rg3/youtube-dl/downloads, not the git repository.\n\n')
16 except NameError: # Python 3
19 filename = sys.argv[0]
21 API_URL = "https://api.github.com/repos/rg3/youtube-dl/downloads"
22 BIN_URL = "https://github.com/downloads/rg3/youtube-dl/youtube-dl"
24 if not os.access(filename, os.W_OK):
25 sys.exit('ERROR: no write permissions on %s' % filename)
28 urlh = compat_urllib_request.urlopen(BIN_URL)
29 newcontent = urlh.read()
31 except (IOError, OSError) as err:
32 sys.exit('ERROR: unable to download latest version')
35 with open(filename, 'wb') as outf:
36 outf.write(newcontent)
37 except (IOError, OSError) as err:
38 sys.exit('ERROR: unable to overwrite current version')
40 sys.stderr.write(u'Done! Now you can run youtube-dl.\n')