- urla = compat_urllib_request.urlopen(API_URL)
- download = filter(lambda x: x["name"] == "youtube-dl.exe", json.loads(urla.read()))
- if not download:
- downloader.to_screen(u'ERROR: can\'t find the current version. Please try again later.')
- return
- newversion = download[0]["description"].strip()
- if newversion == __version__:
- downloader.to_screen(u'youtube-dl is up-to-date (' + __version__ + ')')
- return
- urla.close()
+ # Check if there is a new version
+ try:
+ newversion = compat_urllib_request.urlopen(VERSION_URL).read().decode('utf-8').strip()
+ except:
+ if verbose: to_screen(traceback.format_exc().decode())
+ to_screen(u'ERROR: can\'t find the current version. Please try again later.')
+ return
+ if newversion == __version__:
+ to_screen(u'youtube-dl is up-to-date (' + __version__ + ')')
+ return
+
+ # Download and check versions info
+ try:
+ versions_info = compat_urllib_request.urlopen(JSON_URL).read().decode('utf-8')
+ versions_info = json.loads(versions_info)
+ except:
+ if verbose: to_screen(traceback.format_exc().decode())
+ to_screen(u'ERROR: can\'t obtain versions info. Please try again later.')
+ return
+ if not 'signature' in versions_info:
+ to_screen(u'ERROR: the versions file is not signed or corrupted. Aborting.')
+ return
+ signature = versions_info['signature']
+ del versions_info['signature']
+ if not rsa_verify(json.dumps(versions_info, sort_keys=True), signature, UPDATES_RSA_KEY):
+ to_screen(u'ERROR: the versions file signature is invalid. Aborting.')
+ return