File size: 6,040 Bytes
ebaa914
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
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()