use iitunes api to stop depending on links
This commit is contained in:
parent
27b7f9b5f8
commit
da13cdf3e9
2 changed files with 44 additions and 46 deletions
|
|
@ -40,54 +40,51 @@ export default class PingCommand extends Command {
|
||||||
await interaction.followUp("user isnt listening to music");
|
await interaction.followUp("user isnt listening to music");
|
||||||
} else {
|
} else {
|
||||||
const track_metadata = meow.payload.listens[0].track_metadata
|
const track_metadata = meow.payload.listens[0].track_metadata
|
||||||
if (track_metadata.additional_info.origin_url) {
|
const paramsObj = {entity: "song", term: track_metadata.artist_name + " " + track_metadata.track_name};
|
||||||
const link = keepV(track_metadata.additional_info.origin_url)
|
const searchParams = new URLSearchParams(paramsObj);
|
||||||
|
const itunesinfo = (await (await fetch(`https://itunes.apple.com/search?${searchParams.toString()}`)).json()).results[0];
|
||||||
const preferredApi = getSongOnPreferredProvider(await fetch(`https://api.song.link/v1-alpha.1/links?url=${link}`).then(a => a.json()), link)
|
const link = itunesinfo.trackViewUrl
|
||||||
if (preferredApi) {
|
const songlink = await fetch(`https://api.song.link/v1-alpha.1/links?url=${link}`).then(a => a.json())
|
||||||
const embed = new EmbedBuilder()
|
const preferredApi = getSongOnPreferredProvider(songlink, link)
|
||||||
.setAuthor({
|
if (preferredApi) {
|
||||||
name: preferredApi.artist,
|
const embed = new EmbedBuilder()
|
||||||
})
|
.setAuthor({
|
||||||
.setTitle(preferredApi.title)
|
name: preferredApi.artist,
|
||||||
.setThumbnail(preferredApi.thumbnailUrl)
|
})
|
||||||
.setFooter({
|
.setTitle(preferredApi.title)
|
||||||
text: "amy jr",
|
.setThumbnail(preferredApi.thumbnailUrl)
|
||||||
});
|
.setFooter({
|
||||||
const nya = new ActionRowBuilder<ButtonBuilder>().addComponents(new ButtonBuilder().setURL(preferredApi.link).setLabel("link").setStyle(ButtonStyle.Link))
|
text: "amy jr",
|
||||||
await interaction.followUp({
|
|
||||||
components: [
|
|
||||||
nya
|
|
||||||
],
|
|
||||||
embeds: [embed]
|
|
||||||
});
|
});
|
||||||
return
|
const meow = Object.keys(songlink.linksByPlatform)
|
||||||
|
let message = ""
|
||||||
|
|
||||||
|
const nya: ActionRowBuilder<ButtonBuilder>[] = [];
|
||||||
|
let currentRow = new ActionRowBuilder<ButtonBuilder>();
|
||||||
|
|
||||||
|
for (const meowi of meow) {
|
||||||
|
if (currentRow.components.length >= 5) {
|
||||||
|
nya.push(currentRow);
|
||||||
|
currentRow = new ActionRowBuilder<ButtonBuilder>();
|
||||||
|
}
|
||||||
|
currentRow.addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setURL(songlink.linksByPlatform[meowi].url)
|
||||||
|
.setLabel(meowi)
|
||||||
|
.setStyle(ButtonStyle.Link)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (currentRow.components.length > 0) {
|
||||||
|
nya.push(currentRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
await interaction.followUp({
|
||||||
let hasURL = false;
|
components: nya,
|
||||||
if (track_metadata.additional_info.release_mbid) {
|
embeds: [embed]
|
||||||
const thing = await fetch(`https://coverartarchive.org/release/${track_metadata.additional_info.release_mbid}/front`, {
|
|
||||||
method: "HEAD",
|
|
||||||
redirect: "manual",
|
|
||||||
})
|
|
||||||
hasURL = thing.status === 307;
|
|
||||||
}
|
|
||||||
let embed = new EmbedBuilder()
|
|
||||||
.setAuthor({
|
|
||||||
name: track_metadata.artist_name,
|
|
||||||
})
|
|
||||||
.setTitle(track_metadata.track_name)
|
|
||||||
.setDescription("could not get additional info")
|
|
||||||
.setFooter({
|
|
||||||
text: "amy jr",
|
|
||||||
});
|
});
|
||||||
if (hasURL) {
|
} else {
|
||||||
embed.setThumbnail(`https://aart.yellows.ink/release/${track_metadata.additional_info.release_mbid}.webp`);
|
await interaction.followUp("what")
|
||||||
}
|
}
|
||||||
await interaction.followUp({
|
|
||||||
embeds: [embed],
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,9 @@ const songLinkShape = z.object({
|
||||||
export const preferredProviders = [
|
export const preferredProviders = [
|
||||||
"spotify",
|
"spotify",
|
||||||
"deezer",
|
"deezer",
|
||||||
"youtubeMusic"
|
"youtubeMusic",
|
||||||
|
"tidal",
|
||||||
|
"itunes"
|
||||||
];
|
];
|
||||||
|
|
||||||
export function getSongOnPreferredProvider(json: any, link: string): Song | null {
|
export function getSongOnPreferredProvider(json: any, link: string): Song | null {
|
||||||
|
|
@ -44,13 +46,12 @@ export function getSongOnPreferredProvider(json: any, link: string): Song | null
|
||||||
}
|
}
|
||||||
const entityId = song.linksByPlatform[platform].entityUniqueId;
|
const entityId = song.linksByPlatform[platform].entityUniqueId;
|
||||||
const songInfo = song.entitiesByUniqueId[entityId]
|
const songInfo = song.entitiesByUniqueId[entityId]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: songInfo.title,
|
title: songInfo.title,
|
||||||
artist: songInfo.artistName,
|
artist: songInfo.artistName,
|
||||||
apiProvider: songInfo.apiProvider,
|
apiProvider: songInfo.apiProvider,
|
||||||
thumbnailUrl: songInfo.thumbnailUrl,
|
thumbnailUrl: songInfo.thumbnailUrl,
|
||||||
link
|
link: song.linksByPlatform[platform].url,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue