import streamlit as st from pytube import YouTube import subprocess def download_youtube_video(url): yt = YouTube(url) video = yt.streams.filter(only_audio=True).first() video.download() def convert_to_mp3(video_file): audio_file = video_file.replace(".webm", ".mp3").replace(".mkv", ".mp3") subprocess.run(['ffmpeg', '-i', video_file, '-vn', '-acodec', 'libmp3lame', audio_file]) return audio_file def main(): st.title('YouTube Video to MP3 Converter') youtube_url = st.text_input('Enter YouTube video URL:') if st.button('Convert to MP3'): if youtube_url: st.text('Downloading video...') download_youtube_video(youtube_url) video_filename = YouTube(youtube_url).title + ".mp4" st.text('Converting to MP3...') mp3_file = convert_to_mp3(video_filename) st.success(f"Conversion completed! MP3 file saved as: {mp3_file}") if __name__ == "__main__": main()