-
Notifications
You must be signed in to change notification settings - Fork 20
/
example.js
69 lines (61 loc) · 1.73 KB
/
example.js
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
import HLSDownloader from './build/index';
// for fetching
let downloader = new HLSDownloader({
playlistURL: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
});
console.log(await downloader.startDownload());
// download HLS resoruces
downloader = new HLSDownloader({
playlistURL: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
destination: '/tmp/tests',
});
// with 5 parallel download
downloader = new HLSDownloader({
concurrency: 5,
destination: '/tmp/tests',
playlistURL: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
});
// force overwrite
downloader = new HLSDownloader({
concurrency: 5,
overwrite: true,
destination: '/tmp/tests',
playlistURL: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
});
// passing ky option
downloader = new HLSDownloader({
concurrency: 5,
overwrite: true,
destination: '/tmp/tests',
playlistURL: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
retry: { limit: 0 },
});
// passing onData hook
downloader = new HLSDownloader({
concurrency: 5,
overwrite: true,
destination: '/tmp/tests',
playlistURL: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
retry: { limit: 0 },
onData: function (data) {
console.log(
'downloaded item = ',
data.url,
', total items to download',
data.totalItems,
', downloaded path =',
data.path
);
},
});
// passing onError hook
downloader = new HLSDownloader({
concurrency: 5,
overwrite: true,
destination: '/tmp/tests',
playlistURL: 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
retry: { limit: 0 },
onError: function (error) {
console.log({ ...error });
},
});