From 8b90a4ebc769bd3a5cd26c48ef390939d5705d1e Mon Sep 17 00:00:00 2001 From: Jarian Cottingham Date: Fri, 20 Feb 2026 09:10:37 -0600 Subject: [PATCH] Fix version comparison logic to properly handle version strings like 2026.2.4 vs 2026.02.04 --- youtube_cli/main.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/youtube_cli/main.py b/youtube_cli/main.py index b3fb00b..8a35a4f 100644 --- a/youtube_cli/main.py +++ b/youtube_cli/main.py @@ -82,8 +82,8 @@ class YouTubeCLI: # Simple version comparison (basic implementation) # In a real implementation, you'd want a more robust version comparison - # Check if versions are different - if current_version != latest_version: + # Check if versions are different using proper version comparison + if self._compare_versions(current_version, latest_version) < 0: 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: @@ -100,6 +100,29 @@ class YouTubeCLI: console.print(f"[green]yt-dlp is up to date: {current_version}[/green]") return True + def _compare_versions(self, version1, version2): + """Compare two version strings. + Returns -1 if version1 < version2, 0 if equal, 1 if version1 > version2 + """ + # Split versions into components + v1_parts = [int(x) for x in version1.split('.')] + v2_parts = [int(x) for x in version2.split('.')] + + # Compare each part + for i in range(min(len(v1_parts), len(v2_parts))): + if v1_parts[i] < v2_parts[i]: + return -1 + elif v1_parts[i] > v2_parts[i]: + return 1 + + # If all compared parts are equal, the longer version is newer + if len(v1_parts) < len(v2_parts): + return -1 + elif len(v1_parts) > len(v2_parts): + return 1 + else: + return 0 + def load_config(self, config_path=None): """Load configuration from file or use defaults.""" default_config = {