������my cover art
This commit is contained in:
parent
0a95b72051
commit
6359da85ea
4 changed files with 95 additions and 4 deletions
57
src/helper.ts
Normal file
57
src/helper.ts
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
import { z } from "zod";
|
||||
|
||||
export interface Song {
|
||||
title: string;
|
||||
artist: string;
|
||||
apiProvider: string;
|
||||
thumbnailUrl: string;
|
||||
link: string;
|
||||
}
|
||||
const songLinkShape = z.object({
|
||||
userCountry: z.string(),
|
||||
entitiesByUniqueId: z.record(
|
||||
z.string(),
|
||||
z.object({
|
||||
id: z.string(),
|
||||
type: z.string(),
|
||||
title: z.string(),
|
||||
thumbnailUrl: z.string(),
|
||||
apiProvider: z.string(),
|
||||
artistName: z.string(),
|
||||
})
|
||||
),
|
||||
linksByPlatform: z.record(
|
||||
z.string(),
|
||||
z.object({
|
||||
country: z.string(),
|
||||
url: z.string().url(),
|
||||
entityUniqueId: z.string(),
|
||||
}))
|
||||
});
|
||||
//i hate this
|
||||
export const preferredProviders = [
|
||||
"spotify",
|
||||
"deezer",
|
||||
"youtubeMusic"
|
||||
];
|
||||
|
||||
export function getSongOnPreferredProvider(json: any, link: string): Song | null {
|
||||
const song = songLinkShape.parse(json);
|
||||
for (const platform of preferredProviders) {
|
||||
if (!song.linksByPlatform[platform]) {
|
||||
console.log(`couldnt find song on ${platform}`)
|
||||
continue
|
||||
}
|
||||
const entityId = song.linksByPlatform[platform].entityUniqueId;
|
||||
const songInfo = song.entitiesByUniqueId[entityId]
|
||||
|
||||
return {
|
||||
title: songInfo.title,
|
||||
artist: songInfo.artistName,
|
||||
apiProvider: songInfo.apiProvider,
|
||||
thumbnailUrl: songInfo.thumbnailUrl,
|
||||
link
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue