media-dl 1.0.0

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.
Files changed (3) hide show
  1. package/bin/cli.js +122 -0
  2. package/package.json +24 -0
  3. package/readme.md +51 -0
package/bin/cli.js ADDED
@@ -0,0 +1,122 @@
1
+ 201~200~#!/usr/bin/env node
2
+
3
+ const { spawn, execSync } = require('child_process');
4
+ const readline = require('readline');
5
+ const path = require('path');
6
+ const fs = require('fs');
7
+ const os = require('os');
8
+
9
+ const rl = readline.createInterface({
10
+ input: process.stdin,
11
+ output: process.stdout
12
+ });
13
+
14
+ // Penentuan folder Tools berdasarkan OS (menyimpan di folder Home agar aman)
15
+ const TOOLS_DIR = path.join(os.homedir(), '.media-dl');
16
+ const isWindows = process.platform === 'win32';
17
+
18
+ const YTDLP_PATH = path.join(TOOLS_DIR, isWindows ? 'yt-dlp.exe' : 'yt-dlp');
19
+ const FFMPEG_PATH = path.join(TOOLS_DIR, isWindows ? 'ffmpeg.exe' : 'ffmpeg');
20
+
21
+ if (!fs.existsSync(TOOLS_DIR)) fs.mkdirSync(TOOLS_DIR, { recursive: true });
22
+
23
+ function askQuestion(query) {
24
+ return new Promise(resolve => rl.question(query, resolve));
25
+ }
26
+
27
+ function checkTools() {
28
+ return {
29
+ ytExists: fs.existsSync(YTDLP_PATH),
30
+ ffExists: fs.existsSync(FFMPEG_PATH)
31
+ };
32
+ }
33
+
34
+ async function installTools() {
35
+ console.log(`\n--- šŸ› ļø INSTALASI TOOLS (${process.platform.toUpperCase()}) ---`);
36
+ const { ytExists } = checkTools();
37
+
38
+ if (!ytExists) {
39
+ console.log('ā³ Mengunduh yt-dlp...');
40
+ try {
41
+ const url = isWindows
42
+ ? 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe'
43
+ : 'https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp';
44
+
45
+ if (isWindows) {
46
+ execSync(`powershell -Command "Invoke-WebRequest -Uri ${url} -OutFile '${YTDLP_PATH}'"`);
47
+ } else {
48
+ execSync(`curl -L ${url} -o "${YTDLP_PATH}"`);
49
+ execSync(`chmod a+rx "${YTDLP_PATH}"`);
50
+ }
51
+ console.log('āœ… yt-dlp berhasil diinstal.');
52
+ } catch (e) {
53
+ console.error('āŒ Gagal menginstal yt-dlp. Pastikan koneksi internet stabil.');
54
+ }
55
+ } else {
56
+ console.log('āœ… yt-dlp sudah terpasang.');
57
+ }
58
+
59
+ console.log('\nšŸ“ Catatan untuk FFmpeg:');
60
+ console.log(`Silakan unduh ffmpeg manual dan letakkan di: ${FFMPEG_PATH}`);
61
+ }
62
+
63
+ async function startDownload() {
64
+ const { ytExists, ffExists } = checkTools();
65
+ if (!ytExists) {
66
+ console.log('\nāš ļø Error: Jalankan menu Instalasi terlebih dahulu.');
67
+ return mainMenu();
68
+ }
69
+
70
+ const videoURL = await askQuestion('\nšŸ”— Masukkan Link: ');
71
+ console.log('\n[Format]\n1. Audio (MP3)\n2. Video (MP4)');
72
+ const choice = await askQuestion('Pilihan: ');
73
+
74
+ const outputDir = path.join(process.cwd(), 'downloads');
75
+ if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
76
+
77
+ const args = choice === '1'
78
+ ? ['-x', '--audio-format', 'mp3', '--ffmpeg-location', FFMPEG_PATH, '-o', `${outputDir}/%(title)s.%(ext)s`, videoURL]
79
+ : ['-f', 'mp4', '-o', `${outputDir}/%(title)s.%(ext)s`, videoURL];
80
+
81
+ const download = spawn(YTDLP_PATH, args);
82
+
83
+ download.stdout.on('data', (data) => process.stdout.write(data));
84
+ download.on('close', (code) => {
85
+ console.log(code === 0 ? `\nāœ… SELESAI! Cek folder: ${outputDir}` : '\nāŒ Gagal.');
86
+ mainMenu();
87
+ });
88
+ }
89
+
90
+ async function mainMenu() {
91
+ const { ytExists, ffExists } = checkTools();
92
+ console.log('\n==============================');
93
+ console.log(' MEDIA-DL MANAGER ');
94
+ console.log('==============================');
95
+ console.log(`OS: ${process.platform} | yt-dlp: ${ytExists ? 'āœ…' : 'āŒ'} | ffmpeg: ${ffExists ? 'āœ…' : 'āŒ'}`);
96
+ console.log('------------------------------');
97
+ console.log('1. Download Media');
98
+ console.log('2. Instal/Update yt-dlp');
99
+ console.log('3. Keluar');
100
+
101
+ const menuChoice = await askQuestion('\nPilih: ');
102
+ if (menuChoice === '1') await startDownload();
103
+ else if (menuChoice === '2') { await installTools(); mainMenu(); }
104
+ else { rl.close(); process.exit(0); }
105
+ }
106
+
107
+ mainMenu();
108
+ }
109
+ })
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ })
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "media-dl",
3
+ "version": "1.0.0",
4
+ "description": "CLI Downloader video/audio lintas platform menggunakan yt-dlp.",
5
+ "main": "bin/cli.js",
6
+ "bin": {
7
+ "media-dl": "bin/cli.js"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "keywords": [
13
+ "downloader",
14
+ "youtube",
15
+ "cross-platform",
16
+ "media-dl"
17
+ ],
18
+ "author": "Ariska Hidayat",
19
+ "license": "MIT",
20
+ "dependencies": {},
21
+ "engines": {
22
+ "node": ">=14.0.0"
23
+ }
24
+ }
package/readme.md ADDED
@@ -0,0 +1,51 @@
1
+ # Media-DL CLI šŸš€
2
+
3
+ Alat baris perintah (CLI) lintas platform yang cepat dan sederhana untuk mengunduh video atau audio dari berbagai platform menggunakan kekuatan `yt-dlp`.
4
+
5
+ ## ✨ Fitur
6
+ - šŸŽ„ **Download Video**: Mendukung format MP4.
7
+ - šŸŽµ **Download Audio**: Konversi otomatis ke MP3 kualitas tinggi.
8
+ - šŸ’» **Lintas Platform**: Berjalan lancar di Windows, macOS, dan Linux.
9
+ - šŸ› ļø **Auto-Installer**: Membantu mengunduh dan menyiapkan `yt-dlp` secara otomatis.
10
+
11
+ ## šŸ“¦ Instalasi
12
+
13
+ Pastikan Anda sudah menginstal [Node.js](https://nodejs.org/). Kemudian instal paket ini secara global:
14
+
15
+ ```bash
16
+ npm install -g media-dl
17
+
18
+ ```
19
+
20
+ ## šŸš€ Cara Penggunaan
21
+
22
+ Cukup buka terminal/command prompt Anda dan ketik:
23
+
24
+ ```bash
25
+ media-dl
26
+
27
+ ```
28
+
29
+ Ikuti petunjuk di layar untuk mulai mengunduh atau melakukan pembaruan tools.
30
+
31
+ ## šŸ“‹ Persyaratan Sistem
32
+
33
+ * **Node.js**: v14.0.0 atau lebih tinggi.
34
+ * **FFmpeg**: Diperlukan untuk konversi audio ke MP3. Alat ini akan memberikan instruksi lokasi peletakan file binary FFmpeg di dalam menu.
35
+
36
+ ## ā˜• Dukungan & Donasi
37
+
38
+ Jika alat ini membantu pekerjaan Anda, Anda bisa memberikan dukungan kepada pengembang melalui link di bawah ini:
39
+
40
+ * **Beli Kopi ā˜•**: [Donasi via Midtrans](https://app.midtrans.com/payment-links/coffee-developer)
41
+ * **Beli Pizza šŸ•**: [Donasi via Midtrans](https://app.midtrans.com/payment-links/pizza-developer)
42
+
43
+ Dukungan Anda sangat berarti untuk pengembangan fitur-fitur selanjutnya!
44
+
45
+ ## ⭐ Ulasan
46
+
47
+ > "Alat paling praktis untuk urusan download cepat lewat terminal tanpa ribet iklan!" - *Community User*
48
+
49
+ ## šŸ“„ Lisensi
50
+
51
+ MIT