-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
testAndRefresh.mjs
26 lines (23 loc) · 997 Bytes
/
testAndRefresh.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
import bcfetch from '../../dist/mjs/index.js';
const streamUrl = 'https://t4.bcbits.com/stream/a9fab205c6d82ffc4ca4f377d86bd8dd/mp3-128/3535427082?p=0&ts=1698526235&t=3c987d3b75dc4151c931288780eca682ae1d70ac&token=1698526235_35d7ab2f75c60cdb31c68df15cc5d5024368a535';
console.log(`Testing stream URL: ${streamUrl}`);
bcfetch.stream.test(streamUrl).then((result1) => {
if (result1.ok) {
console.log('Stream URL is valid.');
return;
}
console.log(`Stream URL is invalid. Status code: ${result1.status}. Refreshing...`);
bcfetch.stream.refresh(streamUrl).then((result2) => {
console.log(`Refreshed stream URL: ${result2}`);
if (result2) {
console.log('Testing refreshed stream URL...');
bcfetch.stream.test(result2).then((result3) => {
if (result3.ok) {
console.log('Refreshed stream URL is valid.');
return;
}
console.log(`Refreshed stream URL is invalid. Status code: ${result3.status}`);
});
}
});
});