Add custom folder name support for category selection
This commit is contained in:
parent
44ac8014de
commit
2fb3dd48c5
@ -661,8 +661,11 @@ 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()
|
||||||
|
|
||||||
|
# Check if input is a number
|
||||||
|
if choice.isdigit():
|
||||||
choice_num = int(choice)
|
choice_num = int(choice)
|
||||||
if 1 <= choice_num <= len(categories):
|
if 1 <= choice_num <= len(categories):
|
||||||
selected_category = categories[choice_num - 1]
|
selected_category = categories[choice_num - 1]
|
||||||
@ -670,8 +673,23 @@ class YouTubeCLI:
|
|||||||
return selected_category
|
return selected_category
|
||||||
else:
|
else:
|
||||||
console.print("[red]Invalid selection. Please try again.[/red]")
|
console.print("[red]Invalid selection. Please try again.[/red]")
|
||||||
except ValueError:
|
else:
|
||||||
console.print("[red]Please enter a valid number.[/red]")
|
# Validate custom folder name
|
||||||
|
if not choice:
|
||||||
|
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user