DEV Community

Cover image for Getting the Transcription of a Video From Youtube using google cloud platform.
Amrut
Amrut

Posted on • Edited on

Getting the Transcription of a Video From Youtube using google cloud platform.

So, the other day I was searching for python code that gives me a transcript of any video, I did what all we do I searched everywhere on Internet but was unfortunate. But we are programmers best thing we do is search more on the internet. finally, I got the code I wanted, all thanks to
Pragnakalp Techlabs
. Although the code was a little different from my expectations I did some filters on it and made it to view the transcripts of the youtube video.
Be patient there are going to be few steps involved in our process !!


# pip install google-api-python-client
# pip install youtube_transcript_api

from apiclient.discovery import build
from youtube_transcript_api import YouTubeTranscriptApi

api_key = "Secret Key"  # replace it with your API key
video_id = str(input("Enter the video id: "))  # replace it with your channel id
youtube = build('youtube', 'v3',developerKey=api_key)

try:
        responses = YouTubeTranscriptApi.get_transcript(
            video_id, languages=['en'])
        print('\n'+"Video: "+"https://www.youtube.com/watch?v=" +
              str(video_id)+'\n'+'\n'+"Captions:")
        for response in responses:
            text = response['text']
            print(text)
except Exception as e:
        print(e)

# pip install google-api-python-client
# pip install youtube_transcript_api

from apiclient.discovery import build
from youtube_transcript_api import YouTubeTranscriptApi

api_key = "Secret Key"  # replace it with your API key
video_id = str(input("Enter the video id: "))  # replace it with your channel id
youtube = build('youtube', 'v3',developerKey=api_key)

try:
        responses = YouTubeTranscriptApi.get_transcript(
            video_id, languages=['en'])
        print('\n'+"Video: "+"https://www.youtube.com/watch?v=" +
              str(video_id)+'\n'+'\n'+"Captions:")
        for response in responses:
            text = response['text']
            print(text)
except Exception as e:
        print(e)

# pip install google-api-python-client
# pip install youtube_transcript_api

from apiclient.discovery import build
from youtube_transcript_api import YouTubeTranscriptApi

api_key = "Secret Key"  # replace it with your API key
video_id = str(input("Enter the video id: "))  # replace it with your channel id
youtube = build('youtube', 'v3',developerKey=api_key)

try:
        responses = YouTubeTranscriptApi.get_transcript(
            video_id, languages=['en'])
        print('\n'+"Video: "+"https://www.youtube.com/watch?v=" +
              str(video_id)+'\n'+'\n'+"Captions:")
        for response in responses:
            text = response['text']
            print(text)
except Exception as e:
        print(e)

Enter fullscreen mode Exit fullscreen mode

For full tutorial how to get the API key and all that thing you can check out my medium article on this 👇👇👇

https://medium.com/@computer_geek/getting-the-transcription-of-a-video-from-youtube-using-google-cloud-platform-3c862d1276a5

To be honest, I am finding it little difficult to write code and syntax highlighting and inserting images on dev platform, but the code may not look very attractive but that works fine for any video on youtube.

And also you can follow me on my twitter

https://twitter.com/computer_geek77/

Top comments (0)