Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,23 @@
|
|
| 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'])
|
|
@@ -20,32 +33,33 @@ ydl_opts = {
|
|
| 20 |
}
|
| 21 |
|
| 22 |
if st.button("Download"):
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
| 46 |
else:
|
| 47 |
-
st.error("
|
| 48 |
-
|
| 49 |
-
st.error("
|
| 50 |
-
except Exception as e:
|
| 51 |
-
st.error(f"An error occurred: {str(e)}")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import os
|
| 3 |
import yt_dlp
|
| 4 |
+
import psutil
|
| 5 |
+
|
| 6 |
+
# Function to get system information
|
| 7 |
+
def get_system_info():
|
| 8 |
+
ram_info = psutil.virtual_memory()
|
| 9 |
+
disk_info = psutil.disk_usage('/')
|
| 10 |
+
return ram_info, disk_info
|
| 11 |
|
| 12 |
# Streamlit UI setup
|
| 13 |
st.title("YouTube Video Downloader 8K supported")
|
| 14 |
|
| 15 |
+
# Display server RAM and disk usage
|
| 16 |
+
ram_info, disk_info = get_system_info()
|
| 17 |
+
st.write("## Server Information")
|
| 18 |
+
st.write(f"**RAM Usage:** {ram_info.percent}% used ({ram_info.used // (1024 ** 2)} MB of {ram_info.total // (1024 ** 2)} MB)")
|
| 19 |
+
st.write(f"**Disk Usage:** {disk_info.percent}% used ({disk_info.used // (1024 ** 3)} GB of {disk_info.total // (1024 ** 3)} GB)")
|
| 20 |
+
|
| 21 |
# Streamlit input fields
|
| 22 |
url = st.text_input("Enter the YouTube URL:")
|
| 23 |
quality = st.selectbox("Select the desired quality:", ['4320', '2160', '1440', '1080', '720', '480'])
|
|
|
|
| 33 |
}
|
| 34 |
|
| 35 |
if st.button("Download"):
|
| 36 |
+
with st.spinner("Downloading... Please wait."):
|
| 37 |
+
try:
|
| 38 |
+
# Download the video
|
| 39 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 40 |
+
result = ydl.download([url])
|
| 41 |
+
|
| 42 |
+
# Check if download was successful
|
| 43 |
+
if result == 0:
|
| 44 |
+
# Get the actual file extension used
|
| 45 |
+
info_dict = ydl.extract_info(url, download=False)
|
| 46 |
+
extension = info_dict.get('ext', 'webm')
|
| 47 |
+
file_path = f'{save_file_name}.{extension}'
|
| 48 |
+
|
| 49 |
+
# Check if the file exists
|
| 50 |
+
if os.path.exists(file_path):
|
| 51 |
+
# Provide a download link for the file
|
| 52 |
+
with open(file_path, "rb") as file:
|
| 53 |
+
st.download_button(
|
| 54 |
+
label="Download video",
|
| 55 |
+
data=file,
|
| 56 |
+
file_name=f"{save_file_name}.{extension}",
|
| 57 |
+
mime=f"video/{extension}"
|
| 58 |
+
)
|
| 59 |
+
st.success('Your video is ready for download.')
|
| 60 |
+
else:
|
| 61 |
+
st.error("File not found. Please make sure the download was successful.")
|
| 62 |
else:
|
| 63 |
+
st.error("Download failed. Please check the URL and try again.")
|
| 64 |
+
except Exception as e:
|
| 65 |
+
st.error(f"An error occurred: {str(e)}")
|
|
|
|
|
|