Skip to content

Commit

Permalink
fix: auto updating library
Browse files Browse the repository at this point in the history
  • Loading branch information
Hetari committed Jan 21, 2025
1 parent 413d169 commit 507ffa7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
46 changes: 42 additions & 4 deletions pyutube/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -229,7 +229,7 @@ def check_for_updates() -> None:
None
"""
libraries = {
'PyUTube': {
'pyutube': {
'version': __version__,
'repository': 'https://github.com/Hetari/pyutube'
},
Expand All @@ -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],
Expand Down
3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"Programming Language :: Python :: 3",
],


include_package_data=True,

python_requires=">=3.6",
Expand All @@ -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",
Expand Down

0 comments on commit 507ffa7

Please sign in to comment.