feat: Enhance CLI to clean URLs and display summary on console

This commit is contained in:
2025-01-03 14:09:33 +01:00
parent 3bcc5164e1
commit e5f35154a8

View File

@@ -33,13 +33,14 @@ def estimate_api_cost(text: str) -> float:
def sanitize_filename(url: str) -> str:
"""Convert URL to safe filename, keeping video ID."""
# Extract video ID if it's a YouTube URL
# Clean URL and extract video ID
clean_url = url.split("&")[0] # Remove everything after first &
video_id = None
if "youtube.com" in url or "youtu.be" in url:
if "v=" in url:
video_id = url.split("v=")[1].split("&")[0]
if "youtube.com" in clean_url or "youtu.be" in clean_url:
if "v=" in clean_url:
video_id = clean_url.split("v=")[1]
else:
video_id = url.split("/")[-1].split("?")[0]
video_id = clean_url.split("/")[-1].split("?")[0]
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
return f"{timestamp}_{video_id if video_id else 'video'}"
@@ -277,6 +278,11 @@ def main():
with open(summary_path, "w", encoding="utf-8") as f:
f.write(output)
print(f"\nSummary saved to: {summary_path}")
# Print the summary to console
print("\n=== Summary ===\n")
print(summary)
print() # Extra newline for readability
# If output path specified, also save there
if args.output: