File size: 1,919 Bytes
96144eb
d9c7ef8
76b59ce
d9c7ef8
 
 
8f9557a
d9c7ef8
8f9557a
d9c7ef8
 
8f9557a
 
 
d9c7ef8
 
f7d4277
76b59ce
 
 
f7d4277
76b59ce
 
 
 
 
8f9557a
 
76b59ce
 
 
 
 
8f9557a
76b59ce
 
 
 
 
 
 
8f9557a
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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}")