-
Notifications
You must be signed in to change notification settings - Fork 2
/
goaltube.py
36 lines (26 loc) · 983 Bytes
/
goaltube.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
# -*- coding: utf-8 -*-
"""GoalTube.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/14rIss-KpwPr2knkEYTm9Oh9deaHdihTk
Import library for youtube api
"""
pip install youtube_transcript_api
from youtube_transcript_api import YouTubeTranscriptApi
# assigning srt variable with the list of dictonaries
# obtained by the the .get_transcript() function
# and this time it gets only the subtitles that
# are of english langauge.
srt = YouTubeTranscriptApi.get_transcript("SW14tOda_kI",
languages=['en'])
print(srt)
# creating or overwriting a file "subtitles.txt" with
# the info inside the context manager
cap = []
with open("subtitles.txt", "w") as f:
# iterating through each element of list srt
for i in srt:
# writing each element of srt on a new line
text = i['text']
f.write("{}".format(text))
"""Model Implementation"""