mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-01 11:56:25 +02:00
Merge pull request #336 from sandeeppainuly/fix-294-youtube-transcript-source-not-working-youtubetranscriptapi-has-no-attribute-get-transcript
Fix YouTube transcript API: replace deprecated get_transcript with fetch method
This commit is contained in:
commit
4e012845c4
1 changed files with 5 additions and 4 deletions
|
|
@ -136,13 +136,14 @@ async def add_youtube_video_document(
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
captions = YouTubeTranscriptApi.get_transcript(video_id)
|
ytt_api = YouTubeTranscriptApi()
|
||||||
|
captions = ytt_api.fetch(video_id)
|
||||||
# Include complete caption information with timestamps
|
# Include complete caption information with timestamps
|
||||||
transcript_segments = []
|
transcript_segments = []
|
||||||
for line in captions:
|
for line in captions:
|
||||||
start_time = line.get("start", 0)
|
start_time = line.start
|
||||||
duration = line.get("duration", 0)
|
duration = line.duration
|
||||||
text = line.get("text", "")
|
text = line.text
|
||||||
timestamp = f"[{start_time:.2f}s-{start_time + duration:.2f}s]"
|
timestamp = f"[{start_time:.2f}s-{start_time + duration:.2f}s]"
|
||||||
transcript_segments.append(f"{timestamp} {text}")
|
transcript_segments.append(f"{timestamp} {text}")
|
||||||
transcript_text = "\n".join(transcript_segments)
|
transcript_text = "\n".join(transcript_segments)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue