adding auto update code for yt-dlp
This commit is contained in:
parent
26a36667b8
commit
1d0364cbfc
@ -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:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user