mirror of
https://git.stupid.fish/teidesu/scripts.git
synced 2025-07-28 02:32:11 +10:00
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
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: ['entity', 'filename'],
|
|
})
|
|
|
|
const entity = args.entity ?? 'album'
|
|
const query = args._[0] ?? await question('Search query (Artist - Album): ')
|
|
|
|
const data = await ffetch('https://itunes.apple.com/search', {
|
|
query: {
|
|
term: query,
|
|
entity,
|
|
limit: 15,
|
|
},
|
|
}).parsedJson(z.object({
|
|
results: z.array(z.object({
|
|
kind: z.literal('song').optional(),
|
|
artistName: z.string(),
|
|
collectionName: z.string(),
|
|
artworkUrl100: z.string(),
|
|
releaseDate: z.string(),
|
|
trackName: z.string().optional(),
|
|
}).passthrough()),
|
|
}))
|
|
|
|
for (const [i, result] of iter.enumerate(data.results)) {
|
|
if (result.kind === 'song') {
|
|
console.log(`${i + 1}. ${result.artistName} - ${result.trackName} (${result.collectionName}, ${new Date(result.releaseDate).toLocaleDateString('ru-RU')})`)
|
|
continue
|
|
}
|
|
|
|
console.log(`${i + 1}. ${result.artistName} - ${result.collectionName} (${new Date(result.releaseDate).toLocaleDateString('ru-RU')})`)
|
|
}
|
|
|
|
console.log('Enter number to download album art:')
|
|
|
|
const number = Number.parseInt(await question('[1] > ') || '1')
|
|
|
|
const artworkUrl = data.results[number - 1].artworkUrl100.replace('100x100', '1500x1500')
|
|
|
|
await downloadFile(artworkUrl, args.filename ?? `assets/${query.replace(/\s/g, '_')}.jpg`)
|