-
Notifications
You must be signed in to change notification settings - Fork 52
/
testYtdl.mjs
29 lines (27 loc) · 963 Bytes
/
testYtdl.mjs
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
import ytdl from "@distube/ytdl-core";
const testUrl = "https://youtu.be/R8lg6DM11fM";
console.log('Attempting to get info & download URL for "' + testUrl + '"');
const startTime = new Date().getTime();
ytdl
.getInfo(testUrl)
.then((info) => {
let format = ytdl.chooseFormat(info.formats, { quality: "highestvideo", filter: "videoonly" });
if (format.url) {
const endTime = new Date().getTime();
console.log(
"Successfully found info & download URL in " +
((endTime - startTime) / 1000).toFixed(2) +
"s. Full URL shown below."
);
console.log("\n" + format.url + "\n");
} else {
console.error("Cannot find download URL. Download info shown below.");
console.error("\n" + info + "\n");
throw new Error();
}
})
.catch((reason) => {
console.error("Cannot get download info. Reason shown below.");
console.error("\n" + reason + "\n");
throw new Error();
});