import gradio as gr import subprocess import requests import os import re from pathlib import Path import gdown def download_from_gdrive(url): """Download file from Google Drive""" try: # Extract file ID from various Google Drive URL formats file_id = None if 'drive.google.com' in url: if '/file/d/' in url: file_id = url.split('/file/d/')[1].split('/')[0] elif 'id=' in url: file_id = url.split('id=')[1].split('&')[0] if file_id: output = 'input_video.mp4' gdown.download(f'https://drive.google.com/uc?id={file_id}', output, quiet=False) return output else: return None except Exception as e: print(f"Error downloading from Google Drive: {e}") return None def download_video(url): """Download video from direct URL or Google Drive""" try: # Check if it's a Google Drive link if 'drive.google.com' in url: return download_from_gdrive(url) # Direct download response = requests.get(url, stream=True) response.raise_for_status() output_path = 'input_video.mp4' with open(output_path, 'wb') as f: for chunk in response.iter_content(chunk_size=8192): f.write(chunk) return output_path except Exception as e: return f"Error downloading video: {str(e)}" def burn_subtitles(video_path, subtitle_file): """Burn subtitles into video using FFmpeg""" try: output_path = 'output_with_subs.mp4' # Save subtitle file subtitle_path = 'subtitles.srt' with open(subtitle_path, 'w', encoding='utf-8') as f: f.write(subtitle_file) # FFmpeg command to burn subtitles cmd = [ 'ffmpeg', '-i', video_path, '-vf', f"subtitles={subtitle_path}:force_style='FontSize=24,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,Outline=2'", '-c:a', 'copy', '-y', output_path ] subprocess.run(cmd, check=True, capture_output=True) return output_path except subprocess.CalledProcessError as e: return f"Error burning subtitles: {e.stderr.decode()}" except Exception as e: return f"Error: {str(e)}" def upload_to_abyss(file_path): """Upload file to abyss.to (hydrax.net)""" try: url = 'http://up.hydrax.net/af3a445e1825a2b8256fc918c6087381' file_name = os.path.basename(file_path) file_type = 'video/mp4' with open(file_path, 'rb') as f: files = {'file': (file_name, f, file_type)} response = requests.post(url, files=files, timeout=300) return response.text except Exception as e: return f"Error uploading to abyss.to: {str(e)}" def process_video(video_url, subtitle_content, progress=gr.Progress()): """Main processing function""" try: progress(0.1, desc="Downloading video...") video_path = download_video(video_url) if isinstance(video_path, str) and video_path.startswith("Error"): return video_path, None if not os.path.exists(video_path): return "Error: Video download failed", None progress(0.4, desc="Burning subtitles...") output_path = burn_subtitles(video_path, subtitle_content) if isinstance(output_path, str) and output_path.startswith("Error"): return output_path, None progress(0.7, desc="Uploading to abyss.to...") upload_response = upload_to_abyss(output_path) progress(1.0, desc="Complete!") # Cleanup if os.path.exists(video_path): os.remove(video_path) if os.path.exists('subtitles.srt'): os.remove('subtitles.srt') return f"✅ Upload successful!\n\nResponse from abyss.to:\n{upload_response}", output_path except Exception as e: return f"Error: {str(e)}", None # Gradio Interface with gr.Blocks(title="Subtitle Burner & Uploader", theme=gr.themes.Soft()) as app: gr.Markdown(""" # 🎬 Video Subtitle Burner & Uploader Upload a video (via link) and subtitle file, burn subtitles into the video, and upload to abyss.to """) with gr.Row(): with gr.Column(): video_url = gr.Textbox( label="Video URL", placeholder="Enter Google Drive link or direct video URL", lines=2 ) subtitle_file = gr.Textbox( label="Subtitle Content (.srt)", placeholder="Paste your SRT subtitle content here...", lines=10 ) process_btn = gr.Button("🚀 Process & Upload", variant="primary", size="lg") with gr.Column(): status_output = gr.Textbox( label="Status", lines=10, interactive=False ) video_output = gr.Video( label="Preview (with subtitles)", interactive=False ) gr.Markdown(""" ### 📝 Instructions: 1. **Video URL**: Paste a Google Drive share link or direct video URL 2. **Subtitle Content**: Paste the contents of your .srt subtitle file 3. Click **Process & Upload** and wait 4. The video with burned subtitles will be uploaded to abyss.to ### 🔗 Supported formats: - Google Drive: `https://drive.google.com/file/d/FILE_ID/view` - Direct links: Any direct .mp4 URL - Subtitles: Standard SRT format """) process_btn.click( fn=process_video, inputs=[video_url, subtitle_file], outputs=[status_output, video_output] ) if __name__ == "__main__": app.launch()