Revert "Merge pull request #158 from ben0815/ytTranscriptLanguage"

This reverts commit 70cbf8dda7, reversing
changes made to 88e2964b57.
This commit is contained in:
Daniel Miessler 2024-03-13 14:06:00 -07:00
parent 70cbf8dda7
commit a02b7861d8

View File

@ -1,5 +1,3 @@
#!/usr/bin/env python3
import re import re
from googleapiclient.discovery import build from googleapiclient.discovery import build
from googleapiclient.errors import HttpError from googleapiclient.errors import HttpError
@ -9,7 +7,7 @@ import os
import json import json
import isodate import isodate
import argparse import argparse
import sys
def get_video_id(url): def get_video_id(url):
# Extract video ID from URL # Extract video ID from URL
@ -49,29 +47,9 @@ def main_function(url, options):
duration_seconds = isodate.parse_duration(duration_iso).total_seconds() duration_seconds = isodate.parse_duration(duration_iso).total_seconds()
duration_minutes = round(duration_seconds / 60) duration_minutes = round(duration_seconds / 60)
# Get video transcript language
try:
transcript_available = False
transcript_options = ''
transcript_list = YouTubeTranscriptApi.list_transcripts(video_id)
for transcript in transcript_list:
if options.language == transcript.language_code:
transcript_available = True
else:
transcript_options += transcript.language + ' (' + \
transcript.language_code + '); '
if not transcript_available:
# exit with existing languages, cause get_transcript will fail
sys.exit('"' + options.language + '" not available. ' + \
'Following languages exists: ' + transcript_options)
except Exception as e:
print(e)
# Get video transcript # Get video transcript
try: try:
transcript_list = YouTubeTranscriptApi.get_transcript(video_id, languages=[options.language]) transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
transcript_text = ' '.join([item['text'] transcript_text = ' '.join([item['text']
for item in transcript_list]) for item in transcript_list])
transcript_text = transcript_text.replace('\n', ' ') transcript_text = transcript_text.replace('\n', ' ')
@ -99,8 +77,6 @@ def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='vm (video meta) extracts metadata about a video, such as the transcript and the video\'s duration. By Daniel Miessler.') description='vm (video meta) extracts metadata about a video, such as the transcript and the video\'s duration. By Daniel Miessler.')
parser.add_argument('url', nargs='?', help='YouTube video URL') parser.add_argument('url', nargs='?', help='YouTube video URL')
parser.add_argument('-l', '--language',
help='Set transcript language (default en)', default='en')
parser.add_argument('--duration', action='store_true', parser.add_argument('--duration', action='store_true',
help='Output only the duration') help='Output only the duration')
parser.add_argument('--transcript', action='store_true', parser.add_argument('--transcript', action='store_true',