File size: 22,860 Bytes
586f783
2b158ec
6d7bfa0
 
64af3b9
88721d0
 
6d7bfa0
 
 
2b158ec
6d7bfa0
 
 
 
2b158ec
cff545e
2b158ec
b61b351
 
2b158ec
8025976
5ad161e
2b158ec
b61b351
 
 
8025976
2b158ec
 
8025976
46a986e
8025976
64af3b9
8025976
 
2b158ec
46a986e
5ad161e
8025976
 
 
8ea5abe
8025976
64af3b9
b61b351
 
8ea5abe
2b158ec
 
 
 
 
 
46a986e
8ea5abe
8025976
2b158ec
260c561
2b158ec
 
 
 
46a986e
 
260c561
8025976
 
 
 
 
 
 
 
 
 
8ea5abe
8025976
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b158ec
46a986e
8ea5abe
b61b351
46a986e
8025976
46a986e
 
2b158ec
 
 
8025976
b61b351
2b158ec
 
 
 
 
 
 
8025976
2b158ec
 
8ea5abe
b61b351
 
2b158ec
 
8ea5abe
8025976
2b158ec
 
75193ce
2b158ec
 
8025976
8ea5abe
2b158ec
 
 
b61b351
2b158ec
 
 
b61b351
46a986e
2b158ec
46a986e
 
 
8ea5abe
2b158ec
 
 
46a986e
2b158ec
 
 
b61b351
88721d0
45850d7
 
46a986e
45850d7
46a986e
 
 
88721d0
46a986e
88721d0
45850d7
46a986e
64af3b9
 
 
 
 
77a91cf
 
 
 
 
 
 
 
 
 
 
 
88721d0
 
 
 
 
 
 
 
 
8dfc205
88721d0
 
8dfc205
88721d0
 
8dfc205
0128340
88721d0
8dfc205
 
a5abb63
 
 
 
 
88721d0
 
 
 
 
 
a5abb63
88721d0
 
 
8dfc205
88721d0
 
 
8dfc205
 
 
 
 
 
 
 
0128340
8dfc205
a5abb63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b61b351
6d7bfa0
 
2b158ec
cff545e
46a986e
77a91cf
 
 
ee024c0
77a91cf
2b158ec
8ea5abe
 
2b158ec
 
8ea5abe
64af3b9
77a91cf
64af3b9
2b158ec
 
88721d0
 
 
 
e811cd8
8dfc205
a5abb63
88721d0
 
 
b61b351
8ea5abe
2b158ec
46a986e
2b158ec
 
46a986e
77a91cf
88721d0
 
 
8ea5abe
f629f5b
 
77a91cf
46a986e
 
f629f5b
 
2b158ec
 
 
77a91cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88721d0
 
 
 
 
 
 
 
 
 
77a91cf
f629f5b
 
 
77a91cf
 
 
 
 
8ea5abe
 
2b158ec
 
46a986e
8ea5abe
 
 
f629f5b
8ea5abe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2b158ec
260c561
 
8ea5abe
260c561
 
 
 
8ea5abe
260c561
 
 
2b158ec
260c561
b61b351
f629f5b
8ea5abe
 
260c561
 
 
f629f5b
8ea5abe
 
260c561
 
2b158ec
 
a5abb63
8025976
 
 
8ea5abe
 
f629f5b
8025976
 
0128340
8ea5abe
 
 
 
 
 
 
 
 
 
 
45850d7
3a4993c
eb6a910
8ea5abe
 
 
 
 
 
88721d0
a5abb63
88721d0
 
45850d7
88721d0
 
 
 
 
 
8ea5abe
 
88721d0
 
8dfc205
88721d0
 
 
 
 
 
 
 
 
8ea5abe
b61b351
6d7bfa0
 
2b158ec
6d7bfa0
 
 
 
 
 
 
 
75193ce
6d7bfa0
 
 
2b158ec
6d7bfa0
2b158ec
6d7bfa0
2b158ec
6d7bfa0
 
 
 
2b158ec
6d7bfa0
 
 
2b158ec
75193ce
6d7bfa0
 
 
 
 
 
 
3a4993c
6d7bfa0
 
3a4993c
 
6d7bfa0
2b158ec
 
eb6a910
6d7bfa0
 
2b158ec
6d7bfa0
2b158ec
6d7bfa0
88721d0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d7bfa0
3a4993c
 
6d7bfa0
 
 
3a4993c
 
 
6d7bfa0
 
 
3a4993c
 
6d7bfa0
 
 
 
2b158ec
6d7bfa0
 
 
 
 
 
 
 
08884d2
6d7bfa0
 
 
3a4993c
 
 
6d7bfa0
 
3a4993c
 
6d7bfa0
 
 
3a4993c
 
 
6d7bfa0
 
 
 
 
 
 
 
 
 
3a4993c
6d7bfa0
88721d0
e3e8a5d
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
from fastapi import FastAPI, File, UploadFile, Request
from fastapi.responses import HTMLResponse, JSONResponse, StreamingResponse
import requests
import time
from typing import Dict
import urllib.parse
import re

app = FastAPI()

HTML_CONTENT = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Radd PRO Uploader</title>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Poppins', sans-serif;
            background: #121212;
            height: 100vh;
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            color: #e0e0e0;
        }
        .container {
            background: rgba(255, 255, 255, 0.1);
            padding: 2.5rem;
            border-radius: 15px;
            box-shadow: 0 0 20px rgba(255, 255, 255, 0.2);
            backdrop-filter: blur(4px);
            border: 1px solid rgba(255, 255, 255, 0.18);
            text-align: center;
            max-width: 450px;
            width: 100%;
            transition: all 0.3s ease;
        }
        .container:hover {
            background: rgba(255, 255, 255, 0.2);
            transform: translateY(-5px);
            box-shadow: 0 0 30px rgba(255, 255, 255, 0.3);
        }
        h1 {
            color: #ffffff;
            margin-bottom: 1.5rem;
            font-weight: 600;
        }
        .file-input {
            display: none;
        }
        .btn {
            background-color: #ffffff;
            color: #121212;
            padding: 12px 24px;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s ease;
            display: inline-block;
            font-weight: 600;
            border: none;
            font-size: 1rem;
            margin: 0.5rem;
            position: relative;
            overflow: hidden;
        }
        .btn::after {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 5px;
            height: 5px;
            background: rgba(0, 0, 0, 0.3);
            opacity: 0;
            border-radius: 100%;
            transform: scale(1, 1) translate(-50%);
            transform-origin: 50% 50%;
        }
        @keyframes ripple {
            0% {
                transform: scale(0, 0);
                opacity: 1;
            }
            20% {
                transform: scale(25, 25);
                opacity: 1;
            }
            100% {
                opacity: 0;
                transform: scale(40, 40);
            }
        }
        .btn:focus:not(:active)::after {
            animation: ripple 1s ease-out;
        }
        .btn:hover {
            background-color: #f0f0f0;
        }
        .btn:disabled {
            background-color: #555;
            cursor: not-allowed;
        }
        .file-name {
            margin-top: 1rem;
            font-size: 0.9rem;
            color: #aaa;
        }
        .progress-container {
            margin-top: 1.5rem;
            display: none;
        }
        .progress-bar {
            width: 100%;
            height: 10px;
            background-color: #333;
            border-radius: 5px;
            overflow: hidden;
            margin-bottom: 10px;
        }
        .progress {
            width: 0%;
            height: 100%;
            background-color: #ffffff;
            transition: width 0.3s ease;
        }
        .loading-spinner {
            display: none;
            width: 40px;
            height: 40px;
            border: 4px solid #333;
            border-top: 4px solid #ffffff;
            border-radius: 50%;
            animation: spin 1s linear infinite;
            margin: 20px auto;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        .result-container {
            display: none;
            margin-top: 1.5rem;
        }
        .result-link {
            color: #ffffff;
            text-decoration: none;
            font-weight: 600;
            transition: all 0.3s ease;
            margin-right: 10px;
        }
        .result-link:hover {
            text-decoration: underline;
        }
        .copy-btn, .embed-btn {
            background-color: #333;
            color: #e0e0e0;
            border: none;
            padding: 5px 10px;
            border-radius: 5px;
            cursor: pointer;
            transition: all 0.3s ease;
            margin-right: 5px;
        }
        .copy-btn:hover, .embed-btn:hover {
            background-color: #444;
        }
        .file-types {
            margin-top: 2rem;
            font-size: 0.8rem;
            color: #aaa;
        }
        .drop-zone {
            border: 2px dashed #aaa;
            border-radius: 10px;
            padding: 20px;
            text-align: center;
            cursor: pointer;
            transition: all 0.3s ease;
        }
        .drop-zone:hover, .drop-zone.drag-over {
            border-color: #ffffff;
            background-color: rgba(255, 255, 255, 0.1);
        }
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0,0,0,0.8);
        }
        .modal-content {
            background-color: #1e1e1e;
            margin: 15% auto;
            padding: 20px;
            border: 1px solid #333;
            width: 80%;
            max-width: 600px;
            border-radius: 10px;
            color: #e0e0e0;
            animation: modalFadeIn 0.3s;
        }
        @keyframes modalFadeIn {
            from {opacity: 0; transform: scale(0.8);}
            to {opacity: 1; transform: scale(1);}
        }
        .close {
            color: #aaa;
            float: right;
            font-size: 28px;
            font-weight: bold;
            transition: color 0.3s ease;
        }
        .close:hover,
        .close:focus {
            color: #fff;
            text-decoration: none;
            cursor: pointer;
        }
        #embedLink {
            width: 100%;
            padding: 10px;
            margin-top: 10px;
            background-color: #333;
            border: 1px solid #555;
            color: #e0e0e0;
            border-radius: 5px;
            text-align: center;
        }
        .embed-btn {
            position: relative;
            overflow: hidden;
        }
        .embed-btn::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0) 70%);
            transform: scale(0);
            transition: transform 0.3s ease-out;
        }
        .embed-btn:hover::before {
            transform: scale(1);
        }
        .copy-embed-btn {
            background-color: #4CAF50;
            color: white;
            border: none;
            padding: 10px 20px;
            text-align: center;
            text-decoration: none;
            display: inline-block;
            font-size: 16px;
            margin: 4px 2px;
            transition-duration: 0.4s;
            cursor: pointer;
            border-radius: 25px;
        }
        .copy-embed-btn:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Radd PRO Uploader</h1>
        <form id="uploadForm">
            <div id="dropZone" class="drop-zone">
                <input type="file" name="files" id="files" class="file-input" accept=".zip,.mp4,.txt,.mp3,image/*,.pdf" required multiple>
                <label for="files" class="btn">Choose Files</label>
                <p>or drag and drop files here/paste images</p>
            </div>
            <div class="file-name" id="fileName"></div>
            <button type="button" id="uploadBtn" class="btn" style="display: none; margin-top: 1rem;">Upload Files</button>
            <div class="progress-container" id="progressContainer"></div>
            <div class="loading-spinner" id="loadingSpinner"></div>
        </form>
        <div class="result-container" id="resultContainer"></div>
        <div class="file-types">
            Allowed file types: .zip, .mp4, .txt, .mp3, all image types, .pdf
        </div>
    </div>

    <div id="embedModal" class="modal">
        <div class="modal-content">
            <span class="close">&times;</span>
            <h2>Embed Video Link</h2>
            <p>Copy the following link to embed the video:</p>
            <input type="text" id="embedLink" readonly>
            <button onclick="copyEmbedLink()" class="copy-embed-btn">Copy Embed Link</button>
        </div>
    </div>

    <script>
        const fileInput = document.getElementById('files');
        const fileName = document.getElementById('fileName');
        const uploadBtn = document.getElementById('uploadBtn');
        const progressContainer = document.getElementById('progressContainer');
        const loadingSpinner = document.getElementById('loadingSpinner');
        const resultContainer = document.getElementById('resultContainer');
        const dropZone = document.getElementById('dropZone');
        const modal = document.getElementById('embedModal');
        const span = document.getElementsByClassName("close")[0];
        const embedLinkInput = document.getElementById('embedLink');

        let selectedFiles = [];

        fileInput.addEventListener('change', handleFiles);

        uploadBtn.addEventListener('click', () => {
            if (selectedFiles.length > 0) {
                uploadFiles(selectedFiles);
            }
        });

        dropZone.addEventListener('dragover', (e) => {
            e.preventDefault();
            dropZone.classList.add('drag-over');
        });

        dropZone.addEventListener('dragleave', () => {
            dropZone.classList.remove('drag-over');
        });

        dropZone.addEventListener('drop', (e) => {
            e.preventDefault();
            dropZone.classList.remove('drag-over');
            handleFiles({ target: { files: e.dataTransfer.files } });
        });

        document.addEventListener('paste', (e) => {
            const items = e.clipboardData.items;
            const files = [];
            for (let i = 0; i < items.length; i++) {
                if (items[i].kind === 'file') {
                    const file = items[i].getAsFile();
                    files.push(file);
                }
            }
            if (files.length > 0) {
                handleFiles({ target: { files: files } });
            }
        });

        span.onclick = function() {
            modal.style.display = "none";
        }

        window.onclick = function(event) {
            if (event.target == modal) {
                modal.style.display = "none";
            }
        }

        function handleFiles(e) {
            selectedFiles = Array.from(e.target.files);
            if (selectedFiles.length > 0) {
                const fileNames = selectedFiles.map(file => file.name).join(', ');
                fileName.textContent = fileNames;
                uploadBtn.style.display = 'inline-block';
            }
        }

        function uploadFiles(files) {
            progressContainer.innerHTML = '';
            progressContainer.style.display = 'block';
            loadingSpinner.style.display = 'block';
            uploadBtn.disabled = true;
            resultContainer.innerHTML = '';
            resultContainer.style.display = 'none';

            files.forEach((file, index) => {
                const progressBar = createProgressBar(file.name);
                progressContainer.appendChild(progressBar);
                uploadFile(file, progressBar, index);
            });
        }

        function createProgressBar(fileName) {
            const progressBarContainer = document.createElement('div');
            progressBarContainer.className = 'progress-bar';
            const progress = document.createElement('div');
            progress.className = 'progress';
            progressBarContainer.appendChild(progress);
            const label = document.createElement('div');
            label.textContent = fileName;
            label.style.fontSize = '0.8rem';
            label.style.marginBottom = '5px';
            const container = document.createElement('div');
            container.appendChild(label);
            container.appendChild(progressBarContainer);
            return container;
        }

        function uploadFile(file, progressBarContainer, index) {
            const formData = new FormData();
            formData.append('file', file);

            const xhr = new XMLHttpRequest();
            xhr.open('POST', '/upload', true);
            xhr.upload.onprogress = (event) => updateProgress(event, progressBarContainer.querySelector('.progress'));
            xhr.onload = function() {
                if (xhr.status === 200) {
                    const response = JSON.parse(xhr.responseText);
                    if (response.url) {
                        addResultLink(response.url, file.name);
                    } else {
                        alert('Upload failed: ' + response.error);
                    }
                } else {
                    alert('Upload failed: ' + xhr.statusText);
                }
                if (index === selectedFiles.length - 1) {
                    resetUploadState();
                }
            };
            xhr.onerror = function() {
                alert('Upload failed: Network error');
                if (index === selectedFiles.length - 1) {
                    resetUploadState();
                }
            };
            xhr.send(formData);
        }

                function resetUploadState() {
            fileInput.value = '';
            fileName.textContent = '';
            uploadBtn.style.display = 'none';
            uploadBtn.disabled = false;
            loadingSpinner.style.display = 'none';
            selectedFiles = [];
        }

        function addResultLink(url, fileName) {
            const linkContainer = document.createElement('div');
            linkContainer.style.marginBottom = '10px';
            
            const link = document.createElement('a');
            link.href = url;
            link.textContent = `View ${fileName}`;
            link.className = 'result-link';
            link.target = '_blank';
            
            const copyBtn = document.createElement('button');
            copyBtn.textContent = 'Copy Link';
            copyBtn.className = 'copy-btn';
            copyBtn.onclick = () => {
                navigator.clipboard.writeText(window.location.origin + url).then(() => {
                    alert('Link copied to clipboard!');
                });
            };
            
            linkContainer.appendChild(link);
            linkContainer.appendChild(copyBtn);

            if (fileName.toLowerCase().endsWith('.mp4')) {
                const embedBtn = document.createElement('button');
                embedBtn.textContent = 'Embed Video for Discord';
                embedBtn.className = 'embed-btn';
                embedBtn.onclick = () => {
                    showEmbedModal(url);
                };
                linkContainer.appendChild(embedBtn);
            }

            resultContainer.appendChild(linkContainer);
            resultContainer.style.display = 'block';
        }

        function showEmbedModal(url) {
            const embedUrl = `${window.location.origin}/embed?url=${encodeURIComponent(window.location.origin + url)}&thumbnail=${encodeURIComponent('https://coollsd-fileuploader.hf.space/rbxg/LdiWpl4JO8XmYc6m2PbfrwZgSOjRUX0kPaJzp2IDSN5fYVHK/Untitled.png')}`;
            embedLinkInput.value = embedUrl;
            modal.style.display = "block";
        }

        function copyEmbedLink() {
            embedLinkInput.select();
            document.execCommand('copy');
            alert('Embed link copied to clipboard!');
        }
    </script>
</body>
</html>
"""

@app.get("/", response_class=HTMLResponse)
async def index():
    return HTML_CONTENT

@app.post("/upload")
async def handle_upload(file: UploadFile = File(...)):
    if not file.filename:
        return JSONResponse(content={"error": "No file selected."}, status_code=400)

    cookies = await get_cookies()
    if 'csrftoken' not in cookies or 'sessionid' not in cookies:
        return JSONResponse(content={"error": "Failed to obtain necessary cookies"}, status_code=500)

    upload_result = await initiate_upload(cookies, file.filename, file.content_type)
    if not upload_result or 'upload_url' not in upload_result:
        return JSONResponse(content={"error": "Failed to initiate upload"}, status_code=500)

    file_content = await file.read()
    upload_success = await retry_upload(upload_result['upload_url'], file_content, file.content_type)
    if not upload_success:
        return JSONResponse(content={"error": "File upload failed after multiple attempts"}, status_code=500)

    original_url = upload_result['serving_url']
    mirrored_url = f"/rbxg/{original_url.split('/pbxt/')[1]}"
    
    return JSONResponse(content={"url": mirrored_url})

@app.get("/rbxg/{path:path}")
async def handle_video_stream(path: str, request: Request):
    original_url = f'https://replicate.delivery/pbxt/{path}'
    range_header = request.headers.get('Range')

    headers = {'Range': range_header} if range_header else {}
    response = requests.get(original_url, headers=headers, stream=True)

    def generate():
        for chunk in response.iter_content(chunk_size=8192):
            yield chunk

    headers = dict(response.headers)
    headers['Access-Control-Allow-Origin'] = '*'
    headers['Content-Disposition'] = 'inline'

    if response.status_code == 206:
        headers['Content-Range'] = response.headers.get('Content-Range')

    return StreamingResponse(generate(), status_code=response.status_code, headers=headers)

@app.get("/embed")
async def embed_video(url: str, thumbnail: str):
    html = f'''
    <html>
    <head>
        <meta property="og:type" content="video.other">
        <meta property="og:video" content="{url}">
        <meta property="og:video:url" content="{url}">
        <meta property="og:video:secure_url" content="{url}">
        <meta property="og:video:type" content="video/mp4">
        <meta property="og:video:width" content="1280">
        <meta property="og:video:height" content="720">
        <meta property="og:image" content="{thumbnail}">
        <meta property="og:image:secure_url" content="{thumbnail}">
        <meta property="og:image:width" content="1280">
        <meta property="og:image:height" content="720">
        <meta property="og:image:type" content="image/png">
        <style>
            body, html {{ margin: 0; padding: 0; height: 100%; }}
            #thumbnail {{ width: 100%; height: 100%; object-fit: contain; cursor: pointer; }}
            #video {{ display: none; width: 100%; height: 100%; object-fit: contain; }}
        </style>
    </head>
    <body>
        <img id="thumbnail" src="{thumbnail}" onclick="playVideo()">
        <video id="video" controls>
            <source src="{url}" type="video/mp4">
            Your browser does not support the video tag.
        </video>
        <script>
            function playVideo() {{
                document.getElementById('thumbnail').style.display = 'none';
                document.getElementById('video').style.display = 'block';
                document.getElementById('video').play();
            }}
        </script>
    </body>
    </html>
    '''
    return HTMLResponse(content=html)

async def get_cookies() -> Dict[str, str]:
    try:
        response = requests.get('https://replicate.com/levelsio/neon-tokyo', headers={
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36'
        })
        return dict(response.cookies)
    except Exception as e:
        print(f'Error fetching the page: {e}')
        return {}

async def initiate_upload(cookies: Dict[str, str], filename: str, content_type: str) -> Dict:
    url = f'https://replicate.com/api/upload/{filename}?content_type={content_type}'
    try:
        response = requests.post(url, cookies=cookies, headers={
            'X-CSRFToken': cookies.get('csrftoken'),
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
            'Referer': 'https://replicate.com/levelsio/neon-tokyo',
            'Origin': 'https://replicate.com',
            'Accept': '*/*',
            'Accept-Language': 'en-US,en;q=0.5',
            'Accept-Encoding': 'identity',
            'Sec-Fetch-Dest': 'empty',
            'Sec-Fetch-Mode': 'cors',
            'Sec-Fetch-Site': 'same-origin',
            'Sec-GPC': '1',
            'Priority': 'u=1, i'
        })
        print(f'Initiate upload response status: {response.status_code}')
        print(f'Initiate upload response headers: {response.headers}')
        print(f'Response body: {response.text}')
        return response.json()
    except Exception as e:
        print(f'Error initiating upload: {e}')
        raise

async def upload_file(upload_url: str, file_content: bytes, content_type: str) -> bool:
    try:
        response = requests.put(upload_url, data=file_content, headers={'Content-Type': content_type})
        print(f'File upload response status: {response.status_code}')
        print(f'File upload response headers: {response.headers}')
        return response.status_code == 200
    except Exception as e:
        print(f'Error uploading file: {e}')
        return False

async def retry_upload(upload_url: str, file_content: bytes, content_type: str, max_retries: int = 5, delay: int = 1) -> bool:
    for attempt in range(1, max_retries + 1):
        print(f'Upload attempt {attempt} of {max_retries}')
        success = await upload_file(upload_url, file_content, content_type)
        if success:
            print('Upload successful')
            return True
        if attempt < max_retries:
            print(f'Upload failed, retrying in {delay}s...')
            time.sleep(delay)
            delay *= 2  # Exponential backoff
    print('Upload failed after all retry attempts')
    return False