-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
77 lines (60 loc) · 2.37 KB
/
Copy pathcli.py
File metadata and controls
77 lines (60 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Instagramtranscript CLI Script.
Command-line execution script for transcribing Instagram Reels and Posts directly
from the terminal without launching a web browser.
Usage:
python cli.py "https://www.instagram.com/reel/Cxxxxxx/" --model base --outdir ./output
"""
import sys
import argparse
from pathlib import Path
from dotenv import load_dotenv
from transcriber import InstagramTranscriber
load_dotenv()
def main() -> None:
"""
Parse command-line arguments and run Instagram Transcriber pipeline.
"""
parser = argparse.ArgumentParser(
description="Download audio and transcribe Instagram Reels or Posts using OpenAI Whisper AI."
)
parser.add_argument("url", help="Instagram Reel or Post URL (e.g. https://www.instagram.com/reel/Cxxxxxx/)")
parser.add_argument(
"--model",
default="base",
choices=["tiny", "base", "small", "medium"],
help="Whisper AI model size (default: base)"
)
parser.add_argument(
"--outdir",
default="output",
help="Target output directory for audio and transcript files (default: output)"
)
parser.add_argument(
"--api-key",
default=None,
help="Optional OpenAI API Key for fast cloud transcription using whisper-1 API"
)
args = parser.parse_args()
print(f"[CLI] Processing Instagram URL: {args.url}")
transcriber = InstagramTranscriber(output_dir=args.outdir)
try:
result = transcriber.process_url(args.url, model_name=args.model, openai_api_key=args.api_key)
print("\n" + "=" * 50)
print("=== TRANSCRIPTION COMPLETE ===")
print("=" * 50)
print(f"Audio Saved: {result['audio_file']}")
print("\nTRANSCRIPT:")
print(result['text'])
print("=" * 50)
out_path = Path(args.outdir)
(out_path / "transcript.txt").write_text(result['text'], encoding="utf-8")
(out_path / "transcript.srt").write_text(result['srt'], encoding="utf-8")
(out_path / "transcript.vtt").write_text(result['vtt'], encoding="utf-8")
(out_path / "transcript.json").write_text(result['json'], encoding="utf-8")
print(f"[CLI] Saved transcript files (.txt, .srt, .vtt, .json) to folder: {out_path.resolve()}")
except Exception as e:
print(f"[CLI Error] Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()