1 Subject: Remove autoupdate mechanism
4 From: Nicolas Braud-Santoni <nicolas@braud-santoni.eu>
5 Reviewed-by: Rogério Theodoro de Brito <rbrito@ime.usp.br>
6 Last-Update: 2018-03-16
10 youtube_dl/__init__.py | 8 ++-
11 youtube_dl/options.py | 2 +-
12 youtube_dl/update.py | 187 -------------------------------------------------
13 3 files changed, 6 insertions(+), 191 deletions(-)
14 delete mode 100644 youtube_dl/update.py
16 --- a/youtube_dl/__init__.py
17 +++ b/youtube_dl/__init__.py
22 -from .update import update_self
23 from .downloader import (
27 with YoutubeDL(ydl_opts) as ydl:
30 - update_self(ydl.to_screen, opts.verbose, ydl._opener)
32 + "youtube-dl's self-update mechanism is disabled on Debian.\n"
33 + "Please update youtube-dl using apt(8)."
41 if (len(all_urls) < 1) and (opts.load_info_filename is None):
42 - if opts.update_self or opts.rm_cachedir:
43 + if opts.rm_cachedir:
46 ydl.warn_if_short_id(sys.argv[1:] if argv is None else argv)
47 --- a/youtube_dl/options.py
48 +++ b/youtube_dl/options.py
52 action='store_true', dest='update_self',
53 - help='Update this program to latest version. Make sure that you have sufficient permissions (run with sudo if needed)')
54 + help=optparse.SUPPRESS_HELP)
56 '-i', '--ignore-errors',
57 action='store_true', dest='ignoreerrors', default=False,
58 --- a/youtube_dl/update.py
61 -from __future__ import unicode_literals
70 -from zipimport import zipimporter
72 -from .utils import encode_compat_str
74 -from .version import __version__
77 -def rsa_verify(message, signature, key):
78 - from hashlib import sha256
79 - assert isinstance(message, bytes)
80 - byte_size = (len(bin(key[0])) - 2 + 8 - 1) // 8
81 - signature = ('%x' % pow(int(signature, 16), key[1], key[0])).encode()
82 - signature = (byte_size * 2 - len(signature)) * b'0' + signature
83 - asn1 = b'3031300d060960864801650304020105000420'
84 - asn1 += sha256(message).hexdigest().encode()
85 - if byte_size < len(asn1) // 2 + 11:
87 - expected = b'0001' + (byte_size - len(asn1) // 2 - 3) * b'ff' + b'00' + asn1
88 - return expected == signature
91 -def update_self(to_screen, verbose, opener):
92 - """Update the program file with the latest version from the repository"""
94 - UPDATE_URL = 'https://rg3.github.io/youtube-dl/update/'
95 - VERSION_URL = UPDATE_URL + 'LATEST_VERSION'
96 - JSON_URL = UPDATE_URL + 'versions.json'
97 - UPDATES_RSA_KEY = (0x9d60ee4d8f805312fdb15a62f87b95bd66177b91df176765d13514a0f1754bcd2057295c5b6f1d35daa6742c3ffc9a82d3e118861c207995a8031e151d863c9927e304576bc80692bc8e094896fcf11b66f3e29e04e3a71e9a11558558acea1840aec37fc396fb6b65dc81a1c4144e03bd1c011de62e3f1357b327d08426fe93, 65537)
99 - if not isinstance(globals().get('__loader__'), zipimporter) and not hasattr(sys, 'frozen'):
100 - to_screen('It looks like you installed youtube-dl with a package manager, pip, setup.py or a tarball. Please use that to update.')
103 - # Check if there is a new version
105 - newversion = opener.open(VERSION_URL).read().decode('utf-8').strip()
108 - to_screen(encode_compat_str(traceback.format_exc()))
109 - to_screen('ERROR: can\'t find the current version. Please try again later.')
111 - if newversion == __version__:
112 - to_screen('youtube-dl is up-to-date (' + __version__ + ')')
115 - # Download and check versions info
117 - versions_info = opener.open(JSON_URL).read().decode('utf-8')
118 - versions_info = json.loads(versions_info)
121 - to_screen(encode_compat_str(traceback.format_exc()))
122 - to_screen('ERROR: can\'t obtain versions info. Please try again later.')
124 - if 'signature' not in versions_info:
125 - to_screen('ERROR: the versions file is not signed or corrupted. Aborting.')
127 - signature = versions_info['signature']
128 - del versions_info['signature']
129 - if not rsa_verify(json.dumps(versions_info, sort_keys=True).encode('utf-8'), signature, UPDATES_RSA_KEY):
130 - to_screen('ERROR: the versions file signature is invalid. Aborting.')
133 - version_id = versions_info['latest']
135 - def version_tuple(version_str):
136 - return tuple(map(int, version_str.split('.')))
137 - if version_tuple(__version__) >= version_tuple(version_id):
138 - to_screen('youtube-dl is up to date (%s)' % __version__)
141 - to_screen('Updating to version ' + version_id + ' ...')
142 - version = versions_info['versions'][version_id]
144 - print_notes(to_screen, versions_info['versions'])
146 - # sys.executable is set to the full pathname of the exe-file for py2exe
147 - filename = sys.executable if hasattr(sys, 'frozen') else sys.argv[0]
149 - if not os.access(filename, os.W_OK):
150 - to_screen('ERROR: no write permissions on %s' % filename)
154 - if hasattr(sys, 'frozen'):
156 - directory = os.path.dirname(exe)
157 - if not os.access(directory, os.W_OK):
158 - to_screen('ERROR: no write permissions on %s' % directory)
162 - urlh = opener.open(version['exe'][0])
163 - newcontent = urlh.read()
165 - except (IOError, OSError):
167 - to_screen(encode_compat_str(traceback.format_exc()))
168 - to_screen('ERROR: unable to download latest version')
171 - newcontent_hash = hashlib.sha256(newcontent).hexdigest()
172 - if newcontent_hash != version['exe'][1]:
173 - to_screen('ERROR: the downloaded file hash does not match. Aborting.')
177 - with open(exe + '.new', 'wb') as outf:
178 - outf.write(newcontent)
179 - except (IOError, OSError):
181 - to_screen(encode_compat_str(traceback.format_exc()))
182 - to_screen('ERROR: unable to write the new version')
186 - bat = os.path.join(directory, 'youtube-dl-updater.bat')
187 - with io.open(bat, 'w') as batfile:
190 -echo Waiting for file handle to be closed ...
191 -ping 127.0.0.1 -n 5 -w 1000 > NUL
192 -move /Y "%s.new" "%s" > NUL
193 -echo Updated youtube-dl to version %s.
194 -start /b "" cmd /c del "%%~f0"&exit /b"
195 - \n''' % (exe, exe, version_id))
197 - subprocess.Popen([bat]) # Continues to run in the background
198 - return # Do not show premature success messages
199 - except (IOError, OSError):
201 - to_screen(encode_compat_str(traceback.format_exc()))
202 - to_screen('ERROR: unable to overwrite current version')
206 - elif isinstance(globals().get('__loader__'), zipimporter):
208 - urlh = opener.open(version['bin'][0])
209 - newcontent = urlh.read()
211 - except (IOError, OSError):
213 - to_screen(encode_compat_str(traceback.format_exc()))
214 - to_screen('ERROR: unable to download latest version')
217 - newcontent_hash = hashlib.sha256(newcontent).hexdigest()
218 - if newcontent_hash != version['bin'][1]:
219 - to_screen('ERROR: the downloaded file hash does not match. Aborting.')
223 - with open(filename, 'wb') as outf:
224 - outf.write(newcontent)
225 - except (IOError, OSError):
227 - to_screen(encode_compat_str(traceback.format_exc()))
228 - to_screen('ERROR: unable to overwrite current version')
231 - to_screen('Updated youtube-dl. Restart youtube-dl to use the new version.')
234 -def get_notes(versions, fromVersion):
236 - for v, vdata in sorted(versions.items()):
237 - if v > fromVersion:
238 - notes.extend(vdata.get('notes', []))
242 -def print_notes(to_screen, versions, fromVersion=__version__):
243 - notes = get_notes(versions, fromVersion)
245 - to_screen('PLEASE NOTE:')