media-dl 2.5.0 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.js +84 -32
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -24,11 +24,22 @@ let safeMode = true;
|
|
|
24
24
|
if (!fs.existsSync(TOOLS_DIR)) fs.mkdirSync(TOOLS_DIR, { recursive: true });
|
|
25
25
|
|
|
26
26
|
function checkTools() {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
// Cek jalur default lokal (internal)
|
|
28
|
+
const LOCAL_YT = path.join(TOOLS_DIR, isWindows ? 'yt-dlp.exe' : 'yt-dlp');
|
|
29
|
+
const LOCAL_FF = path.join(TOOLS_DIR, isWindows ? 'ffmpeg.exe' : 'ffmpeg');
|
|
29
30
|
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const isLocalYt = fs.existsSync(LOCAL_YT);
|
|
32
|
+
const isLocalFf = fs.existsSync(LOCAL_FF);
|
|
33
|
+
|
|
34
|
+
let ytExists = isLocalYt;
|
|
35
|
+
let ffExists = isLocalFf;
|
|
36
|
+
|
|
37
|
+
// Reset path ke default sebelum pengecekan global
|
|
38
|
+
if (isLocalYt) YTDLP_PATH = LOCAL_YT;
|
|
39
|
+
if (isLocalFf) FFMPEG_PATH = LOCAL_FF;
|
|
40
|
+
|
|
41
|
+
// Cek Global yt-dlp hanya jika lokal tidak ada
|
|
42
|
+
if (!isLocalYt) {
|
|
32
43
|
try {
|
|
33
44
|
const cmd = isWindows ? 'where yt-dlp' : 'which yt-dlp';
|
|
34
45
|
const pathFound = execSync(cmd, { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
@@ -36,14 +47,16 @@ function checkTools() {
|
|
|
36
47
|
.trim()
|
|
37
48
|
.split('\n')[0];
|
|
38
49
|
if (pathFound) {
|
|
39
|
-
YTDLP_PATH = pathFound;
|
|
50
|
+
YTDLP_PATH = pathFound;
|
|
40
51
|
ytExists = true;
|
|
41
52
|
}
|
|
42
|
-
} catch (e) {
|
|
53
|
+
} catch (e) {
|
|
54
|
+
YTDLP_PATH = LOCAL_YT; // Kembalikan ke path lokal jika global pun tidak ada
|
|
55
|
+
}
|
|
43
56
|
}
|
|
44
57
|
|
|
45
|
-
// Cek Global ffmpeg
|
|
46
|
-
if (!
|
|
58
|
+
// Cek Global ffmpeg hanya jika lokal tidak ada
|
|
59
|
+
if (!isLocalFf) {
|
|
47
60
|
try {
|
|
48
61
|
const cmd = isWindows ? 'where ffmpeg' : 'which ffmpeg';
|
|
49
62
|
const globalPath = execSync(cmd, { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
@@ -51,13 +64,21 @@ function checkTools() {
|
|
|
51
64
|
.trim()
|
|
52
65
|
.split('\n')[0];
|
|
53
66
|
if (globalPath) {
|
|
54
|
-
FFMPEG_PATH = globalPath;
|
|
67
|
+
FFMPEG_PATH = globalPath;
|
|
55
68
|
ffExists = true;
|
|
56
69
|
}
|
|
57
|
-
} catch (e) {
|
|
70
|
+
} catch (e) {
|
|
71
|
+
FFMPEG_PATH = LOCAL_FF; // Kembalikan ke path lokal jika global pun tidak ada
|
|
72
|
+
}
|
|
58
73
|
}
|
|
59
74
|
|
|
60
|
-
return {
|
|
75
|
+
return {
|
|
76
|
+
ytExists,
|
|
77
|
+
ffExists,
|
|
78
|
+
isLocalYt,
|
|
79
|
+
isLocalFf,
|
|
80
|
+
allReady: ytExists && ffExists,
|
|
81
|
+
};
|
|
61
82
|
}
|
|
62
83
|
|
|
63
84
|
// --- INSTALLERS ---
|
|
@@ -246,8 +267,7 @@ async function startDownload(videoURLFromArgs = null) {
|
|
|
246
267
|
console.log(
|
|
247
268
|
`\n${C.red}❌ Engine yt-dlp tidak ditemukan. Silakan pilih menu Update/Install.${C.reset}`,
|
|
248
269
|
);
|
|
249
|
-
await
|
|
250
|
-
return mainMenu();
|
|
270
|
+
await backToMenu();
|
|
251
271
|
}
|
|
252
272
|
|
|
253
273
|
if (!ffExists) {
|
|
@@ -291,8 +311,7 @@ async function startDownload(videoURLFromArgs = null) {
|
|
|
291
311
|
`${C.yellow}⚠️ Pastikan link valid atau tidak diprivat/dihapus.${C.reset}`,
|
|
292
312
|
);
|
|
293
313
|
}
|
|
294
|
-
await
|
|
295
|
-
return mainMenu();
|
|
314
|
+
await backToMenu();
|
|
296
315
|
}
|
|
297
316
|
|
|
298
317
|
// --- PEMILIHAN PLAYLIST (Tetap Sama) ---
|
|
@@ -430,8 +449,23 @@ async function startDownload(videoURLFromArgs = null) {
|
|
|
430
449
|
} else {
|
|
431
450
|
console.log(`\n${C.red}❌ Terjadi kesalahan saat mengunduh.${C.reset}`);
|
|
432
451
|
}
|
|
433
|
-
await
|
|
434
|
-
|
|
452
|
+
await backToMenu();
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
async function backToMenu() {
|
|
456
|
+
try {
|
|
457
|
+
await askQuestion('Tekan Enter untuk kembali ke Menu Utama...');
|
|
458
|
+
mainMenu(); // Kembali ke menu
|
|
459
|
+
} catch (err) {
|
|
460
|
+
// Tangani jika readline sudah tertutup (Ctrl+C ditekan sebelumnya)
|
|
461
|
+
if (err.code === 'ERR_USE_AFTER_CLOSE') {
|
|
462
|
+
console.log(`\n${C.dim}Program dihentikan oleh pengguna.${C.reset}`);
|
|
463
|
+
process.exit(0);
|
|
464
|
+
} else {
|
|
465
|
+
// Jika error lain, lempar kembali agar bisa dideteksi (opsional)
|
|
466
|
+
throw err;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
435
469
|
}
|
|
436
470
|
|
|
437
471
|
async function showSupport() {
|
|
@@ -496,29 +530,35 @@ async function showSupport() {
|
|
|
496
530
|
|
|
497
531
|
console.log(`\n${C.cyan}${'━'.repeat(52)}${C.reset}`);
|
|
498
532
|
|
|
499
|
-
await
|
|
500
|
-
mainMenu();
|
|
533
|
+
await backToMenu();
|
|
501
534
|
}
|
|
502
535
|
|
|
503
536
|
async function mainMenu() {
|
|
504
|
-
const
|
|
537
|
+
const status = checkTools();
|
|
538
|
+
const { ytExists, ffExists } = status;
|
|
505
539
|
|
|
506
540
|
// Menggunakan 2 parameter: Judul dan Summary status singkat
|
|
507
541
|
printHeader('MEDIA-DL PRO 2026', 'Pusat Kendali Unduhan Media Lokal');
|
|
508
542
|
|
|
509
543
|
// --- SEKSI DASHBOARD (INFO SISTEM) ---
|
|
510
|
-
const
|
|
511
|
-
? `${C.green}Ready${C.reset}`
|
|
512
|
-
:
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
544
|
+
const ytLabel = status.isLocalYt
|
|
545
|
+
? `${C.green}Ready (Internal)${C.reset}`
|
|
546
|
+
: status.ytExists
|
|
547
|
+
? `${C.cyan}Ready (System)${C.reset}`
|
|
548
|
+
: `${C.red}Not Found${C.reset}`;
|
|
549
|
+
|
|
550
|
+
const ffLabel = status.isLocalFf
|
|
551
|
+
? `${C.green}Ready (Internal)${C.reset}`
|
|
552
|
+
: status.ffExists
|
|
553
|
+
? `${C.cyan}Ready (System)${C.reset}`
|
|
554
|
+
: `${C.yellow}Missing${C.reset}`;
|
|
555
|
+
|
|
516
556
|
const safeBadge = safeMode
|
|
517
557
|
? `${C.bgBlue}${C.white} ON ${C.reset}`
|
|
518
558
|
: `${C.bgRed}${C.white} OFF ${C.reset}`;
|
|
519
559
|
|
|
520
560
|
console.log(` ${C.bright}SYSTEM STATUS${C.reset}`);
|
|
521
|
-
console.log(` 🤖 Engine : [ ${
|
|
561
|
+
console.log(` 🤖 Engine : [ ${ytLabel} ] | 🎬 FFmpeg : [ ${ffLabel} ]`);
|
|
522
562
|
console.log(` 🛡️ Safe Mode Guard : ${safeBadge}\n`);
|
|
523
563
|
|
|
524
564
|
console.log(` ${C.cyan}━${'━'.repeat(48)}${C.reset}`);
|
|
@@ -592,9 +632,13 @@ async function mainMenu() {
|
|
|
592
632
|
}
|
|
593
633
|
|
|
594
634
|
async function cleanUp() {
|
|
595
|
-
|
|
596
|
-
if (conf.toLowerCase() === 'y')
|
|
635
|
+
if (fs.existsSync(TOOLS_DIR)) {
|
|
597
636
|
fs.rmSync(TOOLS_DIR, { recursive: true, force: true });
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// RESET PATH ke default lokal agar checkTools tidak "tersesat" menggunakan path lama
|
|
640
|
+
YTDLP_PATH = path.join(TOOLS_DIR, isWindows ? 'yt-dlp.exe' : 'yt-dlp');
|
|
641
|
+
FFMPEG_PATH = path.join(TOOLS_DIR, isWindows ? 'ffmpeg.exe' : 'ffmpeg');
|
|
598
642
|
}
|
|
599
643
|
|
|
600
644
|
async function firstTimeSetup() {
|
|
@@ -686,9 +730,17 @@ async function systemMaintenance() {
|
|
|
686
730
|
);
|
|
687
731
|
if (confirm.toLowerCase() === 'y') {
|
|
688
732
|
await cleanUp(); // Panggil fungsi penghapusan folder
|
|
689
|
-
console.log(
|
|
690
|
-
|
|
691
|
-
|
|
733
|
+
console.log(`${C.yellow}Folder .media-dl telah dihapus.${C.reset}`);
|
|
734
|
+
|
|
735
|
+
// Cek ulang status setelah hapus
|
|
736
|
+
const finalCheck = checkTools();
|
|
737
|
+
if (finalCheck.isLocalYt || finalCheck.isLocalFf) {
|
|
738
|
+
console.log(
|
|
739
|
+
`${C.red}Gagal menghapus beberapa file. Pastikan tidak ada proses yang mengunci file.${C.reset}`,
|
|
740
|
+
);
|
|
741
|
+
} else {
|
|
742
|
+
console.log(`${C.green}Reset lokal berhasil.${C.reset}`);
|
|
743
|
+
}
|
|
692
744
|
await askQuestion('Tekan Enter...');
|
|
693
745
|
return bootstrap(); // Kembali ke pengecekan awal
|
|
694
746
|
}
|