Thursday, March 13, 2025

How to get youtube video transcript using python

 

How to get youtube video transcript


To extract the transcript from the YouTube video ID sH4JCwjybGs and save it as PEH-Transcript-part2.txt, follow these steps:


Step 1: Open Command Prompt (CMD)

  1. Press Win + R, type cmd, and press Enter.
  2. Type python (or py if python doesn’t work) and press Enter.

Step 2: Paste the Following Python Code

Copy and paste this code directly into your Python environment:

python
from youtube_transcript_api import YouTubeTranscriptApi video_id = "sH4JCwjybGs" # Video ID for PEH Part 2 transcript = YouTubeTranscriptApi.get_transcript(video_id) with open("PEH-Transcript-part2.txt", "w", encoding="utf-8") as file: for entry in transcript: file.write(f"{entry['text']}\n") print("Transcript successfully saved as 'PEH-Transcript-part2.txt'")

Step 3: Run the Code

  1. After pasting the code, press Enter twice (once to run the loop, once to complete the script).
  2. CMD should display:
csharp
Transcript successfully saved as 'PEH-Transcript-part2.txt'

Step 4: Locate the Transcript File

  1. Type dir in CMD to confirm the file’s location.
  2. The file PEH-Transcript-part2.txt will be in the same folder as where CMD is running.

Step 5: Automate Conversion to Book Chapters (Optional)

Once you have the .txt file:

✅ Use ChatGPT, LangChain, or Hemingway Editor to format it into structured content.
✅ For PDF/Book export, use Pandoc with this command:

bash
pandoc "PEH-Transcript-part2.txt" -o "PEH-Transcript-part2.pdf" --toc --highlight-style=tango

If you’d like a step-by-step guide for creating detailed book chapters automatically from this transcript, let me know