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
46
scripts/media/itunes-art-fetcher.ts
Normal file
46
scripts/media/itunes-art-fetcher.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
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`)
|
Loading…
Add table
Add a link
Reference in a new issue