umer70112254 commited on
Commit
0a96c8a
·
1 Parent(s): 7225c6e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from pytube import YouTube
3
+ import subprocess
4
+
5
+ def download_youtube_video(url):
6
+ yt = YouTube(url)
7
+ video = yt.streams.filter(only_audio=True).first()
8
+ video.download()
9
+
10
+ def convert_to_mp3(video_file):
11
+ audio_file = video_file.replace(".webm", ".mp3").replace(".mkv", ".mp3")
12
+ subprocess.run(['ffmpeg', '-i', video_file, '-vn', '-acodec', 'libmp3lame', audio_file])
13
+ return audio_file
14
+
15
+ def main():
16
+ st.title('YouTube Video to MP3 Converter')
17
+ youtube_url = st.text_input('Enter YouTube video URL:')
18
+
19
+ if st.button('Convert to MP3'):
20
+ if youtube_url:
21
+ st.text('Downloading video...')
22
+ download_youtube_video(youtube_url)
23
+ video_filename = YouTube(youtube_url).title + ".mp4"
24
+ st.text('Converting to MP3...')
25
+ mp3_file = convert_to_mp3(video_filename)
26
+ st.success(f"Conversion completed! MP3 file saved as: {mp3_file}")
27
+
28
+ if __name__ == "__main__":
29
+ main()