I’m having a weird issue with my Django application. I built a feature to get YouTube video transcripts using the youtube-transcript-api library. Everything runs smoothly when I test it on my local machine, but as soon as I deploy to my cloud server (using DigitalOcean App Platform), it breaks.
from youtube_transcript_api import YouTubeTranscriptApi, TranscriptsDisabled, NoTranscriptFound, VideoUnavailable
def get_video_transcript(yt_url):
vid_id = yt_url.split("v=")[-1]
print(f"Processing video ID: {vid_id}")
try:
available_transcripts = YouTubeTranscriptApi.list_transcripts(vid_id)
final_transcript = None
for trans in available_transcripts:
try:
final_transcript = trans.fetch()
break
except Exception as error:
print(f"Failed to get transcript: {error}")
continue
if final_transcript is None:
return "Cannot find any transcripts for this video"
except TranscriptsDisabled:
return "This video has transcripts disabled"
except NoTranscriptFound:
return "No transcript exists for this video"
except VideoUnavailable:
return "This video is not available"
except Exception as error:
return f"Something went wrong: {error}"
full_text = ' '.join([entry['text'] for entry in final_transcript])
return full_text
The problem happens right at available_transcripts = YouTubeTranscriptApi.list_transcripts(vid_id)
. It throws a TranscriptsDisabled error saying the video doesn’t have transcripts available. But I know for sure the video has transcripts because it works fine locally and I can see them on YouTube.
I’ve been stuck on this for days now and tried everything I can think of. Has anyone run into this same problem and found a way to fix it?