import streamlit as st from pytube import YouTube import os # Function to download YouTube video def download_video(url, title): try: yt = YouTube(url) st.write("Video Title:", title) st.write("Downloading...") stream = yt.streams.filter(progressive=True, file_extension='mp4').first() stream.download(output_path=os.path.expanduser("~\Downloads")) st.success("Download completed successfully!") except Exception as e: st.error(f"An error occurred: {e}") # Streamlit UI st.title("YouTube Video Downloader") url = st.text_input("Enter YouTube Video URL:", "") if st.button("Download"): if url.strip() == "": st.warning("Please enter a YouTube video URL.") else: yt = YouTube(url) title = yt.title download_video(url, title) if 'url' in st.session_state and st.session_state.url.strip() != "": yt = YouTube(st.session_state.url) title = yt.title if st.button("Download Video"): download_video(st.session_state.url, title)