Downloaderjavascript226
YouTube Direct Media Downloader & Stream Scraper
Scraper dan downloader video serta audio langsung dari YouTube (youtube.com, youtu.be, shorts) dengan resolusi lengkap 144p hingga 4K dan direct download URL.
Vamz Spectre13 Okt 2026166 baris kode
Jalankan via Terminal / CLI:
# 1. Download file script
curl -sL "https://code.vamxapi.my.id/snippet/raw/downbyt" -o downbyt.js
# 2. Jalankan script
node downbyt.js
downbyt.js(166 lines)
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
/**
* ========================================================
* Name: YouTube Direct Media Downloader & Stream Scraper
*
* Cara Download:
* curl -sL "https://code.vamxapi.my.id/snippet/raw/downbyt" -o downbyt.js
*
* Cara Eksekusi:
* node downbyt.js "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
*
* Author: Vamz Spectre
* Source: https://vamxapi.my.id
* ========================================================
*/
const { execFile } = require("child_process");
const util = require("util");
const execFileAsync = util.promisify(execFile);
/**
* Format bytes ke ukuran yang mudah dibaca (KB, MB, GB)
*/
function formatSize(bytes) {
if (!bytes || bytes <= 0) return null;
const k = 1024;
const sizes = ["Bytes", "KB", "MB", "GB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${(bytes / Math.pow(k, i)).toFixed(2)} ${sizes[i]}`;
}
/**
* Normalisasi dan ekstraksi ID / URL YouTube
*/
function extractYouTubeId(urlOrId) {
if (!urlOrId) return null;
const str = urlOrId.trim();
if (/^[a-zA-Z0-9_-]{11}$/.test(str)) return str;
const match = str.match(
/(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=|shorts\/))([a-zA-Z0-9_-]{11})/i
);
return match ? match[1] : null;
}
/**
* Scraper & Extractor YouTube Langsung dari youtube.com
* @param {string} inputUrl - URL Video, Shorts, atau Video ID YouTube
* @returns {Promise<object>}
*/
async function downbyt(inputUrl) {
if (!inputUrl) throw new Error("URL atau ID YouTube wajib disertakan!");
const videoId = extractYouTubeId(inputUrl);
const targetUrl = videoId ? `https://www.youtube.com/watch?v=${videoId}` : inputUrl.trim();
try {
const { stdout } = await execFileAsync(
"yt-dlp",
[
"--dump-json",
"--no-warnings",
"--no-check-certificates",
"--no-playlist",
targetUrl
],
{ maxBuffer: 50 * 1024 * 1024 }
);
const data = JSON.parse(stdout);
const formats = data.formats || [];
// Filter & Organisasi Kualitas Video (144p - 4K)
const videoMap = new Map();
for (const f of formats) {
if (f.height && f.url && (f.ext === "mp4" || f.ext === "webm")) {
const key = `${f.height}p`;
const current = videoMap.get(key);
// Prioritaskan mp4 atau bitrate tertinggi
if (!current || (f.ext === "mp4" && current.ext !== "mp4") || (f.tbr > (current.tbr || 0))) {
const rawSize = f.filesize || f.filesize_approx || null;
videoMap.set(key, {
quality: key,
resolution: f.resolution || `${f.width}x${f.height}`,
extension: f.ext,
fps: f.fps || null,
size: rawSize,
size_formatted: formatSize(rawSize),
vcodec: f.vcodec,
tbr: f.tbr || null,
download_url: f.url
});
}
}
}
// Urutkan kualitas video dari terendah ke tertinggi
const videos = Array.from(videoMap.values())
.sort((a, b) => parseInt(a.quality) - parseInt(b.quality))
.map(({ tbr, ...item }) => item);
// Filter Audio (m4a, webm, opus)
const audioList = [];
for (const f of formats) {
if (f.vcodec === "none" && f.acodec !== "none" && f.url) {
const rawSize = f.filesize || f.filesize_approx || null;
audioList.push({
format_id: f.format_id,
extension: f.ext,
bitrate: f.abr ? `${Math.round(f.abr)} kbps` : null,
size: rawSize,
size_formatted: formatSize(rawSize),
acodec: f.acodec,
download_url: f.url
});
}
}
// Best direct streams
const bestVideo = videos[videos.length - 1] || null;
const bestAudio = audioList[audioList.length - 1] || null;
return {
success: true,
id: data.id,
title: data.title,
uploader: data.uploader || data.channel,
channel_url: data.channel_url || data.uploader_url || null,
duration: data.duration || null,
duration_formatted: data.duration_string || null,
view_count: data.view_count || null,
like_count: data.like_count || null,
thumbnail: data.thumbnail,
best: {
video: bestVideo,
audio: bestAudio
},
videos,
audios: audioList
};
} catch (err) {
throw new Error(`Gagal memproses YouTube: ${err.message}`);
}
}
/**
* CLI Runner:
* Langsung eksekusi jika dijalankan via terminal: node downbyt.js "<url>"
*/
const argUrl = process.argv[2];
if (argUrl) {
downbyt(argUrl)
.then(result => {
console.log(JSON.stringify(result, null, 2));
})
.catch(err => {
console.error(JSON.stringify({ success: false, error: err.message }, null, 2));
process.exit(1);
});
} else if (process.argv[1] && process.argv.length <= 2) {
console.log("Usage: node downbyt.js \"<url_youtube>\"");
}
if (typeof module !== "undefined" && module.exports) {
module.exports = { extractYouTubeId, downbyt, default: downbyt };
}