Spaces:
Runtime error
Runtime error
from youtube_transcript_api import YouTubeTranscriptApi as yt | |
import pytube | |
from deep_translator import GoogleTranslator as gt | |
def VideoToSubtitle(url,language): | |
id=pytube.extract.video_id(url) | |
video_subtitle=yt.get_transcript(id) | |
final_data='' | |
translate_data='' | |
i=0 | |
j=0 | |
for data in video_subtitle: | |
final_data=final_data+""+video_subtitle[i].get("text") | |
i=i+1 | |
mode=" " | |
if(language=="Arabic"): | |
mode="arabic" | |
elif(language=="French"): | |
mode="french" | |
elif(language=="German"): | |
mode="german" | |
elif(language=="Persian"): | |
mode="persian" | |
elif(language=="Spanish"): | |
mode="spanish" | |
else: | |
mode="english" | |
for Conv_data in video_subtitle: | |
translate_data=translate_data+""+gt(source="auto",target=mode).translate(video_subtitle[j].get("text")) | |
j=j+1 | |
translate_data=translate_data.replace("\n"," ") | |
final_data.replace("\n"," ") | |
return final_data,translate_data |