From 1d0364cbfc4e60d2911545fc6cbe45c4bc9700e3 Mon Sep 17 00:00:00 2001 From: Jarian Cottingham Date: Sat, 31 Jan 2026 05:00:17 -0600 Subject: [PATCH] adding auto update code for yt-dlp --- .DS_Store | Bin 0 -> 6148 bytes youtube_cli/main.py | 90 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f7607f4002eaefce56fdcb26e297490bca236fdd GIT binary patch literal 6148 zcmeHKJxc>Y5S>j<2?iuZ1Pj3{Z4^_cku#ivoe;1!V zfQ7aA3oQHt*1p+Y%pOVnDnxV#X5X?ivorH9cbg?5QRr54L>VGVK^dJH3}b}ttRs@p zD_Nl6J(~4gu@ba8Bc67_GGH0_jSTR+>(C0-sX<}v{heFbF>S5D_sh+ojJ4F&P51ov z>J;P#Q{Q*w?{QjCk)f z^(mk(h0ro8*rf_JsbN+@LcC1&G;6xgpZO2RvZe|9niYQRZPrV|<9f5>>%~*6;kngm z8PBdwdlbYvpxNYCV$Gf&r?;;+L)p`(bDLd$CqC9UmAG#~N3o8?(y3ZCYhB9^E)Lai z0{&(daZ7A}vC8}Zcfpy>l1eMIqh-J{U>SI0fWHqel+n`|DU_cM4Dt#9bg(Q1^9)ab zu0~H|q!1Q}P@zB-D)bdYsBo;i+RxJ%DOBMk^yNe7%tGH#gv^fpUFoh*P&K!sWxz5p zWPtx4LNa{*Z%n@bOD8*61}p=AlL6uQMZbXF^w~PnC7-n}v;<{gzeu4B!Jv<0IpL#t c9x4SkmnT3^W26u(5c@|!(qIS6z>hNU3RoGrzW@LL literal 0 HcmV?d00001 diff --git a/youtube_cli/main.py b/youtube_cli/main.py index 4281b84..2876cff 100644 --- a/youtube_cli/main.py +++ b/youtube_cli/main.py @@ -29,6 +29,76 @@ class YouTubeCLI: ) self.downloaded_videos = self.load_archive() + def get_yt_dlp_version(self): + """Get the current version of yt-dlp installed.""" + try: + import yt_dlp + return yt_dlp.version.__version__ + except ImportError: + return None + + def get_latest_yt_dlp_version(self): + """Get the latest version of yt-dlp available from PyPI.""" + try: + import requests + response = requests.get("https://pypi.org/pypi/yt-dlp/json", timeout=10) + if response.status_code == 200: + data = response.json() + return data["info"]["version"] + return None + except Exception: + return None + + def update_yt_dlp(self): + """Update yt-dlp to the latest version.""" + try: + console.print("[blue]Updating yt-dlp to the latest version...[/blue]") + result = subprocess.run( + [sys.executable, "-m", "pip", "install", "--upgrade", "yt-dlp"], + capture_output=True, + text=True, + check=True + ) + console.print("[green]yt-dlp updated successfully![/green]") + return True + except subprocess.CalledProcessError as e: + console.print(f"[red]Failed to update yt-dlp: {e.stderr}[/red]") + return False + except Exception as e: + console.print(f"[red]Error updating yt-dlp: {e}[/red]") + return False + + def check_for_updates(self): + """Check if yt-dlp needs to be updated and update if needed.""" + current_version = self.get_yt_dlp_version() + if not current_version: + console.print("[yellow]Could not determine current yt-dlp version[/yellow]") + return False + + latest_version = self.get_latest_yt_dlp_version() + if not latest_version: + console.print("[yellow]Could not determine latest yt-dlp version[/yellow]") + return False + + # Simple version comparison (basic implementation) + # In a real implementation, you'd want a more robust version comparison + if current_version != latest_version: + console.print(f"[yellow]Newer version available: {latest_version} (current: {current_version})[/yellow]") + console.print("[blue]Would you like to update? (y/n): [/blue]", end="") + try: + choice = input().strip().lower() + if choice in ['y', 'yes']: + return self.update_yt_dlp() + else: + console.print("[yellow]Update skipped[/yellow]") + return False + except Exception: + console.print("[yellow]Update skipped[/yellow]") + return False + else: + console.print(f"[green]yt-dlp is up to date: {current_version}[/green]") + return True + def load_config(self, config_path=None): """Load configuration from file or use defaults.""" default_config = { @@ -790,15 +860,35 @@ def main(): ) parser.add_argument("--config", help="Configuration file path") parser.add_argument("--page", type=int, default=1, help="Page number for results") + parser.add_argument("--update", action="store_true", help="Update yt-dlp to latest version") + parser.add_argument("--check-update", action="store_true", help="Check for yt-dlp updates") args = parser.parse_args() # Create CLI instance cli = YouTubeCLI(args.config) + # Check for updates if requested + if args.check_update: + cli.check_for_updates() + return + + # Update if requested + if args.update: + cli.update_yt_dlp() + return + # Pre-fill archive with existing downloads cli.prefill_archive_from_downloads() + # Check for updates before proceeding with main operations + # This is a lightweight check that doesn't interrupt user flow + try: + cli.check_for_updates() + except Exception: + # Don't let update checking break the application + pass + if args.download: # Handle download functionality if not args.query: