From 507ffa764a63ef3e7f2fa2438d7ffb9ef5045790 Mon Sep 17 00:00:00 2001 From: Hetari Date: Tue, 21 Jan 2025 23:57:46 +0300 Subject: [PATCH] fix: auto updating library --- pyutube/utils.py | 46 ++++++++++++++++++++++++++++++++++++++++++---- setup.py | 3 --- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/pyutube/utils.py b/pyutube/utils.py index c46bd69..ccc048d 100644 --- a/pyutube/utils.py +++ b/pyutube/utils.py @@ -16,7 +16,7 @@ from pytubefix import __version__ as pytubefix_version -__version__ = "1.4.13" +__version__ = "1.4.14.alpha" __app__ = "pyutube" ABORTED_PREFIX = "Aborted" CANCEL_PREFIX = "Cancel" @@ -229,7 +229,7 @@ def check_for_updates() -> None: None """ libraries = { - 'PyUTube': { + 'pyutube': { 'version': __version__, 'repository': 'https://github.com/Hetari/pyutube' }, @@ -246,13 +246,51 @@ def check_for_updates() -> None: if r.status_code == 200: latest_version = r.json()['info']['version'] - if latest_version != version['version']: + # Special handling for pytubefix + if library == 'pytubefix': + current_version = version['version'] + target_version = '8.11.0' + + # Convert versions to tuples for comparison + current_parts = tuple(map(int, current_version.split('.'))) + target_parts = tuple(map(int, target_version.split('.'))) + + # Compare major version (8) + if current_parts[0] < target_parts[0]: + needs_update = True + # If major versions equal, compare minor version (11) + elif current_parts[0] == target_parts[0]: + if current_parts[1] != target_parts[1]: # Changed from < to != + needs_update = True + else: + needs_update = False + else: + needs_update = False + + if needs_update: + try: + subprocess.check_call( + [sys.executable, '-m', 'pip', 'install', 'pytubefix==8.11'], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE + ) + + except subprocess.CalledProcessError as e: + error_console.print( + f"❗ Failed to update [blue]pytubefix[/blue]: {e.stderr.decode()}" + ) + console.print( + "❗ If you want to use version 8.11 of [blue]pytubefix[/blue], " + + "Update it by running [bold red link=https://github.com/Hetari/pytubefix] " + + "pip install pytubefix==8.11[/bold red link]" + ) + # Normal handling for other libraries + elif latest_version != version['version']: console.print( f"👉 A new version of [blue]{library}[/blue] is available: {latest_version} " + f"Updating it now... ", style="warning" ) - # auto-update the package try: subprocess.check_call( [sys.executable, '-m', 'pip', 'install', '--upgrade', library], diff --git a/setup.py b/setup.py index d16787c..33969dd 100644 --- a/setup.py +++ b/setup.py @@ -45,7 +45,6 @@ "Programming Language :: Python :: 3", ], - include_package_data=True, python_requires=">=3.6", @@ -63,14 +62,12 @@ "setuptools", ], - entry_points={ "console_scripts": [ "pyutube=pyutube:cli.app", ], }, - project_urls={ "Author": "https://github.com/Hetari", "Homepage": "https://github.com/Hetari/pyutube",