mirror of
https://git.stupid.fish/teidesu/scripts.git
synced 2025-07-28 02:32:11 +10:00
chore: update public repo
This commit is contained in:
parent
e0109980c0
commit
e7c9507247
25 changed files with 5364 additions and 0 deletions
58
scripts/media/deezer-art-fetcher.ts
Normal file
58
scripts/media/deezer-art-fetcher.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
import { iter } from '@fuman/utils'
|
||||
import { z } from 'zod'
|
||||
import { minimist, question } from 'zx'
|
||||
|
||||
import { downloadFile, ffetch } from '../../utils/fetch.ts'
|
||||
|
||||
const args = minimist(process.argv.slice(2), {
|
||||
string: ['filename'],
|
||||
})
|
||||
|
||||
const query = args._[0] ?? await question('Search query (Artist - Album): ')
|
||||
|
||||
const data = await ffetch('https://api.deezer.com/search', {
|
||||
query: {
|
||||
q: query,
|
||||
limit: 15,
|
||||
},
|
||||
}).parsedJson(z.object({
|
||||
data: z.array(z.object({
|
||||
type: z.literal('track'),
|
||||
title: z.string(),
|
||||
artist: z.object({
|
||||
name: z.string(),
|
||||
}),
|
||||
album: z.object({
|
||||
id: z.number(),
|
||||
title: z.string(),
|
||||
cover_xl: z.string(),
|
||||
}),
|
||||
})),
|
||||
}))
|
||||
|
||||
const groupedByAlbum = new Map<number, typeof data['data']>()
|
||||
for (const result of data.data) {
|
||||
const albumId = result.album.id
|
||||
if (!groupedByAlbum.has(albumId)) {
|
||||
groupedByAlbum.set(albumId, [])
|
||||
}
|
||||
|
||||
groupedByAlbum.get(albumId)!.push(result)
|
||||
}
|
||||
|
||||
const idxToAlbum = new Map<number, number>()
|
||||
for (const [idx, [id, tracks]] of iter.enumerate(groupedByAlbum.entries())) {
|
||||
idxToAlbum.set(idx, id)
|
||||
console.log(`${idx + 1}. ${tracks[0].artist.name} - ${tracks[0].album.title}`)
|
||||
for (const track of tracks) {
|
||||
console.log(` ${track.title}`)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('Enter number to download album art:')
|
||||
|
||||
const number = Number.parseInt(await question('[1] > ') || '1')
|
||||
|
||||
const artworkUrl = groupedByAlbum.get(idxToAlbum.get(number - 1)!)![0].album.cover_xl
|
||||
|
||||
await downloadFile(artworkUrl, args.filename ?? `assets/${query.replace(/\s/g, '_')}.jpg`)
|
Loading…
Add table
Add a link
Reference in a new issue