mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-30 22:25:19 +00:00 
			
		
		
		
	[cleanup] Upgrade syntax
Using https://github.com/asottile/pyupgrade 1. `__future__` imports and `coding: utf-8` were removed 2. Files were rewritten with `pyupgrade --py36-plus --keep-percent-format` 3. f-strings were cherry-picked from `pyupgrade --py36-plus` Extractors are left untouched (except removing header) to avoid unnecessary merge conflicts
This commit is contained in:
		| @@ -1,5 +1,3 @@ | ||||
| from __future__ import unicode_literals | ||||
| 
 | ||||
| import hashlib | ||||
| import json | ||||
| import os | ||||
| @@ -111,11 +109,11 @@ def run_update(ydl): | ||||
|     } | ||||
| 
 | ||||
|     def get_bin_info(bin_or_exe, version): | ||||
|         label = version_labels['%s_%s' % (bin_or_exe, version)] | ||||
|         label = version_labels[f'{bin_or_exe}_{version}'] | ||||
|         return next((i for i in version_info['assets'] if i['name'] == 'yt-dlp%s' % label), {}) | ||||
| 
 | ||||
|     def get_sha256sum(bin_or_exe, version): | ||||
|         filename = 'yt-dlp%s' % version_labels['%s_%s' % (bin_or_exe, version)] | ||||
|         filename = 'yt-dlp%s' % version_labels[f'{bin_or_exe}_{version}'] | ||||
|         urlh = next( | ||||
|             (i for i in version_info['assets'] if i['name'] in ('SHA2-256SUMS')), | ||||
|             {}).get('browser_download_url') | ||||
| @@ -136,7 +134,7 @@ def run_update(ydl): | ||||
|         try: | ||||
|             if os.path.exists(filename + '.old'): | ||||
|                 os.remove(filename + '.old') | ||||
|         except (IOError, OSError): | ||||
|         except OSError: | ||||
|             return report_unable('remove the old version') | ||||
| 
 | ||||
|         try: | ||||
| @@ -147,13 +145,13 @@ def run_update(ydl): | ||||
|             urlh = ydl._opener.open(url) | ||||
|             newcontent = urlh.read() | ||||
|             urlh.close() | ||||
|         except (IOError, OSError): | ||||
|         except OSError: | ||||
|             return report_network_error('download latest version') | ||||
| 
 | ||||
|         try: | ||||
|             with open(filename + '.new', 'wb') as outf: | ||||
|                 outf.write(newcontent) | ||||
|         except (IOError, OSError): | ||||
|         except OSError: | ||||
|             return report_permission_error(f'{filename}.new') | ||||
| 
 | ||||
|         expected_sum = get_sha256sum(variant, arch) | ||||
| @@ -168,11 +166,11 @@ def run_update(ydl): | ||||
| 
 | ||||
|         try: | ||||
|             os.rename(filename, filename + '.old') | ||||
|         except (IOError, OSError): | ||||
|         except OSError: | ||||
|             return report_unable('move current version') | ||||
|         try: | ||||
|             os.rename(filename + '.new', filename) | ||||
|         except (IOError, OSError): | ||||
|         except OSError: | ||||
|             report_unable('overwrite current version') | ||||
|             os.rename(filename + '.old', filename) | ||||
|             return | ||||
| @@ -195,7 +193,7 @@ def run_update(ydl): | ||||
|             urlh = ydl._opener.open(url) | ||||
|             newcontent = urlh.read() | ||||
|             urlh.close() | ||||
|         except (IOError, OSError): | ||||
|         except OSError: | ||||
|             return report_network_error('download the latest version') | ||||
| 
 | ||||
|         expected_sum = get_sha256sum(variant, pack_type) | ||||
| @@ -207,7 +205,7 @@ def run_update(ydl): | ||||
|         try: | ||||
|             with open(filename, 'wb') as outf: | ||||
|                 outf.write(newcontent) | ||||
|         except (IOError, OSError): | ||||
|         except OSError: | ||||
|             return report_unable('overwrite current version') | ||||
| 
 | ||||
|         ydl.to_screen('Updated yt-dlp to version %s; Restart yt-dlp to use the new version' % version_id) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 pukkandan
					pukkandan