Add custom folder name support for category selection

This commit is contained in:
Jarian Cottingham 2026-02-21 13:29:10 -06:00
parent 44ac8014de
commit 2fb3dd48c5

View File

@ -661,17 +661,35 @@ class YouTubeCLI:
while True: while True:
try: try:
console.print("\n[blue]Select a category (enter number):[/blue]") console.print("\n[blue]Select a category (enter number) or type a custom folder name:[/blue]")
choice = input().strip() choice = input().strip()
choice_num = int(choice)
if 1 <= choice_num <= len(categories): # Check if input is a number
selected_category = categories[choice_num - 1] if choice.isdigit():
console.print(f"[green]Selected category: {Path(selected_category).name}[/green]") choice_num = int(choice)
return selected_category if 1 <= choice_num <= len(categories):
selected_category = categories[choice_num - 1]
console.print(f"[green]Selected category: {Path(selected_category).name}[/green]")
return selected_category
else:
console.print("[red]Invalid selection. Please try again.[/red]")
else: else:
console.print("[red]Invalid selection. Please try again.[/red]") # Validate custom folder name
except ValueError: if not choice:
console.print("[red]Please enter a valid number.[/red]") console.print("[red]Folder name cannot be empty. Please try again.[/red]")
continue
# Check for invalid characters (only allow a-z, 0-9, and hyphens/underscores)
import re
if not re.match(r'^[a-zA-Z0-9_-]+$', choice):
console.print("[red]Invalid characters. Only a-z, 0-9, hyphens, and underscores are allowed.[/red]")
continue
# If valid, use the custom folder name
console.print(f"[green]Using custom folder: {choice}[/green]")
# Return the custom folder name (will be appended to base path)
return choice
except KeyboardInterrupt: except KeyboardInterrupt:
console.print("\n[yellow]Operation cancelled.[/yellow]") console.print("\n[yellow]Operation cancelled.[/yellow]")
return None return None