1
0
mirror of synced 2026-08-06 11:36:59 +00:00
Files

35 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2024-08-08 10:19:14 +02:00
import https from 'node:https';
import { inspect } from 'node:util';
import { parseStream } from '../../lib/index.js'; // music-metadata
2019-02-02 19:01:54 +01:00
const audioUrl = 'https://github.com/Borewit/music-metadata/raw/master/test/samples/MusicBrainz%20-%20Beth%20Hart%20-%20Sinner\'s%20Prayer%20%5Bid3v2.3%5D.V2.mp3';
function httpGet (url) {
2021-01-02 19:27:17 +01:00
return new Promise((resolve, reject) => {
https.get(url, (res) => {
2019-02-02 19:01:54 +01:00
switch (res.statusCode) {
case 200:
resolve(res);
break;
case 302: // redirect
resolve(httpGet(res.headers.location));
break;
default:
2024-08-08 10:19:14 +02:00
reject(new Error(`Unexpected status-code:${res.statusCode}`));
2019-02-02 19:01:54 +01:00
}
});
});
}
2021-01-02 19:27:17 +01:00
(async () => {
try {
// Stream MP3 sample file from GitHub via HTTP
2021-01-04 07:49:01 +01:00
const stream = await httpGet(audioUrl);
const metadata = await parseStream(stream);
console.log(inspect(metadata, { showHidden: false, depth: null }));
2021-02-08 18:10:51 +01:00
} catch(error) {
2021-01-02 19:27:17 +01:00
// Oops, something went wrong
2021-02-08 18:10:51 +01:00
console.error(error.message);
2021-01-02 19:27:17 +01:00
}
})();