diff options
Diffstat (limited to 'yt_dlp')
-rw-r--r-- | yt_dlp/YoutubeDL.py | 10 | ||||
-rw-r--r-- | yt_dlp/update.py | 34 |
2 files changed, 24 insertions, 20 deletions
diff --git a/yt_dlp/YoutubeDL.py b/yt_dlp/YoutubeDL.py index 8df8f1675..2258e22af 100644 --- a/yt_dlp/YoutubeDL.py +++ b/yt_dlp/YoutubeDL.py @@ -27,7 +27,6 @@ import traceback import random from string import ascii_letters -from zipimport import zipimporter from .compat import ( compat_basestring, @@ -143,6 +142,7 @@ from .postprocessor import ( FFmpegPostProcessor, MoveFilesAfterDownloadPP, ) +from .update import detect_variant from .version import __version__ if compat_os_name == 'nt': @@ -3266,12 +3266,8 @@ class YoutubeDL(object): self.get_encoding())) write_string(encoding_str, encoding=None) - source = ( - '(exe)' if hasattr(sys, 'frozen') - else '(zip)' if isinstance(globals().get('__loader__'), zipimporter) - else '(source)' if os.path.basename(sys.argv[0]) == '__main__.py' - else '') - self._write_string('[debug] yt-dlp version %s %s\n' % (__version__, source)) + source = detect_variant() + self._write_string('[debug] yt-dlp version %s%s\n' % (__version__, '' if source == 'unknown' else f' ({source})')) if _LAZY_LOADER: self._write_string('[debug] Lazy loading extractors enabled\n') if _PLUGIN_CLASSES: diff --git a/yt_dlp/update.py b/yt_dlp/update.py index d3681b832..531eea7c9 100644 --- a/yt_dlp/update.py +++ b/yt_dlp/update.py @@ -31,6 +31,18 @@ def rsa_verify(message, signature, key): ''' +def detect_variant(): + if hasattr(sys, 'frozen') and getattr(sys, '_MEIPASS', None): + if sys._MEIPASS == os.path.dirname(sys.executable): + return 'dir' + return 'exe' + elif isinstance(globals().get('__loader__'), zipimporter): + return 'zip' + elif os.path.basename(sys.argv[0]) == '__main__.py': + return 'source' + return 'unknown' + + def update_self(to_screen, verbose, opener): ''' Exists for backward compatibility. Use run_update(ydl) instead ''' @@ -87,13 +99,14 @@ def run_update(ydl): h.update(mv[:n]) return h.hexdigest() - err = None - if isinstance(globals().get('__loader__'), zipimporter): - pass - elif hasattr(sys, 'frozen'): - pass - else: - err = 'It looks like you installed yt-dlp with a package manager, pip, setup.py or a tarball. Please use that to update' + ERRORS = { + 'exe': None, + 'zip': None, + 'dir': 'Auto-update is not supported for unpackaged windows executable. Re-download the latest release', + 'source': 'You cannot update when running from source code', + 'unknown': 'It looks like you installed yt-dlp with a package manager, pip, setup.py or a tarball. Use that to update', + } + err = ERRORS.get(detect_variant(), ERRORS['unknown']) if err: return report_error(err, expected=True) @@ -138,12 +151,7 @@ def run_update(ydl): if not urlh: return None hash_data = ydl._opener.open(urlh).read().decode('utf-8') - 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) + 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) |