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
63
scripts/media/itunes-artist-art-fetcher.ts
Normal file
63
scripts/media/itunes-artist-art-fetcher.ts
Normal file
|
@ -0,0 +1,63 @@
|
|||
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: ')
|
||||
|
||||
const data = await ffetch('https://itunes.apple.com/search', {
|
||||
query: {
|
||||
term: query,
|
||||
entity: 'musicArtist',
|
||||
limit: 15,
|
||||
},
|
||||
}).parsedJson(z.object({
|
||||
results: z.array(z.object({
|
||||
wrapperType: z.literal('artist'),
|
||||
artistName: z.string(),
|
||||
artistLinkUrl: z.string(),
|
||||
primaryGenreName: z.string().default('Unknown'),
|
||||
}).passthrough()),
|
||||
}))
|
||||
|
||||
for (const [i, result] of iter.enumerate(data.results)) {
|
||||
console.log(`${i + 1}. ${result.artistName} (${result.primaryGenreName})`)
|
||||
continue
|
||||
}
|
||||
|
||||
console.log('Enter number to download artist art:')
|
||||
|
||||
const number = Number.parseInt(await question('[1] > ') || '1')
|
||||
|
||||
const pageUrl = data.results[number - 1].artistLinkUrl
|
||||
const $ = await ffetch(pageUrl).cheerio()
|
||||
const pageData = JSON.parse($('#serialized-server-data').html()!)
|
||||
|
||||
const pageDataValidated = z.tuple([
|
||||
z.object({
|
||||
data: z.object({
|
||||
seoData: z.object({
|
||||
artworkUrl: z.string(),
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
]).parse(pageData)
|
||||
|
||||
// {w}x{h}{c}.{f}
|
||||
const artworkUrl = pageDataValidated[0].data.seoData.artworkUrl
|
||||
.replace('{w}', '2500')
|
||||
.replace('{h}', '2500')
|
||||
.replace('{c}', 'cc')
|
||||
.replace('{f}', 'jpg')
|
||||
|
||||
if (artworkUrl === '/assets/meta/apple-music.png') {
|
||||
console.log('No artwork available')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
await downloadFile(artworkUrl, args.filename ?? `assets/${query.replace(/\s/g, '_')}.jpg`)
|
Loading…
Add table
Add a link
Reference in a new issue