Skip to content

Commit

Permalink
[update] Check for new version even if not updateable
Browse files Browse the repository at this point in the history
  • Loading branch information
pukkandan committed Sep 27, 2021
1 parent 91dd88b commit 2823428
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions yt_dlp/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,21 @@ def calc_sha256sum(path):
h.update(mv[:n])
return h.hexdigest()

# Download and check versions info
try:
version_info = ydl._opener.open(JSON_URL).read().decode('utf-8')
version_info = json.loads(version_info)
except Exception:
return report_error('can\'t obtain versions info. Please try again later ', True, delim='or')

def version_tuple(version_str):
return tuple(map(int, version_str.split('.')))

version_id = version_info['tag_name']
if version_tuple(__version__) >= version_tuple(version_id):
ydl.to_screen(f'yt-dlp is up to date ({__version__})')
return

ERRORS = {
'exe': None,
'zip': None,
Expand All @@ -108,30 +123,15 @@ def calc_sha256sum(path):
}
err = ERRORS.get(detect_variant(), ERRORS['unknown'])
if err:
ydl.to_screen(f'Latest version: {version_id}, Current version: {__version__}')
return report_error(err, expected=True)

# sys.executable is set to the full pathname of the exe-file for py2exe
# though symlinks are not followed so that we need to do this manually
# with help of realpath
filename = compat_realpath(sys.executable if hasattr(sys, 'frozen') else sys.argv[0])
ydl.to_screen('Current Build Hash %s' % calc_sha256sum(filename))

# Download and check versions info
try:
version_info = ydl._opener.open(JSON_URL).read().decode('utf-8')
version_info = json.loads(version_info)
except Exception:
return report_error('can\'t obtain versions info. Please try again later ', True, delim='or')

def version_tuple(version_str):
return tuple(map(int, version_str.split('.')))

version_id = version_info['tag_name']
if version_tuple(__version__) >= version_tuple(version_id):
ydl.to_screen('yt-dlp is up to date (%s)' % __version__)
return

ydl.to_screen('Updating to version ' + version_id + ' ...')
ydl.to_screen(f'Current version {__version__}; Build Hash {calc_sha256sum(filename)}')
ydl.to_screen(f'Updating to version {version_id} ...')

version_labels = {
'zip_3': '',
Expand Down

0 comments on commit 2823428

Please sign in to comment.