-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathall_save.py
44 lines (37 loc) · 2.15 KB
/
all_save.py
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
import os
from save_to_json import save_transcripts_to_json
from save_to_txt import save_transcripts_to_txt
from get_transcript import fetch_transcripts, sanitize_filename, format_filename
def main():
"""Saving the transcripts"""
json_saving_folder = "json_transcripts"
txt_saving_folder = "txt_transcripts"
# Ensure saving folders exist
os.makedirs(json_saving_folder, exist_ok=True)
os.makedirs(txt_saving_folder, exist_ok=True)
for index, url in enumerate(playlist_urls):
transcripts = fetch_transcripts(url)
if transcripts:
first_video_title = transcripts[0][0]
base_filename = format_filename(first_video_title)
# Include index in filename to preserve order
json_filename = f"{index:02d}_transcript_{sanitize_filename(base_filename)}.json"
txt_filename = f"{index:02d}_transcript_{sanitize_filename(base_filename)}.txt"
save_transcripts_to_json(transcripts, os.path.join(json_saving_folder, json_filename))
save_transcripts_to_txt(transcripts, os.path.join(txt_saving_folder, txt_filename))
else:
print(f"No transcripts fetched for playlist: {url}")
if __name__=="__main__":
playlist_urls = [
'https://www.youtube.com/watch?v=Ab-1wMFj3DA&list=PLMcG1Hs2JbcsGGJ84BtG2fClp7SF7K9jU',
'https://www.youtube.com/watch?v=xoJ6vmK9m3Q&list=PLMcG1Hs2JbcsyDndXARl6TVtBRCal0VHD',
'https://www.youtube.com/watch?v=CFRyQZbmJ-M&list=PLMcG1Hs2Jbcu_RpgG0VSuWC4ZcIpUxD8F',
'https://www.youtube.com/watch?v=Q-nS88HWA40&list=PLMcG1Hs2JbcucfbPvfAa6jA_y1RpRxhp5',
'https://www.youtube.com/watch?v=Gm1tVIQyTC0&list=PLMcG1Hs2JbcsUeHH2MMX4YvGPQ8Khe4Uy',
'https://www.youtube.com/watch?v=VMXCMulRtyM&list=PLMcG1Hs2JbcsgmDMZhvsUzm8f7o5qaN3d',
'https://www.youtube.com/watch?v=yJgPct6gAtg&list=PLMcG1Hs2JbcsfCFBHTlRjrK_CHLHlGLRE',
'https://www.youtube.com/watch?v=OE1YKqwD5i8&list=PLMcG1Hs2Jbcshbr_qSsVrwEbrsRs03_7-',
'https://www.youtube.com/watch?v=1LYG2xono0g&list=PLMcG1Hs2JbcvOXwi4y9kDRRYd8xnNKDbV',
'https://www.youtube.com/watch?v=uIc4eSxm1oI&list=PLMcG1Hs2JbcsACzF2loiQuH1mcagq8br3'
]
main()