]> jfr.im git - yt-dlp.git/blame - devscripts/transition_helper.py
fix increment operator
[yt-dlp.git] / devscripts / transition_helper.py
CommitLineData
c7287a3c
FV
1#!/usr/bin/env python
2
3import sys, os
4
5try:
6 import urllib.request as compat_urllib_request
7except ImportError: # Python 2
8 import urllib2 as compat_urllib_request
9
10sys.stderr.write(u'Hi! We changed distribution method and now youtube-dl needs to update itself one more time.\n')
11sys.stderr.write(u'This will only happen once. Simply press enter to go on. Sorry for the trouble!\n')
12sys.stderr.write(u'The new location of the binaries is https://github.com/rg3/youtube-dl/downloads, not the git repository.\n\n')
13
14try:
15 raw_input()
16except NameError: # Python 3
17 input()
18
19filename = sys.argv[0]
20
21API_URL = "https://api.github.com/repos/rg3/youtube-dl/downloads"
22BIN_URL = "https://github.com/downloads/rg3/youtube-dl/youtube-dl"
23
24if not os.access(filename, os.W_OK):
25 sys.exit('ERROR: no write permissions on %s' % filename)
26
27try:
28 urlh = compat_urllib_request.urlopen(BIN_URL)
29 newcontent = urlh.read()
30 urlh.close()
31except (IOError, OSError) as err:
32 sys.exit('ERROR: unable to download latest version')
33
34try:
35 with open(filename, 'wb') as outf:
36 outf.write(newcontent)
37except (IOError, OSError) as err:
38 sys.exit('ERROR: unable to overwrite current version')
39
40sys.stderr.write(u'Done! Now you can run youtube-dl.\n')