• Home
  • Guides
    • All
    • Linux
    • Programming
    • Tools
    • WordPress
    My Backup Setup for Linux PCs

    My Backup Setup for Linux PCs

    Detecting Hidden WordPress Malware Disguised as Images

    Detecting Hidden WordPress Malware Disguised as Images

    Server-Side Image Conversion with Apache

    Server-Side Image Conversion with Apache

    Fastest Way to Extract a Massive .tar.gz File on Linux

    Fastest Way to Extract a Massive .tar.gz File on Linux

    Monitor SSL Expiration with Python

    Monitor SSL Expiration with Python

    Building a Simple WordPress Post List Tool with PHP

    Building a Simple WordPress Post List Tool with PHP

    Monitoring Web Page Changes with Python

    Monitoring Web Page Changes with Python

    My SSH Setup: How I Manage Multiple Servers

    My SSH Setup: How I Manage Multiple Servers

    Building a Network Tracker Auditor for Privacy with Python

    Building a Network Tracker Auditor for Privacy with Python

  • Blog
    • All
    • Artificial Intelligence
    • Developer Life
    • Privacy
    • Reviews
    • Security
    • Tutorials
    Imposter Syndrome as a Self-Taught Developer

    Imposter Syndrome as a Self-Taught Developer

    Why Stable Websites Outperform Flashy Redesigns

    Why Stable Websites Outperform Flashy Redesigns

    AdGuard Ad Blocker Review

    AdGuard Ad Blocker Review

    Surfshark VPN Review

    Surfshark VPN Review

    Nmap Unleash the Power of Cybersecurity Scanning

    Nmap: Unleash the Power of Cybersecurity Scanning

    Floorp Browser Review

    Floorp Browser Review

    Understanding Man-in-the-Middle Attacks

    Understanding Man-in-the-Middle Attacks

    Privacy-Focused Analytics

    Privacy-Focused Analytics: Balancing Insights and Integrity

    Safeguarding Your Facebook Account

    Safeguarding Your Facebook Account: Understanding the Differences Between Hacking and Cloning

  • Apps
    • Bible App
    • Bible Verse Screensaver
    • Blue AI Chatbot
    • Early Spring Predictor
    • FIGlet Generator
    • Password Generator
    • StegX
    • The Matrix
    • WeatherX
    • Website Risk Level Tool
  • About
    • About JMooreWV
    • Live Cyber Attack Stats
  • Contact
    • General Contact
    • Website Administration & Cybersecurity
No Result
View All Result
  • Home
  • Guides
    • All
    • Linux
    • Programming
    • Tools
    • WordPress
    My Backup Setup for Linux PCs

    My Backup Setup for Linux PCs

    Detecting Hidden WordPress Malware Disguised as Images

    Detecting Hidden WordPress Malware Disguised as Images

    Server-Side Image Conversion with Apache

    Server-Side Image Conversion with Apache

    Fastest Way to Extract a Massive .tar.gz File on Linux

    Fastest Way to Extract a Massive .tar.gz File on Linux

    Monitor SSL Expiration with Python

    Monitor SSL Expiration with Python

    Building a Simple WordPress Post List Tool with PHP

    Building a Simple WordPress Post List Tool with PHP

    Monitoring Web Page Changes with Python

    Monitoring Web Page Changes with Python

    My SSH Setup: How I Manage Multiple Servers

    My SSH Setup: How I Manage Multiple Servers

    Building a Network Tracker Auditor for Privacy with Python

    Building a Network Tracker Auditor for Privacy with Python

  • Blog
    • All
    • Artificial Intelligence
    • Developer Life
    • Privacy
    • Reviews
    • Security
    • Tutorials
    Imposter Syndrome as a Self-Taught Developer

    Imposter Syndrome as a Self-Taught Developer

    Why Stable Websites Outperform Flashy Redesigns

    Why Stable Websites Outperform Flashy Redesigns

    AdGuard Ad Blocker Review

    AdGuard Ad Blocker Review

    Surfshark VPN Review

    Surfshark VPN Review

    Nmap Unleash the Power of Cybersecurity Scanning

    Nmap: Unleash the Power of Cybersecurity Scanning

    Floorp Browser Review

    Floorp Browser Review

    Understanding Man-in-the-Middle Attacks

    Understanding Man-in-the-Middle Attacks

    Privacy-Focused Analytics

    Privacy-Focused Analytics: Balancing Insights and Integrity

    Safeguarding Your Facebook Account

    Safeguarding Your Facebook Account: Understanding the Differences Between Hacking and Cloning

  • Apps
    • Bible App
    • Bible Verse Screensaver
    • Blue AI Chatbot
    • Early Spring Predictor
    • FIGlet Generator
    • Password Generator
    • StegX
    • The Matrix
    • WeatherX
    • Website Risk Level Tool
  • About
    • About JMooreWV
    • Live Cyber Attack Stats
  • Contact
    • General Contact
    • Website Administration & Cybersecurity
No Result
View All Result
Home Guides Programming Python

How to Transcribe YouTube Videos with Python

Jonathan Moore by Jonathan Moore
5 years ago
Reading Time: 3 mins read
A A
How to Transcribe YouTube Videos with Python
FacebookTwitter

In May 2020, while in the middle of doing some research, I came across a YouTube video on a piece of history that I was researching. The video was long and had a lot of reference information that I needed. Instead of replaying the clip over and over to hear the information that I needed, I decided to find a way to obtain a transcript of the video.

Whenever I have a problem to solve, I jump straight to Python for the solution. With a little research, I found an API that will allow you to transcribe YouTube videos for Python called, YouTube Transcript/Subtitle API.

This is a Python API that allows you to get the transcript/subtitles for a given YouTube video. It also works for automatically generated subtitles, supports translating subtitles, and does not require a headless browser, as other Selenium-based solutions do.

You can install this API by using the following command:

pip install youtube_transcript_api

This API works by passing the YouTube video ID to YouTubeTranscriptApi.get_transcript function. The function then returns a dictionary of transcripts for the video. The API has many different options that you can use.

The following code will allow you to grab the transcript/subtitles for a given YouTube video. An error message will be displayed if the video does not contain a transcript. The code will accept one of the following formats:

  • Full YouTube Video URL (https://www.youtube.com/watch?v=BvA0J_2ZpIQ)
  • Short YouTube Video URL (https://youtu.be/BvA0J_2ZpIQ)
  • YouTube Video ID (BvA0J_2ZpIQ)

The code will extract the video ID from the YouTube URL if the URL is used instead of a YouTube video ID.

#!/usr/bin/python3

from youtube_transcript_api import YouTubeTranscriptApi


def get_transcript(video):
    # Extract the Video ID from the YouTube URLs
    if "youtu.be" in video:
        video_id = video.split("/")[3]
    elif "watch?v=" in video:
        video_id = video.split("=")[1]
    else:
        # Video is not a URL but the ID
        video_id = video

    try:
        # Create an empty list to store transcript lines
        transcript_lines = []
        # Iterate over the APIs Dictionary of transcripts
        for transcript in YouTubeTranscriptApi.get_transcript(video_id):
           # Append the text value of each line to the list
           transcript_lines.append(transcript['text'])
        # Join the list elements together separated by a new line and return the results
        return '\n'.join(transcript_lines)
    except:
        # No transcript was found for the video, return an error
        return "Transcription is not available for this video."


if __name__ == "__main__":
    # Pass the YouTube Video to the 'get_transcript' function
    print(get_transcript('https://youtu.be/iODxExWFx_0'))

Terminal Output:

[Music]<br>
cyber security is the term used to<br>
characterize<br>
and collect all of the activities<br>
policies<br>
procedures and tools used in concert to<br>
protect the information technology<br>
systems and data<br>
that is core to the functioning of the<br>
modern world<br>
the protections of cyber security apply<br>
to physical systems<br>
software systems as well as the people<br>
who use them<br>
there are multiple things that<br>
organizations can do to implement cyber<br>
security protections<br>
these include having agreed policies and<br>
procedures<br>
regular staff awareness training deploy<br>
strong password management tools<br>
and multi-factor authentication<br>
implement identity access management and<br>
privileged access management encrypt<br>
data at rest<br>
and in transit over networks install<br>
endpoint protection software and keep it<br>
up to date<br>
do frequent backups to secure locations<br>
and keep all it systems including<br>
network equipment up to date via<br>
installation of the latest<br>
security and operating systems updates<br>
the insights external threat protection<br>
suite enhances cyber security protection<br>
measures<br>
by applying threat intelligence allowing<br>
the monitoring of multiple sources to<br>
identify<br>
threats to your organization on the<br>
clear deep<br>
and dark web that could indicate<br>
potential cyber attack planning<br>
or data exposure against your brand<br>
people<br>
or infrastructure to deliver actionable<br>
insights that can be taken<br>
to mitigate the attack and risk

The code above will display the video transcript in your terminal. You may wish to modify the code so that it saves the output into a file instead. This snippet of code will allow you to do just that.

#!/usr/bin/python3

from youtube_transcript_api import YouTubeTranscriptApi


def get_transcript(video, file_name):
    # Extract the Video ID from the YouTube URLs
    if "youtu.be" in video:
        video_id = video.split("/")[3]
    elif "watch?v=" in video:
        video_id = video.split("=")[1]
    else:
        # Video is not a URL but the ID
        video_id = video

    try:
        # Create an empty list to store transcript lines
        transcript_lines = []
        # Iterate over the APIs Dictionary of transcripts
        for transcript in YouTubeTranscriptApi.get_transcript(video_id):
           # Append the text value of each line to the list
           transcript_lines.append(transcript['text'])

        # Create a file and write the Transcript to it
        with open(file_name, "w") as file:
            # Join the list elements together separated by a new line and write to file
            file.write('\n'.join(transcript_lines))

        # Return a successful message
        return "The transcript has been created."
    except:
        # No transcript was found for the video, return an error
        return "Transcription is not available for this video."


if __name__ == "__main__":
    # Pass the YouTube Video and file name to the 'get_transcript' function
    print(get_transcript('https://youtu.be/iODxExWFx_0', "transcript.txt"))
Tags: ProgrammingPython
ShareTweetSharePinShareShareScan
ADVERTISEMENT
Jonathan Moore

Jonathan Moore

I am a Software Architect and Senior Software Engineer with 30+ years of experience building applications for Linux and Windows systems. I focus on system architecture, custom web platforms, server infrastructure, and security-focused tools, with an emphasis on performance and reliability. Over the years, I have built everything from WordPress plugins and automation systems to full platforms, ad serving systems, monitoring tools, and API-driven applications. I prefer working close to the system, solving real problems, and building tools that are meant to be used.

Related Articles

Server-Side Image Conversion with Apache

Server-Side Image Conversion with Apache

I stopped relying on third party image services a while ago. They work, but they add cost, latency, and another...

Fastest Way to Extract a Massive .tar.gz File on Linux

Fastest Way to Extract a Massive .tar.gz File on Linux

When I am dealing with a 40GB or 50GB website backup, I do not just run tar -xzf file.tar.gz and...

Monitor SSL Expiration with Python

Monitor SSL Expiration with Python

SSL certificates are one of those systems that work quietly in the background until something goes wrong. When a certificate...

Next Post
Using XlsxWriter to Create an Excel Spreadsheet

Using XlsxWriter to Create an Excel Spreadsheet

Recommended Services

Latest Articles

My Backup Setup for Linux PCs

My Backup Setup for Linux PCs

March 31st is World Backup Day. It is meant to be a reminder, but I do not rely on reminders...

Read moreDetails

Detecting Hidden WordPress Malware Disguised as Images

Detecting Hidden WordPress Malware Disguised as Images

With the recent discovery of malicious files like Stained_Heart_Red-600x500.png being found on servers across the web, it pushed me to...

Read moreDetails

Server-Side Image Conversion with Apache

Server-Side Image Conversion with Apache

I stopped relying on third party image services a while ago. They work, but they add cost, latency, and another...

Read moreDetails

Imposter Syndrome as a Self-Taught Developer

Imposter Syndrome as a Self-Taught Developer

I started writing code over 35 years ago. Everything I learned came from figuring things out on my own, long...

Read moreDetails
  • Privacy Policy
  • Terms of Service

© 2025 JMooreWV. All rights reserved.

No Result
View All Result
  • Home
  • Guides
    • Linux
    • Programming
      • JavaScript
      • PHP
      • Python
    • Tools
    • WordPress
  • Blog
    • Artificial Intelligence
    • Tutorials
    • Privacy
    • Security
  • Apps
    • Bible App
    • Bible Verse Screensaver
    • Blue AI Chatbot
    • Early Spring Predictor
    • FIGlet Generator
    • Password Generator
    • StegX
    • The Matrix
    • WeatherX
    • Website Risk Level Tool
  • About
    • About JMooreWV
    • Live Cyber Attack Stats
  • Contact
    • General Contact
    • Website Administration & Cybersecurity