From 6b9fe938cc43573c446ba9c44d863d7505e10555 Mon Sep 17 00:00:00 2001 From: Subhamoy Biswas Date: Sun, 19 Jan 2025 19:16:00 +0530 Subject: [PATCH] (feat): added nodejs and ffmpeg installation checks --- pytubepp/main.py | 13 ++++++++++++- pytubepp/utils.py | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pytubepp/main.py b/pytubepp/main.py index 4f4082b..7cc93d9 100644 --- a/pytubepp/main.py +++ b/pytubepp/main.py @@ -3,7 +3,7 @@ from tabulate import tabulate 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 +from .utils import get_version, clear_temp_files, is_valid_url, network_available, ffmpeg_installed, nodejs_installed import appdirs, os, re, sys, argparse, json class YouTubeDownloader: @@ -42,6 +42,11 @@ class YouTubeDownloader: if not network_available(): print('\nRequest timeout! Please check your network and try again...!!') sys.exit() + + if not nodejs_installed(): + print("\nWarning: 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 from https://nodejs.org/en/download\n") if is_valid_url(link): link = is_valid_url(link).group(1) @@ -251,6 +256,12 @@ class YouTubeDownloader: print(f'\nTitle: {self.title}\nSelected Stream: {resolution_map.get(chosen_stream, "Unknown")}\n') 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!") + print("Some core functionalities like video processing will not work properly without FFmpeg") + print("Please install FFmpeg, read https://github.com/neosubhamoy/pytubepp#%EF%B8%8F-installation for instructions\n") + sys.exit() + if self.set_video_info(link): allowed_streams = self.get_allowed_streams(link) allowed_captions = self.get_allowed_captions(link) diff --git a/pytubepp/utils.py b/pytubepp/utils.py index c0f951c..a5d4105 100644 --- a/pytubepp/utils.py +++ b/pytubepp/utils.py @@ -14,6 +14,20 @@ def network_available(): return True except subprocess.CalledProcessError: return False + +def nodejs_installed(): + try: + subprocess.run(['node', '--version'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True) + return True + except (subprocess.CalledProcessError, FileNotFoundError): + return False + +def ffmpeg_installed(): + try: + subprocess.run(['ffmpeg', '-version'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True) + return True + except (subprocess.CalledProcessError, FileNotFoundError): + return False def get_version(): try: