File size: 924 Bytes
abd418e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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