Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +24 -20
src/streamlit_app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import yt_dlp
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
st.title("📥 Multi-Platform Video Downloader")
|
|
@@ -13,28 +14,32 @@ if st.button("Download"):
|
|
| 13 |
else:
|
| 14 |
with st.spinner("Downloading video..."):
|
| 15 |
try:
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
|
| 28 |
}
|
| 29 |
-
}
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
except yt_dlp.utils.DownloadError as e:
|
| 40 |
error_msg = str(e)
|
|
@@ -42,4 +47,3 @@ if st.button("Download"):
|
|
| 42 |
st.error("⚠️ This video requires login. Only public videos can be downloaded.")
|
| 43 |
else:
|
| 44 |
st.error(f"❌ Download failed: {error_msg}")
|
| 45 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import yt_dlp
|
| 3 |
+
import tempfile
|
| 4 |
import os
|
| 5 |
|
| 6 |
st.title("📥 Multi-Platform Video Downloader")
|
|
|
|
| 14 |
else:
|
| 15 |
with st.spinner("Downloading video..."):
|
| 16 |
try:
|
| 17 |
+
# Use a temporary directory
|
| 18 |
+
with tempfile.TemporaryDirectory() as tmp_dir:
|
| 19 |
+
ydl_opts = {
|
| 20 |
+
'outtmpl': os.path.join(tmp_dir, '%(title)s.%(ext)s'),
|
| 21 |
+
'format': 'bestvideo+bestaudio/best',
|
| 22 |
+
'merge_output_format': 'mp4',
|
| 23 |
+
'noplaylist': True,
|
| 24 |
+
'quiet': True,
|
| 25 |
+
'http_headers': {
|
| 26 |
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)'
|
| 27 |
+
}
|
|
|
|
| 28 |
}
|
|
|
|
| 29 |
|
| 30 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 31 |
+
info = ydl.extract_info(url, download=True)
|
| 32 |
+
filename = ydl.prepare_filename(info)
|
| 33 |
+
|
| 34 |
+
st.success("✅ Download completed!")
|
| 35 |
|
| 36 |
+
with open(filename, 'rb') as f:
|
| 37 |
+
st.download_button(
|
| 38 |
+
label="📥 Click to Download",
|
| 39 |
+
data=f,
|
| 40 |
+
file_name=os.path.basename(filename),
|
| 41 |
+
mime="video/mp4"
|
| 42 |
+
)
|
| 43 |
|
| 44 |
except yt_dlp.utils.DownloadError as e:
|
| 45 |
error_msg = str(e)
|
|
|
|
| 47 |
st.error("⚠️ This video requires login. Only public videos can be downloaded.")
|
| 48 |
else:
|
| 49 |
st.error(f"❌ Download failed: {error_msg}")
|
|
|