Skip to content

Commit

Permalink
chore(shuffle+): updated api (#1559)
Browse files Browse the repository at this point in the history
`hm://` protocol deprecated, used alternatives to fetch album's and artist's data.
  • Loading branch information
huhridge authored Mar 30, 2022
1 parent eb3adee commit a6966fb
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions Extensions/shuffle+.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@
return await fetchCollection();
case Spicetify.URI.Type.ARTIST:
if (playDiscography) {
return await fetchDiscography(uriObj.getBase62Id());
return await fetchDiscography(uri);
}
return await fetchArtist(uriObj.getBase62Id());
return await fetchArtist(uri);
case Spicetify.URI.Type.TRACK:
case Spicetify.URI.Type.EPISODE:
return [uri];
Expand Down Expand Up @@ -205,13 +205,8 @@
*/
const fetchAlbum = async (uri) => {
const arg = uri.split(":")[2];
const res = await Spicetify.CosmosAsync.get(`hm://album/v1/album-app/album/${arg}/desktop`);
const items = [];
for (const disc of res.discs) {
const availables = disc.tracks.filter((track) => track.playable);
items.push(...availables.map((track) => track.uri));
}
return items;
const res = await Spicetify.CosmosAsync.get(`https://api.spotify.com/v1/albums/${arg}`);
return res.tracks.items.map((item) => item.uri);
};

/**
Expand All @@ -227,26 +222,30 @@

/**
*
* @param {string} uriBase62
* @param {string} uri
* @returns {Promise<string[]>}
*/
const fetchArtist = async (uriBase62) => {
const res = await Spicetify.CosmosAsync.get(`hm://artist/v1/${uriBase62}/desktop?format=json`);
return res.top_tracks.tracks.map((item) => item.uri);
const fetchArtist = async (uri) => {
const res = await Spicetify.CosmosAsync.get(
`https://api-partner.spotify.com/pathfinder/v1/query?operationName=queryArtistOverview&variables=%7B%22uri%22%3A%22${uri}%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22433e28d1e949372d3ca3aa6c47975cff428b5dc37b12f5325d9213accadf770a%22%7D%7D`
);
return res.data.artist.discography.topTracks.items.map((item) => item.track.uri);
};

/**
*
* @param {string} uriBase62
* @param {string} uri
* @returns {Promise<string[]>}
*/
const fetchDiscography = async (uriBase62) => {
const fetchDiscography = async (uri) => {
Spicetify.showNotification(`Fetching albums list...`);
let res = await Spicetify.CosmosAsync.get(`hm://artist/v1/${uriBase62}/desktop?format=json`);
let albums = res.releases.albums.releases;
const res = await Spicetify.CosmosAsync.get(
`https://api-partner.spotify.com/pathfinder/v1/query?operationName=queryArtistOverview&variables=%7B%22uri%22%3A%22${uri}%22%7D&extensions=%7B%22persistedQuery%22%3A%7B%22version%22%3A1%2C%22sha256Hash%22%3A%22433e28d1e949372d3ca3aa6c47975cff428b5dc37b12f5325d9213accadf770a%22%7D%7D`
);
let albums = res.data.artist.discography.albums.items.map((items) => items.releases.items[0].uri);
const tracks = [];
for (const album of albums) {
tracks.push(...(await fetchAlbum(album.uri)));
tracks.push(...(await fetchAlbum(album)));
}
return tracks;
};
Expand Down

0 comments on commit a6966fb

Please sign in to comment.