Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated shuffle+ to work 1.1.81 onwards #1559

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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