Add track downloading functionality and improve error handling
This commit is contained in:
parent
43667b79f0
commit
80d73027a6
2 changed files with 27 additions and 3 deletions
26
index.ts
26
index.ts
|
@ -52,3 +52,29 @@ Bun.serve({
|
|||
},
|
||||
development: true
|
||||
})
|
||||
|
||||
const tracks = await utils.fetchTracks();
|
||||
|
||||
for await (const track of tracks.items) {
|
||||
const { id } = track.item
|
||||
|
||||
const trackId = parseInt(id)
|
||||
|
||||
if (await Bun.file(`downloaded/${trackId}.flac`).exists()) {
|
||||
console.log(`Already downloaded ${trackId}.flac`)
|
||||
continue
|
||||
}
|
||||
|
||||
const { manifestMimeType, manifest } = await utils.fetchTrack(parseInt(id))
|
||||
|
||||
try {
|
||||
const audio = await utils.tagFlac(trackId, await utils.downloadFlac(manifestMimeType, manifest))
|
||||
|
||||
await Bun.write(`downloaded/${trackId}.flac`, audio)
|
||||
console.log(`Downloaded ${trackId}.flac`)
|
||||
} catch (e) {
|
||||
console.error(`Failed to download ${trackId}.flac`)
|
||||
}
|
||||
}
|
||||
|
||||
console.log("Done")
|
|
@ -113,8 +113,6 @@ export default class {
|
|||
],
|
||||
}
|
||||
|
||||
console.log(track)
|
||||
|
||||
return FlacStreamTagger.fromBuffer(Buffer.from(audioBuffer), {
|
||||
tagMap: {
|
||||
title: track.title,
|
||||
|
|
Loading…
Add table
Reference in a new issue