-
Notifications
You must be signed in to change notification settings - Fork 557
Expand file tree
/
Copy pathmain.py
More file actions
60 lines (50 loc) · 2.33 KB
/
main.py
File metadata and controls
60 lines (50 loc) · 2.33 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
"""CLI entry point.
Usage:
python main.py "https://www.youtube.com/watch?v=..." \
--num-clips 3 --aspect-ratio 9:16 --whisper-model base
"""
import argparse
import json
import sys
from shorts_generator import generate_shorts
def main() -> int:
parser = argparse.ArgumentParser(description="AI YouTube Shorts Generator (MuAPI edition)")
parser.add_argument("url", help="YouTube video URL")
parser.add_argument("--num-clips", type=int, default=3, help="How many shorts to render (default: 3)")
parser.add_argument("--aspect-ratio", default="9:16", help="Output aspect ratio (default: 9:16)")
parser.add_argument("--format", default="720", help="Source download resolution: 360 / 480 / 720 / 1080 (default: 720)")
parser.add_argument("--whisper-model", default="base", help="Whisper size: tiny | base | small | medium | large (default: base)")
parser.add_argument("--language", default=None, help="Force Whisper language code, e.g. 'en' (default: auto-detect)")
parser.add_argument("--output-json", default=None, help="Write the full result JSON to this path")
args = parser.parse_args()
try:
result = generate_shorts(
youtube_url=args.url,
num_clips=args.num_clips,
aspect_ratio=args.aspect_ratio,
download_format=args.format,
whisper_model=args.whisper_model,
language=args.language,
)
except Exception as e:
print(f"\nFAILED: {e}", file=sys.stderr)
return 1
print("\n" + "=" * 72)
print(f"Source video: {result['source_video_url']}")
print(f"Highlights: {len(result['highlights'])} candidates → kept top {len(result['shorts'])}")
print("=" * 72)
for i, s in enumerate(result["shorts"], 1):
print(f"\n#{i} score={s.get('score')} {s.get('start_time'):.1f}s → {s.get('end_time'):.1f}s")
print(f" title: {s.get('title')}")
print(f" hook: {s.get('hook_sentence')}")
if s.get("clip_url"):
print(f" clip: {s['clip_url']}")
else:
print(f" clip: FAILED ({s.get('error')})")
if args.output_json:
with open(args.output_json, "w") as f:
json.dump(result, f, indent=2)
print(f"\nFull JSON written to {args.output_json}")
return 0
if __name__ == "__main__":
sys.exit(main())