-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexample.ts
90 lines (79 loc) · 1.85 KB
/
example.ts
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
import { createWriteStream } from 'fs';
import { YtDlp } from './src/index';
const ytdlp = new YtDlp();
async function getVideoFile() {
try {
const videoFile = await ytdlp.getFileAsync(
'https://www.youtube.com/watch?v=_AL4IwHuHlY',
{
onProgress: (progress) => {
console.log(progress);
},
}
);
console.log('Video File:', {
name: videoFile.name,
type: videoFile.type,
size: videoFile.size,
});
} catch (error) {
console.error('Error:', error);
}
}
async function downloadVideo() {
try {
const output = await ytdlp.downloadAsync(
'https://www.youtube.com/watch?v=_AL4IwHuHlY',
{
onProgress: (progress) => {
console.log(progress);
},
}
);
console.log(output);
} catch (error) {
console.error('Error:', error);
}
}
async function streamVideo() {
try {
const st = createWriteStream('video.mp4');
const ytdlpStream = ytdlp.stream(
'https://www.youtube.com/watch?v=_AL4IwHuHlY',
{
onProgress: (progress) => {
console.log(progress);
},
}
);
await ytdlpStream.pipeAsync(st);
console.log('Downloaded');
} catch (error) {
console.error('Error:', error);
}
}
async function execVideo() {
const s = ytdlp.download('https://www.youtube.com/watch?v=_AL4IwHuHlY');
s.on('progress', (d) => {
console.log(d);
});
}
async function isInstallation() {
try {
const isInstalled = await ytdlp.checkInstallationAsync({ ffmpeg: true });
console.log(isInstalled);
} catch (error) {
console.log('test', error.message);
}
}
ytdlp.downloadFFmpeg().then(async () => {
try {
await isInstallation();
await downloadVideo();
await streamVideo();
await execVideo();
await getVideoFile();
} catch (error) {
console.log(error);
}
});