30 lines
No EOL
1.1 KiB
Python
30 lines
No EOL
1.1 KiB
Python
import yt_dlp
|
|
|
|
def download_transcript(url):
|
|
ydl_opts = {
|
|
'skip_download': True, # Don't download the video
|
|
'writesubtitles': True, # Write subtitles file
|
|
'writeautomaticsub': True, # Write automatic subtitles file
|
|
'subtitlesformat': 'txt', # Format as plain text
|
|
'quiet': True, # Less output in console
|
|
'no_warnings': True # Don't show warnings
|
|
}
|
|
|
|
try:
|
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
|
# Extract video info first
|
|
info = ydl.extract_info(url, download=False)
|
|
video_title = info.get('title', 'video')
|
|
print(f"Downloading transcript for: {video_title}")
|
|
|
|
# Download the transcript
|
|
ydl.download([url])
|
|
print("Transcript downloaded successfully")
|
|
|
|
except Exception as e:
|
|
print(f"Error downloading transcript: {str(e)}")
|
|
|
|
if __name__ == "__main__":
|
|
# Example usage
|
|
video_url = "https://youtu.be/xpki1IcjinU?si=AACF69HJw39TqlD1"
|
|
download_transcript(video_url) |