Fix version comparison logic to properly handle version strings like 2026.2.4 vs 2026.02.04
This commit is contained in:
parent
f58f0445ca
commit
8b90a4ebc7
@ -82,8 +82,8 @@ class YouTubeCLI:
|
|||||||
|
|
||||||
# Simple version comparison (basic implementation)
|
# Simple version comparison (basic implementation)
|
||||||
# In a real implementation, you'd want a more robust version comparison
|
# In a real implementation, you'd want a more robust version comparison
|
||||||
# Check if versions are different
|
# Check if versions are different using proper version comparison
|
||||||
if current_version != latest_version:
|
if self._compare_versions(current_version, latest_version) < 0:
|
||||||
console.print(f"[yellow]Newer version available: {latest_version} (current: {current_version})[/yellow]")
|
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="")
|
console.print("[blue]Would you like to update? (y/n): [/blue]", end="")
|
||||||
try:
|
try:
|
||||||
@ -100,6 +100,29 @@ class YouTubeCLI:
|
|||||||
console.print(f"[green]yt-dlp is up to date: {current_version}[/green]")
|
console.print(f"[green]yt-dlp is up to date: {current_version}[/green]")
|
||||||
return True
|
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):
|
def load_config(self, config_path=None):
|
||||||
"""Load configuration from file or use defaults."""
|
"""Load configuration from file or use defaults."""
|
||||||
default_config = {
|
default_config = {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user