|
| 1 | +"""CLI for Zoom transcript downloads.""" |
| 2 | + |
| 3 | +from pathlib import Path |
| 4 | +from dotenv import load_dotenv |
| 5 | +from fastcore.parallel import parallel |
| 6 | +import httpx |
| 7 | +import typer |
| 8 | +from hamel.zoom import get_zoom_token, list_recordings, download_transcript, make_filename |
| 9 | + |
| 10 | +load_dotenv() |
| 11 | + |
| 12 | +app = typer.Typer() |
| 13 | + |
| 14 | +@app.command() |
| 15 | +def zoom( |
| 16 | + meeting_id: str = typer.Argument(None, help="Meeting ID to download"), |
| 17 | + search: str = typer.Option(None, "--search", "-s", help="Filter by text in topic"), |
| 18 | + days: int = typer.Option(45, "--days", "-d", help="Number of days to look back"), |
| 19 | + output: Path = typer.Option(None, "--output", "-o", help="Output file or directory"), |
| 20 | +): |
| 21 | + """Download Zoom meeting transcripts. |
| 22 | + |
| 23 | + Examples: |
| 24 | + zoom 123456789 # Print to stdout (pipe to other tools) |
| 25 | + zoom 123456789 -o file.vtt # Download to file |
| 26 | + zoom -s "Jason" # Search, select one or 'a' for all |
| 27 | + zoom -s "" # List all meetings |
| 28 | + """ |
| 29 | + try: |
| 30 | + token = get_zoom_token() |
| 31 | + |
| 32 | + # Direct meeting ID download |
| 33 | + if meeting_id: |
| 34 | + transcript = download_transcript(meeting_id, token) |
| 35 | + if not transcript: |
| 36 | + print("No transcript available.") |
| 37 | + raise typer.Exit(1) |
| 38 | + |
| 39 | + if output: |
| 40 | + output.parent.mkdir(parents=True, exist_ok=True) |
| 41 | + output.write_text(transcript, encoding="utf-8") |
| 42 | + print(f"Saved to {output}") |
| 43 | + else: |
| 44 | + print(transcript) |
| 45 | + return |
| 46 | + |
| 47 | + # Search and download |
| 48 | + meetings = list_recordings(days) |
| 49 | + |
| 50 | + # Filter by topic |
| 51 | + if search is not None: |
| 52 | + query = search.lower() |
| 53 | + meetings = [m for m in meetings if query in m.get('topic', '').lower()] |
| 54 | + |
| 55 | + if not meetings: |
| 56 | + print("No meetings found.") |
| 57 | + return |
| 58 | + |
| 59 | + # Show list |
| 60 | + print(f"\nFound {len(meetings)} meeting(s):\n") |
| 61 | + for idx, meeting in enumerate(meetings, 1): |
| 62 | + date = meeting['start_time'].split('T')[0] |
| 63 | + print(f"{idx:2}. {date} | {meeting['id']} | {meeting.get('topic', '')}") |
| 64 | + |
| 65 | + # Prompt for selection |
| 66 | + choice = typer.prompt("\nEnter number (or 'a' for all)") |
| 67 | + |
| 68 | + # Prompt for output directory |
| 69 | + outdir = Path(typer.prompt("Save to directory", default=".")) |
| 70 | + if outdir != Path("."): |
| 71 | + outdir.mkdir(parents=True, exist_ok=True) |
| 72 | + |
| 73 | + # Download all |
| 74 | + if choice.lower() == "a": |
| 75 | + print(f"\nDownloading {len(meetings)} transcript(s)...") |
| 76 | + |
| 77 | + def download_one(meeting): |
| 78 | + transcript = download_transcript(str(meeting['id']), token) |
| 79 | + if transcript: |
| 80 | + filepath = outdir / make_filename(meeting) |
| 81 | + filepath.write_text(transcript, encoding="utf-8") |
| 82 | + print(f"✓ {filepath.name}") |
| 83 | + else: |
| 84 | + print(f"✗ No transcript: {meeting.get('topic', '')[:50]}") |
| 85 | + |
| 86 | + parallel(download_one, meetings, threadpool=True, n_workers=8) |
| 87 | + return |
| 88 | + |
| 89 | + # Download one |
| 90 | + try: |
| 91 | + idx = int(choice) |
| 92 | + except ValueError: |
| 93 | + print("Invalid input.") |
| 94 | + raise typer.Exit(1) |
| 95 | + |
| 96 | + if idx < 1 or idx > len(meetings): |
| 97 | + print("Invalid selection.") |
| 98 | + raise typer.Exit(1) |
| 99 | + |
| 100 | + meeting = meetings[idx - 1] |
| 101 | + transcript = download_transcript(str(meeting['id']), token) |
| 102 | + if not transcript: |
| 103 | + print("No transcript available.") |
| 104 | + raise typer.Exit(1) |
| 105 | + |
| 106 | + filepath = outdir / make_filename(meeting) |
| 107 | + filepath.write_text(transcript, encoding="utf-8") |
| 108 | + print(f"Saved to {filepath}") |
| 109 | + |
| 110 | + except (httpx.HTTPError, httpx.RequestError, KeyError) as e: |
| 111 | + print(f"Error: {e}") |
| 112 | + raise typer.Exit(1) |
| 113 | + |
| 114 | +def main(): |
| 115 | + app() |
0 commit comments