]> Raphaƫl G. Git Repositories - youtubedl/blob - devscripts/transition_helper.py
debian/control: Remove B-D on pandoc.
[youtubedl] / devscripts / transition_helper.py
1 #!/usr/bin/env python
2
3 import sys, os
4
5 try:
6 import urllib.request as compat_urllib_request
7 except ImportError: # Python 2
8 import urllib2 as compat_urllib_request
9
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')
13
14 try:
15 raw_input()
16 except NameError: # Python 3
17 input()
18
19 filename = sys.argv[0]
20
21 API_URL = "https://api.github.com/repos/rg3/youtube-dl/downloads"
22 BIN_URL = "https://github.com/downloads/rg3/youtube-dl/youtube-dl"
23
24 if not os.access(filename, os.W_OK):
25 sys.exit('ERROR: no write permissions on %s' % filename)
26
27 try:
28 urlh = compat_urllib_request.urlopen(BIN_URL)
29 newcontent = urlh.read()
30 urlh.close()
31 except (IOError, OSError) as err:
32 sys.exit('ERROR: unable to download latest version')
33
34 try:
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')
39
40 sys.stderr.write(u'Done! Now you can run youtube-dl.\n')