Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899import gradio as grimport yt_dlpimport osimport shutildef download_playlist(playlist_url, format_choice, progress=gr.Progress(track_tqdm=True)):if not playlist_url.strip():return "❌ Please enter a valid YouTube URL."# Unique download folder name to avoid conflictsdownload_dir = "youtube_downloads"# Clean up previous downloads if they existif os.path.exists(download_dir):shutil.rmtree(download_dir)os.makedirs(download_dir, exist_ok=True)# Base configuration for yt-dlpydl_opts = {'outtmpl': f'{download_dir}/%(title)s.%(ext)s','ignoreerrors': True, # Skips unavailable videos'quiet': True,}# Match quality choiceif format_choice == "Best Video Quality (Up to 4K)":ydl_opts['format'] = 'bestvideo+bestaudio/best'ydl_opts['merge_output_format'] = 'mkv'elif format_choice == "Standard Video Quality (Up to 1080p)":ydl_opts['format'] = 'bestvideo[height<=1080]+bestaudio/best'ydl_opts['merge_output_format'] = 'mp4'else: # MP3ydl_opts['format'] = 'bestaudio/best'ydl_opts['postprocessors'] = [{'key': 'FFmpegExtractAudio','preferredcodec': 'mp3','preferredquality': '192',}]try:# Download files to the serverwith yt_dlp.YoutubeDL(ydl_opts) as ydl:ydl.download([playlist_url])# Check if anything actually downloadeddownloaded_files = os.listdir(download_dir)if not downloaded_files:return "❌ No videos were downloaded. Make sure the playlist is public and the URL is correct."# Zip the folder so the user can download everything at oncezip_archive_path = "playlist_download"shutil.make_archive(zip_archive_path, 'zip', download_dir)final_zip_file = f"{zip_archive_path}.zip"# Clean up the raw directory to save server spaceshutil.rmtree(download_dir)return final_zip_fileexcept Exception as e:return f"❌ An error occurred: {str(e)}"# Define the Gradio Web Interfacewith gr.Blocks(theme=gr.themes.Soft()) as demo:gr.Markdown("# 🎬 YouTube Playlist Downloader (4K & MP3) 🎵")gr.Markdown("Enter a YouTube playlist link, select your desired quality, and get a single `.zip` file with all your contents.")with gr.Row():url_input = gr.Textbox(label="YouTube Playlist / Video URL",placeholder="https://www.youtube.com/playlist?list=...",lines=1)with gr.Row():quality_input = gr.Radio(choices=["Best Video Quality (Up to 4K)","Standard Video Quality (Up to 1080p)","Audio Only (MP3)"],label="Select Quality / Format",value="Standard Video Quality (Up to 1080p)")download_btn = gr.Button("🚀 Fetch & Download All", variant="primary")# File output box to host the generated .zip filefile_output = gr.File(label="📥 Download Your Zip File Here")# Link button to actiondownload_btn.click(fn=download_playlist,inputs=[url_input, quality_input],outputs=file_output)# Launch the appdemo.launch()1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import gradio as grimport base64from cryptography.hazmat.primitives import hashesfrom cryptography.hazmat.primitives.asymmetric import ecfrom cryptography.hazmat.primitives import serialization# === अपनी जेनरेट की गई PRIVATE KEY यहाँ डालें ===# ध्यान दें: इसे वैसा ही रहने दें जैसा चरण 1 में मिला थाPRIVATE_KEY_PEM = b"""-----BEGIN PRIVATE KEY-----यहाँ_अपनी_असली_PRIVATE_KEY_पेस्ट_करें-----END PRIVATE KEY-----"""def generate_key(device_id, app_version):try:# 1. Private Key लोड करेंprivate_key = serialization.load_pem_private_key(PRIVATE_KEY_PEM, password=None)# 2. वर्ज़न स्ट्रिंग को बाइट्स में बदलेंversion_bytes = app_version.encode('utf-8')version_len = len(version_bytes)# 3. पहले 2 बाइट्स में वर्ज़न की लंबाई सेट करेंlength_bytes = version_len.to_bytes(2, byteorder='big')# 4. पेलोड बनाएँ (Version Bytes + Device ID Bytes)device_id_bytes = device_id.strip().encode('utf-8')payload = version_bytes + device_id_bytes# 5. पेलोड को साइन करेंsignature = private_key.sign(payload,ec.ECDSA(hashes.SHA256()))# 6. कस्टम स्ट्रक्चर: [Length] + [Version] + [Signature]final_key_bytes = length_bytes + version_bytes + signature# 7. URL-Safe Base64 एन्कोडिंगactivation_key = base64.urlsafe_b64encode(final_key_bytes).decode('utf-8').rstrip('=')return f"✅ सफलता! आपकी Activation Key है:\n\n{activation_key}"except Exception as e:return f"❌ Error: {str(e)}\nक्या आपने अपनी असली Private Key सही से पेस्ट की है?"# === Gradio UI (वेब इंटरफ़ेस) ===with gr.Blocks(title="App Key Generator") as interface:gr.Markdown("## 🔐 Pocket FM Access - Key Generator")gr.Markdown("उपयोगकर्ता की Device ID दर्ज करें और उनके लिए Activation Key बनाएँ।")with gr.Row():device_id_input = gr.Textbox(label="Device ID (उदा: 6B72-157B-F5A9-7197)", placeholder="यहाँ Device ID डालें...")version_input = gr.Textbox(label="App Version (Prefix)", value="1.0")generate_btn = gr.Button("🔑 Generate Activation Key", variant="primary")output_text = gr.Textbox(label="Result", lines=4)generate_btn.click(fn=generate_key,inputs=[device_id_input, version_input],outputs=output_text)if __name__ == "__main__":interface.launch()
app.py+53-87