Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- Dockerfile +2 -3
- server.js +28 -7
Dockerfile
CHANGED
|
@@ -11,9 +11,8 @@ RUN apt-get update && apt-get install -y \
|
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
# Install yt-dlp
|
| 14 |
-
# Install yt-dlp (Direct from
|
| 15 |
-
RUN
|
| 16 |
-
chmod a+rx /usr/local/bin/yt-dlp
|
| 17 |
|
| 18 |
# Optional: Install python3 requests (sometimes needed by yt-dlp internals)
|
| 19 |
RUN pip3 install --break-system-packages requests
|
|
|
|
| 11 |
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
|
| 13 |
# Install yt-dlp
|
| 14 |
+
# Install yt-dlp (Direct from Master Branch for Bleeding Edge Fixes)
|
| 15 |
+
RUN pip3 install --break-system-packages --upgrade --force-reinstall https://github.com/yt-dlp/yt-dlp/archive/master.zip
|
|
|
|
| 16 |
|
| 17 |
# Optional: Install python3 requests (sometimes needed by yt-dlp internals)
|
| 18 |
RUN pip3 install --break-system-packages requests
|
server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
// =================================================================
|
| 2 |
// == KODE LENGKAP - backend/server.js ==
|
| 3 |
-
// == SOLUSI FINAL: STABIL (
|
| 4 |
// =================================================================
|
| 5 |
const express = require('express');
|
| 6 |
const cors = require('cors');
|
|
@@ -74,8 +74,8 @@ const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
|
|
| 74 |
const execWithRetry = async (originalArgs, retries = 3) => {
|
| 75 |
let currentRetries = 0;
|
| 76 |
|
| 77 |
-
//
|
| 78 |
-
|
| 79 |
|
| 80 |
while (currentRetries < retries) {
|
| 81 |
try {
|
|
@@ -93,7 +93,18 @@ const execWithRetry = async (originalArgs, retries = 3) => {
|
|
| 93 |
errorMsg.includes('Connection refused');
|
| 94 |
|
| 95 |
if (isNetworkError && currentRetries < retries) {
|
| 96 |
-
console.log(`[RETRY SYSTEM] Percobaan ${currentRetries}/${retries} gagal.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
await new Promise(r => setTimeout(r, 2000));
|
| 98 |
continue;
|
| 99 |
}
|
|
@@ -270,15 +281,25 @@ app.post('/api/create-all-files', (req, res) => {
|
|
| 270 |
async function startServer() {
|
| 271 |
console.log('--- STARTING SERVER ---');
|
| 272 |
try {
|
| 273 |
-
//
|
|
|
|
|
|
|
|
|
|
| 274 |
if (fs.existsSync('/usr/local/bin/yt-dlp')) {
|
| 275 |
ytDlp = new YtDlpWrap('/usr/local/bin/yt-dlp');
|
| 276 |
-
console.log('Using
|
|
|
|
|
|
|
|
|
|
| 277 |
} else {
|
|
|
|
| 278 |
ytDlp = new YtDlpWrap('yt-dlp');
|
| 279 |
-
console.log('Using
|
| 280 |
}
|
|
|
|
| 281 |
} catch (e) {
|
|
|
|
|
|
|
| 282 |
ytDlp = new YtDlpWrap('yt-dlp');
|
| 283 |
}
|
| 284 |
console.log('yt-dlp initialized.');
|
|
|
|
| 1 |
// =================================================================
|
| 2 |
// == KODE LENGKAP - backend/server.js ==
|
| 3 |
+
// == SOLUSI FINAL: STABIL (Smart Retry + Master Branch) ==
|
| 4 |
// =================================================================
|
| 5 |
const express = require('express');
|
| 6 |
const cors = require('cors');
|
|
|
|
| 74 |
const execWithRetry = async (originalArgs, retries = 3) => {
|
| 75 |
let currentRetries = 0;
|
| 76 |
|
| 77 |
+
// Mulai dengan args standard (termasuk --force-ipv4 jika ada di originalArgs)
|
| 78 |
+
let args = [...originalArgs];
|
| 79 |
|
| 80 |
while (currentRetries < retries) {
|
| 81 |
try {
|
|
|
|
| 93 |
errorMsg.includes('Connection refused');
|
| 94 |
|
| 95 |
if (isNetworkError && currentRetries < retries) {
|
| 96 |
+
console.log(`[RETRY SYSTEM] Percobaan ${currentRetries}/${retries} gagal. Mencoba strategi alternatif...`);
|
| 97 |
+
|
| 98 |
+
// STRATEGI: Toggle --force-ipv4
|
| 99 |
+
// Jika error DNS terus terjadi, mungkin container lebih suka IPv6 atau default routing
|
| 100 |
+
const ipv4Index = args.indexOf('--force-ipv4');
|
| 101 |
+
if (ipv4Index !== -1) {
|
| 102 |
+
console.log('[RETRY] Menghapus flag --force-ipv4');
|
| 103 |
+
args.splice(ipv4Index, 1);
|
| 104 |
+
} else {
|
| 105 |
+
// Optional: Bisa tambahkan strategi lain di sini
|
| 106 |
+
}
|
| 107 |
+
|
| 108 |
await new Promise(r => setTimeout(r, 2000));
|
| 109 |
continue;
|
| 110 |
}
|
|
|
|
| 281 |
async function startServer() {
|
| 282 |
console.log('--- STARTING SERVER ---');
|
| 283 |
try {
|
| 284 |
+
// Cek binary yang tersedia dan valid
|
| 285 |
+
// Kita prioritas pakai yt-dlp dari pip modules karena di-install dari master branch
|
| 286 |
+
// Tapi YtDlpWrap expect path binary.
|
| 287 |
+
// Helper: Cari lokasi yt-dlp
|
| 288 |
if (fs.existsSync('/usr/local/bin/yt-dlp')) {
|
| 289 |
ytDlp = new YtDlpWrap('/usr/local/bin/yt-dlp');
|
| 290 |
+
console.log('Using binary: /usr/local/bin/yt-dlp');
|
| 291 |
+
} else if (fs.existsSync('/usr/bin/yt-dlp')) {
|
| 292 |
+
ytDlp = new YtDlpWrap('/usr/bin/yt-dlp');
|
| 293 |
+
console.log('Using binary: /usr/bin/yt-dlp');
|
| 294 |
} else {
|
| 295 |
+
// Fallback ke string command (berharap ada di PATH)
|
| 296 |
ytDlp = new YtDlpWrap('yt-dlp');
|
| 297 |
+
console.log('Using PATH binary: yt-dlp');
|
| 298 |
}
|
| 299 |
+
|
| 300 |
} catch (e) {
|
| 301 |
+
console.error("Critical Init Error:", e);
|
| 302 |
+
// Fallback terakhir
|
| 303 |
ytDlp = new YtDlpWrap('yt-dlp');
|
| 304 |
}
|
| 305 |
console.log('yt-dlp initialized.');
|