BilalSardar commited on
Commit
7e0ba5b
·
1 Parent(s): 7fccfb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -34,7 +34,30 @@ import spacy
34
 
35
 
36
  warnings.filterwarnings("ignore")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
 
 
38
  def Process_audio(fileName):
39
  text=''
40
  txtf=open("The_audio.txt","w+")
@@ -66,7 +89,8 @@ except:
66
 
67
  def UrlToAudio(VideoUrl):
68
  url=VideoUrl
69
- os.system("yt-dlp -x --audio-format wav " + url)
 
70
  # load audio and pad/trim it to fit 30 seconds
71
  base_path = Path(r"")
72
  for wav_file_path in base_path.glob("*.wav"):
 
34
 
35
 
36
  warnings.filterwarnings("ignore")
37
+ def download_youtube(url, choice, res):
38
+
39
+ yt = pytube.YouTube(url)
40
+
41
+ if choice == 'mp3':
42
+ audio = yt.streams.filter(only_audio=True).first()
43
+ print(f"Downloading {audio.title} as MP3")
44
+ return audio.download()
45
+
46
+ elif choice == 'mp4':
47
+ if res == "720p":
48
+ video = yt.streams.filter(res="720p").first()
49
+ elif res == "1080p":
50
+ video = yt.streams.filter(res="1080p").first()
51
+ elif res == "2160p":
52
+ video = yt.streams.filter(res="2160p").first()
53
+ else:
54
+ return "Invalid resolution"
55
+
56
+ print(f"Downloading {video.title} at {video.resolution}")
57
+ return video.download()
58
 
59
+ else:
60
+ return "Invalid choice"
61
  def Process_audio(fileName):
62
  text=''
63
  txtf=open("The_audio.txt","w+")
 
89
 
90
  def UrlToAudio(VideoUrl):
91
  url=VideoUrl
92
+ #os.system("yt-dlp -x --audio-format wav " + url)
93
+ download_youtube(VideoUrl,"mp3","")
94
  # load audio and pad/trim it to fit 30 seconds
95
  base_path = Path(r"")
96
  for wav_file_path in base_path.glob("*.wav"):