Spaces:
Running
Running
| import streamlit as st | |
| import os | |
| import yt_dlp | |
| import psutil | |
| # Custom CSS with improved styling | |
| st.markdown( | |
| """ | |
| <style> | |
| @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;700&display=swap'); | |
| /* Global styles */ | |
| * { | |
| font-family: 'Poppins', sans-serif !important; | |
| } | |
| /* Custom container styling */ | |
| .custom-container { | |
| background-color: #ffffff; | |
| padding: 2rem; | |
| border-radius: 1rem; | |
| box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | |
| margin-bottom: 2rem; | |
| } | |
| /* Stats container */ | |
| .stats-container { | |
| background-color: #f8f9fa; | |
| padding: 1.5rem; | |
| border-radius: 0.75rem; | |
| margin-top: 2rem; | |
| } | |
| /* Title styling */ | |
| .main-title { | |
| color: #1e3a8a; | |
| font-size: 2.5rem; | |
| font-weight: 700; | |
| text-align: center; | |
| margin-bottom: 2rem; | |
| } | |
| /* Section headers */ | |
| .section-header { | |
| color: #2563eb; | |
| font-size: 1.5rem; | |
| font-weight: 600; | |
| margin-bottom: 1rem; | |
| } | |
| /* Footer styling */ | |
| .footer { | |
| text-align: center; | |
| padding: 1rem; | |
| color: #6b7280; | |
| font-size: 0.875rem; | |
| margin-top: 2rem; | |
| } | |
| /* Progress bar styling */ | |
| .stProgress > div > div > div { | |
| background-color: #2563eb; | |
| } | |
| </style> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| # Function to get disk usage information | |
| def get_disk_info(): | |
| disk_info = psutil.disk_usage('/') | |
| return disk_info | |
| # Main title with custom styling | |
| st.markdown('<h1 class="main-title">๐ฅ YouTube Downloader</h1>', unsafe_allow_html=True) | |
| # Download section in a custom container | |
| st.markdown('<div class="custom-container">', unsafe_allow_html=True) | |
| st.markdown('<h2 class="section-header">Download Video</h2>', unsafe_allow_html=True) | |
| # Input fields with better organization | |
| url = st.text_input("๐ YouTube URL", placeholder="Paste your YouTube video URL here...") | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| quality = st.selectbox( | |
| "๐ฎ Video Quality", | |
| ['4320p (8K)', '2160p (4K)', '1440p (2K)', '1080p (FHD)', '720p (HD)', '480p (SD)'], | |
| format_func=lambda x: x | |
| ) | |
| with col2: | |
| save_file_name = st.text_input("๐ File Name", placeholder="Enter file name (without extension)") | |
| # Convert quality selection to numerical value | |
| quality_map = { | |
| '4320p (8K)': '4320', | |
| '2160p (4K)': '2160', | |
| '1440p (2K)': '1440', | |
| '1080p (FHD)': '1080', | |
| '720p (HD)': '720', | |
| '480p (SD)': '480' | |
| } | |
| quality_value = quality_map[quality] | |
| # Configuration and download logic | |
| cookies_path = os.path.join(os.getcwd(), "cookies.txt") | |
| quality_format = f"bestvideo[height<={quality_value}]+bestaudio/best[height<={quality_value}]" | |
| ydl_opts = { | |
| 'format': quality_format, | |
| 'outtmpl': f'{save_file_name}.%(ext)s', | |
| 'cookiefile': cookies_path, | |
| } | |
| # Download button with progress tracking | |
| if st.button("โฌ๏ธ Download Video", type="primary"): | |
| with st.spinner("๐ Processing your download..."): | |
| try: | |
| with yt_dlp.YoutubeDL(ydl_opts) as ydl: | |
| result = ydl.download([url]) | |
| if result == 0: | |
| info_dict = ydl.extract_info(url, download=False) | |
| extension = info_dict.get('ext', 'webm') | |
| file_path = f'{save_file_name}.{extension}' | |
| if os.path.exists(file_path): | |
| st.success('โ Video downloaded successfully!') | |
| with open(file_path, "rb") as file: | |
| st.download_button( | |
| label="๐ฅ Save Video", | |
| data=file, | |
| file_name=f"{save_file_name}.{extension}", | |
| mime=f"video/{extension}", | |
| key="download_button" | |
| ) | |
| else: | |
| st.error("โ File not found. Please try again.") | |
| else: | |
| st.error("โ Download failed. Please check the URL and try again.") | |
| except Exception as e: | |
| st.error(f"โ Error: {str(e)}") | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| # Server stats in a custom container | |
| st.markdown('<div class="stats-container">', unsafe_allow_html=True) | |
| st.markdown('<h2 class="section-header">๐ Server Statistics</h2>', unsafe_allow_html=True) | |
| # Display disk usage with progress bar | |
| disk_info = get_disk_info() | |
| disk_used_gb = disk_info.used / (1024 ** 3) | |
| disk_total_gb = disk_info.total / (1024 ** 3) | |
| st.progress(disk_info.percent / 100) | |
| st.markdown(f"**๐พ Disk Usage:** {disk_info.percent}% used ({disk_used_gb:.2f} GB of {disk_total_gb:.2f} GB)") | |
| # Server specs in columns | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.markdown("**๐ฅ๏ธ Hardware Specs**") | |
| st.markdown("- RAM: 124 GB") | |
| st.markdown("- CPU: Intel Xeon 64-core 2.00 GHz") | |
| with col2: | |
| st.markdown("**๐ฝ Storage**") | |
| st.markdown("- Disk 1: 2.4 TB") | |
| st.markdown("- Disk 2: 1.7 TB") | |
| st.markdown(f"**๐ Location:** Paris, France") | |
| st.markdown('</div>', unsafe_allow_html=True) | |
| # Footer | |
| st.markdown( | |
| '<div class="footer">ยฉ 2024 SlimShadow. All Rights Reserved.</div>', | |
| unsafe_allow_html=True | |
| ) |