-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api.py
More file actions
51 lines (41 loc) · 1.32 KB
/
Copy pathtest_api.py
File metadata and controls
51 lines (41 loc) · 1.32 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
#!/usr/bin/env python3
"""
Test script for the YouTubeSummarizer API
"""
import os
from tldr import YouTubeSummarizer
def main():
# Check if OpenAI API key is set
if not os.getenv('OPENAI_API_KEY'):
print("Please set OPENAI_API_KEY environment variable")
return
# Initialize the summarizer
summarizer = YouTubeSummarizer(
model="gpt-4o-mini",
target_segments=5,
min_segment_minutes=2,
max_segment_minutes=10
)
# Example YouTube URL (replace with actual video)
video_url = "https://youtube.com/watch?v=YOUR_VIDEO_ID"
print("YouTubeSummarizer API Test")
print("=" * 50)
print(f"Processing: {video_url}")
print()
try:
# Process the video
segments = summarizer.process(video_url)
# Display results
print(f"\nCreated {len(segments)} segments:")
print("-" * 50)
for i, segment in enumerate(segments, 1):
print(f"\nSegment {i}:")
print(f"Title: {segment.title}")
print(f"Duration: {segment.duration}")
print(f"Time: {segment.start_time:.1f}s - {segment.end_time:.1f}s")
print(f"Summary: {segment.summary}")
print("-" * 30)
except Exception as e:
print(f"Error processing video: {e}")
if __name__ == "__main__":
main()