1
1
mirror of https://github.com/neosubhamoy/pytubepp.git synced 2025-12-19 23:59:36 +05:30

(feat): added update checker and coloured alert messages

This commit is contained in:
2025-03-07 13:34:41 +05:30
parent fb021fb716
commit 1e260fba6f
4 changed files with 45 additions and 8 deletions

View File

@@ -43,6 +43,7 @@ dependencies = [
"tabulate", "tabulate",
"tqdm", "tqdm",
"appdirs", "appdirs",
"rich",
"setuptools", "setuptools",
] ]

View File

@@ -1,9 +1,10 @@
from pytubefix import YouTube from pytubefix import YouTube
from tabulate import tabulate from tabulate import tabulate
from rich import print as rprint
from .config import get_temporary_directory, load_config, update_config, reset_config from .config import get_temporary_directory, load_config, update_config, reset_config
from .download import download_progressive, download_nonprogressive, download_audio, progress from .download import download_progressive, download_nonprogressive, download_audio, progress
from .postprocess import merge_audio_video, convert_to_mp3 from .postprocess import merge_audio_video, convert_to_mp3
from .utils import get_version, clear_temp_files, is_valid_url, network_available, ffmpeg_installed, nodejs_installed, unpack_caption from .utils import get_version, clear_temp_files, is_valid_url, network_available, ffmpeg_installed, nodejs_installed, unpack_caption, check_update
from .postinstaller import postinstall from .postinstaller import postinstall
import appdirs, os, re, sys, argparse, json import appdirs, os, re, sys, argparse, json
@@ -45,9 +46,14 @@ class YouTubeDownloader:
sys.exit() sys.exit()
if not nodejs_installed(): if not nodejs_installed():
print("\nWarning: Node.js is not installed or not found in PATH!") rprint("\n[dark_orange]WARNING:[/dark_orange] Node.js is not installed or not found in PATH!")
print("BotGuard poToken generation will not work properly without Node.js environment") print("BotGuard poToken generation will not work properly without Node.js environment")
print("Please install Node.js, by running: pytubepp --postinstall or read https://github.com/neosubhamoy/pytubepp#%EF%B8%8F-installation for manual instructions\n") rprint("Please install Node.js, by running: [green]pytubepp --postinstall[/green] or read [steel_blue3]https://github.com/neosubhamoy/pytubepp#%EF%B8%8F-installation[/steel_blue3] for manual instructions\n")
update = check_update()
if update[0]:
rprint(f'\n[blue]NOTE:[/blue] A newer version of pytubepp is available! ([dark_orange]v{update[1]}[/dark_orange] -> [light_green]v{update[2]}[/light_green])')
rprint(f'Please upgrade to the latest version using: [green]{update[3]}[/green]')
if is_valid_url(link): if is_valid_url(link):
link = is_valid_url(link).group(1) link = is_valid_url(link).group(1)
@@ -304,9 +310,9 @@ class YouTubeDownloader:
def download_stream(self, link, chosen_stream, chosen_caption=None): def download_stream(self, link, chosen_stream, chosen_caption=None):
if not ffmpeg_installed(): if not ffmpeg_installed():
print("\nWarning: FFmpeg is not installed or not found in PATH!") rprint("\n[dark_orange]WARNING:[/dark_orange] FFmpeg is not installed or not found in PATH!")
print("Some core functionalities like video processing will not work properly without FFmpeg") print("Some core functionalities like video processing will not work properly without FFmpeg")
print("Please install FFmpeg, by running: pytubepp --postinstall or read https://github.com/neosubhamoy/pytubepp#%EF%B8%8F-installation for manual instructions\n") rprint("Please install FFmpeg, by running: [green]pytubepp --postinstall[/green] or read [steel_blue3]https://github.com/neosubhamoy/pytubepp#%EF%B8%8F-installation[/steel_blue3] for manual instructions\n")
sys.exit() sys.exit()
if self.set_video_info(link): if self.set_video_info(link):

View File

@@ -1,6 +1,6 @@
from importlib.metadata import version from importlib.metadata import version
from .config import load_config, get_temporary_directory from .config import load_config, get_temporary_directory
import os, re, subprocess, platform import os, re, subprocess, platform, requests
userConfig = load_config() userConfig = load_config()
downloadDIR = userConfig['downloadDIR'] downloadDIR = userConfig['downloadDIR']
@@ -78,4 +78,33 @@ def clear_temp_files():
except Exception as e: except Exception as e:
print(e) print(e)
else: else:
print('No temporary files found to clear...!') print('No temporary files found to clear...!')
def compare_versions(v1: str, v2: str):
parts1 = list(map(int, v1.split('.')))
parts2 = list(map(int, v2.split('.')))
for i in range(max(len(parts1), len(parts2))):
part1 = parts1[i] if i < len(parts1) else 0
part2 = parts2[i] if i < len(parts2) else 0
if part1 > part2:
return 1
if part1 < part2:
return -1
return 0
def get_platform_specific_upgrade_command():
if platform.system().lower() == 'windows':
return 'pip install pytubefix pytubepp --upgrade; pytubepp --postinstall'
else:
return 'pip3 install pytubefix pytubepp --upgrade && pytubepp --postinstall'
def check_update():
try:
response = requests.get('https://pypi.org/pypi/pytubepp/json')
if response.status_code != 200:
return False, None, None, None
latest_version = response.json()['info']['version']
current_version = get_version()
return compare_versions(current_version, latest_version) == -1, current_version, latest_version, get_platform_specific_upgrade_command()
except Exception as e:
return False, None, None, None

View File

@@ -8,4 +8,5 @@ appdirs
setuptools setuptools
wheel wheel
twine twine
build build
rich