slimshadow commited on
Commit
68df142
·
verified ·
1 Parent(s): 61b8812

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -28
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
- try:
24
- # Download the video
25
- with yt_dlp.YoutubeDL(ydl_opts) as ydl:
26
- result = ydl.download([url])
27
-
28
- # Check if download was successful
29
- if result == 0:
30
- # Get the actual file extension used
31
- info_dict = ydl.extract_info(url, download=False)
32
- extension = info_dict.get('ext', 'webm')
33
- file_path = f'{save_file_name}.{extension}'
34
-
35
- # Check if the file exists
36
- if os.path.exists(file_path):
37
- # Provide a download link for the file
38
- with open(file_path, "rb") as file:
39
- st.download_button(
40
- label="Download video",
41
- data=file,
42
- file_name=f"{save_file_name}.{extension}",
43
- mime=f"video/{extension}"
44
- )
45
- st.success('Your video is ready for download.')
 
 
 
46
  else:
47
- st.error("File not found. Please make sure the download was successful.")
48
- else:
49
- st.error("Download failed. Please check the URL and try again.")
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)}")