Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,42 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import yt_dlp
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
'listformats': True,
|
| 8 |
-
}
|
| 9 |
-
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 10 |
-
info_dict = ydl.extract_info(url, download=False)
|
| 11 |
-
formats = info_dict.get('formats', [])
|
| 12 |
-
return formats
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
return 'downloaded_video.mp4' # Assuming MP4 format for simplicity
|
| 22 |
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
if
|
| 28 |
-
if
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
downloaded_file = download_video(url, format_id=selected_format_id)
|
| 39 |
-
st.success("Download complete!")
|
| 40 |
-
|
| 41 |
-
with open(downloaded_file, 'rb') as file:
|
| 42 |
-
btn = st.download_button(
|
| 43 |
-
label="Download Video",
|
| 44 |
-
data=file,
|
| 45 |
-
file_name=downloaded_file,
|
| 46 |
-
mime='video/mp4'
|
| 47 |
-
)
|
| 48 |
else:
|
| 49 |
-
st.
|
| 50 |
-
if st.button("Download"):
|
| 51 |
-
st.write("Downloading...")
|
| 52 |
-
downloaded_file = download_video(url)
|
| 53 |
-
st.success("Download complete!")
|
| 54 |
-
|
| 55 |
-
with open(downloaded_file, 'rb') as file:
|
| 56 |
-
btn = st.download_button(
|
| 57 |
-
label="Download Video",
|
| 58 |
-
data=file,
|
| 59 |
-
file_name=downloaded_file,
|
| 60 |
-
mime='video/mp4'
|
| 61 |
-
)
|
|
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import os
|
| 3 |
+
import yt_dlp
|
| 4 |
|
| 5 |
+
# Streamlit UI setup
|
| 6 |
+
st.title("YouTube Video Downloader 8K supported")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
# Streamlit input fields
|
| 9 |
+
url = st.text_input("Enter the YouTube URL:")
|
| 10 |
+
quality = st.selectbox("Select the desired quality:", ['4320', '2160', '1440', '1080', '720', '480'])
|
| 11 |
+
save_file_name = st.text_input("Enter the save file name (without extension):")
|
| 12 |
+
|
| 13 |
+
# Convert quality to the appropriate format string for yt-dlp
|
| 14 |
+
quality_format = f"bestvideo[height<={quality}]+bestaudio/best[height<={quality}]"
|
|
|
|
| 15 |
|
| 16 |
+
# Define download options based on user input
|
| 17 |
+
ydl_opts = {
|
| 18 |
+
'format': quality_format, # Download the specified quality
|
| 19 |
+
'outtmpl': f'{save_file_name}.%(ext)s', # Save the video with the specified name
|
| 20 |
+
}
|
| 21 |
|
| 22 |
+
if st.button("Download"):
|
| 23 |
+
# Download the video
|
| 24 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 25 |
+
ydl.download([url])
|
| 26 |
+
|
| 27 |
+
# Path to the downloaded video file
|
| 28 |
+
file_path = f'{save_file_name}.webm'
|
| 29 |
|
| 30 |
+
# Check if the file exists
|
| 31 |
+
if os.path.exists(file_path):
|
| 32 |
+
# Provide a download link for the file
|
| 33 |
+
with open(file_path, "rb") as file:
|
| 34 |
+
btn = st.download_button(
|
| 35 |
+
label="Download video",
|
| 36 |
+
data=file,
|
| 37 |
+
file_name=f"{save_file_name}.webm",
|
| 38 |
+
mime="video/webm"
|
| 39 |
+
)
|
| 40 |
+
st.success('Your video is ready for download.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
else:
|
| 42 |
+
st.error("File not found. Please make sure the download was successful.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|