Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import yt_dlp | |
| import tempfile | |
| import os | |
| st.title("π₯ Multi-Platform Video Downloader") | |
| st.write("Download public videos from YouTube, Instagram, Facebook, TikTok, and X (Twitter).") | |
| url = st.text_input("Paste video URL here") | |
| if st.button("Download"): | |
| if not url: | |
| st.warning("Please paste a video URL.") | |
| else: | |
| with st.spinner("Downloading video..."): | |
| try: | |
| # Use a temp folder | |
| with tempfile.TemporaryDirectory() as tmp_dir: | |
| ydl_opts = { | |
| 'outtmpl': os.path.join(tmp_dir, '%(title)s.%(ext)s'), | |
| 'format': 'mp4/best[ext=mp4]/best', # avoid separate audio/video streams | |
| 'noplaylist': True, | |
| 'quiet': True, | |
| 'http_headers': { | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' | |
| } | |
| } | |
| with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
| info = ydl.extract_info(url, download=True) | |
| filename = ydl.prepare_filename(info) | |
| st.success("β Download completed!") | |
| with open(filename, 'rb') as f: | |
| st.download_button( | |
| label="π₯ Click to Download", | |
| data=f, | |
| file_name=os.path.basename(filename), | |
| mime="video/mp4" | |
| ) | |
| except yt_dlp.utils.DownloadError as e: | |
| error_msg = str(e) | |
| if "login" in error_msg.lower() or "403" in error_msg: | |
| st.error("β οΈ This video requires login. Only public videos can be downloaded.") | |
| else: | |
| st.error(f"β Download failed: {error_msg}") | |