Hey there! π Imagine watching a YouTube video and thinking, "I wish I could have the transcript in seconds." Well, this handy YouTube Video Transcriber app does just that! Letβs dive straight in and see how it works. π
Here is the demo of this application :
What Does This App Do? π₯βοΈ
This app lets you:
- Fetch Video Details: Get the title and description of a YouTube video.
- Transcribe Videos: Extract subtitles/transcripts in seconds (if available).
Cool, right? You donβt even need to leave your browser.
How Does It Work? π οΈ
- Enter YouTube API Key π: To access video details, you'll need your YouTube Data API Key.
- Paste YouTube URL π: Share the video link you want transcribed.
- Hit Transcribe β¨: The app fetches the details and subtitles, displaying them instantly.
Keys Setup π
Step 1: Set Up a Google Cloud Project
1) Go to the Google Cloud Console.
2) Sign in with your Google account.
3) Click Select a Project in the top menu, then click New Project.
4) Enter a project name (e.g., "Video Transcriber") and click Create.
Step 2: Enable the YouTube Data API
1) In the Cloud Console, go to the API Library.
2) Search for YouTube Data API v3.
3) Click on the YouTube Data API v3 result, then click Enable.
Step 3: Create API Credentials
1) Go to the Credentials page.
2) Click + CREATE CREDENTIALS and select API Key.
3) Your API key will be generated. Copy it and save it somewhere safe.
Code Breakdown π»
Hereβs the magic:
Extracting the Video ID π½οΈ
The get_video_id()
function grabs the video ID from URLs like https://www.youtube.com/watch?v=VIDEO_ID
.
def get_video_id(url):
if "watch?v=" in url:
return url.split("watch?v=")[1].split("&")[0]
elif "youtu.be/" in url:
return url.split("youtu.be/")[1].split("?")[0]
return None
Fetching Video Details π
Using the YouTube Data API, fetch_video_details()
pulls video title and description.
youtube = build("youtube", "v3", developerKey=api_key)
request = youtube.videos().list(part="snippet", id=video_id)
response = request.execute()
Fetching the Transcript π£οΈ
The YouTubeTranscriptApi
library retrieves the transcript for the video (if enabled).
transcript = YouTubeTranscriptApi.get_transcript(video_id)
return "\n".join([item['text'] for item in transcript])
Streamlit Magic πͺ
Finally, Streamlit makes the app interactive and easy to use:
- Accept inputs for API key and video URL.
- Show video details and transcript on the same page.
Here is the final code details :
import streamlit as st
from googleapiclient.discovery import build
from youtube_transcript_api import YouTubeTranscriptApi
def get_video_id(url):
"""Extracts video ID from a YouTube URL."""
if "watch?v=" in url:
return url.split("watch?v=")[1].split("&")[0]
elif "youtu.be/" in url:
return url.split("youtu.be/")[1].split("?")[0]
return None
def fetch_video_details(api_key, video_id):
"""Fetches video details using the YouTube Data API."""
youtube = build("youtube", "v3", developerKey=api_key)
request = youtube.videos().list(part="snippet", id=video_id)
response = request.execute()
if "items" in response and len(response["items"]) > 0:
snippet = response["items"][0]["snippet"]
title = snippet["title"]
description = snippet["description"]
return title, description
return None, None
def fetch_transcript(video_id):
"""Fetches the transcript for a YouTube video."""
try:
transcript = YouTubeTranscriptApi.get_transcript(video_id)
return "\n".join([item['text'] for item in transcript])
except Exception as e:
return f"Error fetching transcript: {str(e)}"
# Streamlit UI
st.title("YouTube Video Transcriber")
youtube_api_key = st.text_input("Enter your YouTube Data API Key:", type="password")
youtube_url = st.text_input("Enter YouTube Video URL:")
if st.button("Transcribe"):
if not youtube_api_key or not youtube_url:
st.error("Please provide both API Key and Video URL.")
else:
video_id = get_video_id(youtube_url)
if not video_id:
st.error("Invalid YouTube URL.")
else:
with st.spinner("Fetching video details..."):
title, description = fetch_video_details(youtube_api_key, video_id)
if not title:
st.error("Unable to fetch video details. Check API Key and URL.")
else:
st.success("Video details fetched successfully!")
st.write(f"**Title:** {title}")
st.write(f"**Description:** {description}")
with st.spinner("Fetching transcript..."):
transcript = fetch_transcript(video_id)
st.text_area("Transcript:", value=transcript, height=300)
st.success("Transcript fetched successfully!")
Setup in 3 Steps β‘
1) Install the dependencies:
pip install -r requirements.txt
2) Run the app:
streamlit run app.py
3) Enjoy your transcripts instantly! π
Future Features? π€
Here are some cool ideas you can add:
- Download Transcript as a text file. π
- Summarize Transcript using AI. π€
- Translate Transcript to other languages. π
Feel inspired? Head over to the GitHub Repo and contribute your ideas! π
Jagroop2001 / video-transcriber
Video Transcriber with Streamlit & Youtube API
YouTube Video Transcriber
This is a Streamlit application that allows you to fetch and transcribe the content of a YouTube video using the YouTube Data API and YouTube Transcript API.
Features
- Extracts the video ID from a YouTube URL.
- Fetches the title and description of the YouTube video using the YouTube Data API.
- Retrieves and displays the transcript of the YouTube video.
- User-friendly interface built with Streamlit.
Requirements
This project requires the following Python packages:
streamlit
google-api-python-client
youtube-transcript-api
To install the necessary dependencies, create a virtual environment and install the packages from the requirements.txt
file:
pip install -r requirements.txt
Setting Up
- Obtain a YouTube Data API key by following the instructions on the Google Developers Console.
- Clone or download this repository to your local machine.
- Install the required dependencies using the command above.
- Run the Streamlit app:
streamlit run app.py
Usage
- Open the application in your web browser (usuallyβ¦
Letβs build something awesome together! π
Top comments (8)
It cause issue which python version are you using for this. @jagroop2001
My system have python version of
3.11.11
, But I think any python3 version will works well.got it, I am using version 2 that's why it cause issue.
It would also work for some python2 version.
Such a great, simple, clear project. I would surely contribute to this.
Thanks @john12
It's such a cool & simple mini project. Also code is very clearly written.
Thanks @works