diff --git a/pyproject.toml b/pyproject.toml index 551d7f0..919eb9e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,6 +43,7 @@ dependencies = [ "tabulate", "tqdm", "appdirs", + "rich", "setuptools", ] diff --git a/pytubepp/main.py b/pytubepp/main.py index 0e21c15..0a8f942 100644 --- a/pytubepp/main.py +++ b/pytubepp/main.py @@ -1,9 +1,10 @@ from pytubefix import YouTube from tabulate import tabulate +from rich import print as rprint from .config import get_temporary_directory, load_config, update_config, reset_config from .download import download_progressive, download_nonprogressive, download_audio, progress 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 import appdirs, os, re, sys, argparse, json @@ -45,9 +46,14 @@ class YouTubeDownloader: sys.exit() 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("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): link = is_valid_url(link).group(1) @@ -304,9 +310,9 @@ class YouTubeDownloader: def download_stream(self, link, chosen_stream, chosen_caption=None): 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("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() if self.set_video_info(link): diff --git a/pytubepp/utils.py b/pytubepp/utils.py index 614d125..f2a362b 100644 --- a/pytubepp/utils.py +++ b/pytubepp/utils.py @@ -1,6 +1,6 @@ from importlib.metadata import version from .config import load_config, get_temporary_directory -import os, re, subprocess, platform +import os, re, subprocess, platform, requests userConfig = load_config() downloadDIR = userConfig['downloadDIR'] @@ -78,4 +78,33 @@ def clear_temp_files(): except Exception as e: print(e) else: - print('No temporary files found to clear...!') \ No newline at end of file + 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 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index c0fa5fa..148a018 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ appdirs setuptools wheel twine -build \ No newline at end of file +build +rich \ No newline at end of file