Я пытаюсь извлечь расшифровки видео с YouTube с помощью Youtube API или другого пакета Python.
Я нашел код в Google и попробовал.
# importing the module
from youtube_transcript_api import YouTubeTranscriptApi
# retrieve the available transcripts
transcript_list = YouTubeTranscriptApi.list_transcripts('pxiP-HJLCx0')
# iterate over all available transcripts
for transcript in transcript_list:
# the Transcript object provides metadata
# properties
print(
transcript.video_id,
transcript.language,
transcript.language_code,
# whether it has been manually created or
# generated by YouTube
transcript.is_generated,
# whether this transcript can be translated
# or not
transcript.is_translatable,
# a list of languages the transcript can be
# translated to
transcript.translation_languages,
)
# fetch the actual transcript data
print(transcript.fetch())
# translating the transcript will return another
# transcript object
print(transcript.translate('en').fetch())
# you can also directly filter for the language you are
# looking for, using the transcript list
transcript = transcript_list.find_transcript(['en'])
# or just filter for manually created transcripts
transcript = transcript_list.find_manually_created_transcript(['en'])
# importing modules
from youtube_transcript_api import YouTubeTranscriptApi
# using the srt variable with the list of dictionaries
# obtained by the .get_transcript() function
srt = YouTubeTranscriptApi.get_transcript("pxiP-HJLCx0")
# creating or overwriting a file "subtitles.txt" with
# the info inside the context manager
with open("subtitles.txt", "w") as f:
# iterating through each element of list srt
for i in srt:
# writing each element of srt on a new line
f.write("{}\n".format(i))
< /code>
Он извлекает транскрипты, но проблема в том, что он содержит не только текст, но и время начала и продолжительности. Поскольку не существует знаков препинания, предложения не разделены, и кажется, что слова только что перечислены в ряду, что затрудняет анализ текста. < /P>
{'text': "in this video I'm going to tell you the", 'start': 0.0, 'duration': 4.74}
{'text': 'best laptops for students now for this', 'start': 2.159, 'duration': 5.16}
{'text': 'one my team and I went absolutely nuts', 'start': 4.74, 'duration': 4.68}
{'text': 'we got in pretty much every viable', 'start': 7.319, 'duration': 4.801}
{'text': "student laptop think I'm joking I am not", 'start': 9.42, 'duration': 6.299}
{'text': 'we tested an epic 15 laptops everything', 'start': 12.12, 'duration': 5.52}
< /code>
Как я могу решить эту проблему? Спасибо
Подробнее здесь: https://stackoverflow.com/questions/768 ... -on-python
Как извлечь видео -транскрипты на YouTube с использованием API YouTube на Python ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Microsoft Graph API: не удалось выполнить запрос на бэкэнд - получить транскрипты
Anonymous » » в форуме C# - 0 Ответы
- 2 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Как добавить текущий URL -адрес страницы в транскрипты агента Voiceflow AI
Anonymous » » в форуме Javascript - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Воспроизведение видео на YouTube: Аккаунт YouTube, связанный с этим видео, закрыт.
Anonymous » » в форуме IOS - 0 Ответы
- 57 Просмотры
-
Последнее сообщение Anonymous
-