Im trying to get the transcript of a number of videos of a playlist. When I run the code I get as a result the list below, which contains the id of each video as key of a dictionary, and a list of dictionaries as the value. Does anyone know how a could extract and join only the "text" from the list and store it in a variable named "GetText"?
this is the code:
from googleapiclient.discovery import build
from youtube_transcript_api import YouTubeTranscriptApi
import os
api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
nextPageToken = None
srt = []
vid_ids = []
vid_title = []
while True:
#1.query API
rq = build("youtube", "v3", developerKey=api_key).playlistItems().list(
part="contentDetails, snippet",
playlistId="PLNIs-AWhQzckr8Dgmgb3akx_gFMnpxTN5",
maxResults=50,
pageToken=nextPageToken
).execute()
#2.Create a list with video Ids and Titles
for item in rq["items"]:
vid_ids.append(item["contentDetails"]["videoId"])
vid_title.append(item["snippet"]["title"])
nextPageToken = rq.get('nextPageToken')
if not nextPageToken:
break
#3.Get transcripts
for i in vid_ids:
try:
srt += [YouTubeTranscriptApi.get_transcripts([i])]
except:
print(f"{i} doesn't have a transcript")
print(srt)
#4.For each video id extract the Key:"text" from a list of dictionaries
?????????????????????
this is a part of the list of transcripts I get:
[
({
"KHO5NIcZAc4":[
{
"text":"welcome to this wise ell tutorial in",
"start":0.23,
"duration":4.15
},
{
"text":"this video we're going to teach you",
"start":3.06,
"duration":3.09
},
...
]
})
]