]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/update.py
[youtube:tab] Support channel search
[yt-dlp.git] / yt_dlp / update.py
index 5ae4e52049046801264de563c5584bd8d441b138..67b112f6e1d25842c6d8ae60ad56a5e56d622598 100644 (file)
@@ -50,7 +50,7 @@ def calc_sha256sum(path):
         return h.hexdigest()
 
     if not isinstance(globals().get('__loader__'), zipimporter) and not hasattr(sys, 'frozen'):
-        to_screen('It looks like you installed yt-dlp with a package manager, pip, setup.py or a tarball. Please use that to update.')
+        to_screen('It looks like you installed yt-dlp with a package manager, pip, setup.py or a tarball. Please use that to update')
         return
 
     # sys.executable is set to the full pathname of the exe-file for py2exe
@@ -66,7 +66,7 @@ def calc_sha256sum(path):
     except Exception:
         if verbose:
             to_screen(encode_compat_str(traceback.format_exc()))
-        to_screen('ERROR: can\'t obtain versions info. Please try again later.')
+        to_screen('ERROR: can\'t obtain versions info. Please try again later')
         to_screen('Visit https://github.com/yt-dlp/yt-dlp/releases/latest')
         return
 
@@ -165,7 +165,7 @@ def get_sha256sum(bin_or_exe, version):
     echo.Waiting for file handle to be closed ...
     ping 127.0.0.1 -n 5 -w 1000 > NUL
     move /Y "%s.new" "%s" > NUL
-    echo.Updated yt-dlp to version %s.
+    echo.Updated yt-dlp to version %s
 )
 @start /b "" cmd /c del "%%~f0"&exit /b
                 ''' % (exe, exe, version_id))
@@ -197,32 +197,22 @@ def get_sha256sum(bin_or_exe, version):
             to_screen('Visit https://github.com/yt-dlp/yt-dlp/releases/latest')
             return
 
-        try:
-            with open(filename + '.new', 'wb') as outf:
-                outf.write(newcontent)
-        except (IOError, OSError):
-            if verbose:
-                to_screen(encode_compat_str(traceback.format_exc()))
-            to_screen('ERROR: unable to write the new version')
-            return
-
         expected_sum = get_sha256sum('zip', py_ver)
-        if expected_sum and calc_sha256sum(filename + '.new') != expected_sum:
+        if expected_sum and hashlib.sha256(newcontent).hexdigest() != expected_sum:
             to_screen('ERROR: unable to verify the new zip')
             to_screen('Visit https://github.com/yt-dlp/yt-dlp/releases/latest')
-            try:
-                os.remove(filename + '.new')
-            except OSError:
-                to_screen('ERROR: unable to remove corrupt zip')
             return
 
         try:
-            os.rename(filename + '.new', filename)
-        except OSError:
+            with open(filename, 'wb') as outf:
+                outf.write(newcontent)
+        except (IOError, OSError):
+            if verbose:
+                to_screen(encode_compat_str(traceback.format_exc()))
             to_screen('ERROR: unable to overwrite current version')
             return
 
-    to_screen('Updated yt-dlp. Restart yt-dlp to use the new version.')
+    to_screen('Updated yt-dlp. Restart yt-dlp to use the new version')
 
 
 '''  # UNUSED