diff options
author | Nil Admirari <50202386+nihil-admirari@users.noreply.github.com> | 2021-06-08 10:34:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-08 16:04:07 +0530 |
commit | beb982bead45db3c966c66715e10417682b605fd (patch) | |
tree | ad9dd6b876e31e574078c5503005b9fba783f995 /yt_dlp | |
parent | e88396f123820a80a776e354b397a0dc0cac781f (diff) | |
download | hypervideo-pre-beb982bead45db3c966c66715e10417682b605fd.tar.lz hypervideo-pre-beb982bead45db3c966c66715e10417682b605fd.tar.xz hypervideo-pre-beb982bead45db3c966c66715e10417682b605fd.zip |
[build,update] Add GNU-style SHA512 and prepare updater for simlar SHA256 (#383)
Authored by: nihil-admirari <50202386+nihil-admirari@users.noreply.github.com>
Related: #385
Diffstat (limited to 'yt_dlp')
-rw-r--r-- | yt_dlp/update.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/yt_dlp/update.py b/yt_dlp/update.py index 14ae96633..c49c78d4b 100644 --- a/yt_dlp/update.py +++ b/yt_dlp/update.py @@ -135,15 +135,19 @@ def run_update(ydl): return next((i for i in version_info['assets'] if i['name'] == 'yt-dlp%s' % label), {}) def get_sha256sum(bin_or_exe, version): - label = version_labels['%s_%s' % (bin_or_exe, version)] + filename = 'yt-dlp%s' % version_labels['%s_%s' % (bin_or_exe, version)] urlh = next( (i for i in version_info['assets'] if i['name'] in ('SHA2-256SUMS')), {}).get('browser_download_url') if not urlh: return None hash_data = ydl._opener.open(urlh).read().decode('utf-8') - hashes = list(map(lambda x: x.split(':'), hash_data.splitlines())) - return next((i[1] for i in hashes if i[0] == 'yt-dlp%s' % label), None) + if hash_data.startswith('version:'): + # Old colon-separated hash file + return dict(ln.split(':') for ln in hash_data.splitlines()).get(filename) + else: + # GNU-style hash file + return dict(ln.split()[::-1] for ln in hash_data.splitlines()).get(filename) if not os.access(filename, os.W_OK): return report_error('no write permissions on %s' % filename, expected=True) @@ -220,7 +224,9 @@ def run_update(ydl): return report_error('unable to download latest version', True) expected_sum = get_sha256sum('zip', '3') - if expected_sum and hashlib.sha256(newcontent).hexdigest() != expected_sum: + if not expected_sum: + ydl.report_warning('no hash information found for the release') + elif hashlib.sha256(newcontent).hexdigest() != expected_sum: return report_error('unable to verify the new zip', True) try: |