Spaces:
Sleeping
Sleeping
import streamlit as st | |
import yt_dlp | |
def download_video(url): | |
try: | |
ydl_opts = { | |
'format': 'best', | |
'outtmpl': 'downloads/%(title)s.%(ext)s', | |
} | |
with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
info = ydl.extract_info(url, download=True) | |
return info.get('title', 'Video') | |
except Exception as e: | |
return str(e) | |
st.title("YouTube Video Downloader") | |
url = st.text_input("Enter the YouTube URL") | |
if st.button("Download"): | |
if url: | |
with st.spinner("Downloading..."): | |
video_title = download_video(url) | |
if "https://" in url: | |
st.success(f"Downloaded: {video_title}") | |
else: | |
st.error("Invalid URL. Please enter a valid YouTube link.") | |
else: | |
st.error("Please provide a YouTube URL.") | |