nayyabzahra148 commited on
Commit
abd418e
1 Parent(s): 4da2956

Create Translator.py

Browse files
Files changed (1) hide show
  1. Translator.py +33 -0
Translator.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from youtube_transcript_api import YouTubeTranscriptApi as yt
2
+ import pytube
3
+ from deep_translator import GoogleTranslator as gt
4
+
5
+ def VideoToSubtitle(url,language):
6
+ id=pytube.extract.video_id(url)
7
+ video_subtitle=yt.get_transcript(id)
8
+ final_data=''
9
+ translate_data=''
10
+ i=0
11
+ j=0
12
+ for data in video_subtitle:
13
+ final_data=final_data+""+video_subtitle[i].get("text")
14
+ i=i+1
15
+ mode=" "
16
+ if(language=="Arabic"):
17
+ mode="arabic"
18
+ elif(language=="French"):
19
+ mode="french"
20
+ elif(language=="German"):
21
+ mode="german"
22
+ elif(language=="Persian"):
23
+ mode="persian"
24
+ elif(language=="Spanish"):
25
+ mode="spanish"
26
+ else:
27
+ mode="english"
28
+ for Conv_data in video_subtitle:
29
+ translate_data=translate_data+""+gt(source="auto",target=mode).translate(video_subtitle[j].get("text"))
30
+ j=j+1
31
+ translate_data=translate_data.replace("\n"," ")
32
+ final_data.replace("\n"," ")
33
+ return final_data,translate_data