-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
46 lines (32 loc) · 1.41 KB
/
main.py
File metadata and controls
46 lines (32 loc) · 1.41 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
import os
from src.youtube import get_video_transcript, get_channel_videos, save_transcript
from src.chatgpt import get_chatgpt_category
from src.csv_writer import write_to_csv, write_csv_headers
from openai import OpenAI
def main(youtube_api_key: str, openai_client: OpenAI, channel_id: str, output_dir: str):
if not os.path.exists(output_dir):
os.makedirs(output_dir)
csv_file = os.path.join(output_dir, "video_details.csv")
write_csv_headers(csv_file)
video_data = get_channel_videos(youtube_api_key, channel_id)
print(f"Found {len(video_data)} videos in the channel.")
for video_id, video_title in video_data:
transcript = get_video_transcript(video_id)
if transcript:
category = get_chatgpt_category(transcript, openai_api_key)
if category:
transcript_file_path = save_transcript(
video_id, video_title, transcript, category, output_dir
)
write_to_csv(video_id, csv_file)
if __name__ == "__main__":
# Replace with your YouTube Data API key
YOUTUBE_API_KEY = ""
# Replace with your target YouTube channel ID
CHANNEL_ID = ""
# Replace with your OpenAI API Key
OPENAI_API_KEY = ""
openapi_client = OpenAI(api_key=OPENAI_API_KEY)
# Directory to save transcripts
output_dir = "transcripts"
main(YOUTUBE_API_KEY, openapi_client, CHANNEL_ID, output_dir)