Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Fix rating tracks on the album page
Browse files Browse the repository at this point in the history
  • Loading branch information
duffey committed Jun 26, 2023
1 parent bda6b9c commit c77fbfc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/star-ratings.js

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ export async function createFolder(name) {
await Spicetify.Platform.RootlistAPI.createFolder(name, { before: "" });
}

export async function getAlbum(albumId) {
return await Spicetify.CosmosAsync.get(`wg://album/v1/album-app/album/${albumId}/desktop`);
export async function getAlbum(uri) {
const { queryAlbumTracks } = Spicetify.GraphQL.Definitions;
const { data, errors } = await Spicetify.GraphQL.Request(queryAlbumTracks, { uri, offset: 0, limit: 500 });
return data;
}

export async function getContents() {
Expand Down Expand Up @@ -75,6 +77,7 @@ export async function deleteTrackFromPlaylist(playlistUri, trackUri) {

export async function getPlaylistItems(uri) {
const result = await Spicetify.CosmosAsync.get(`sp://core-playlist/v1/playlist/${uri}`);
console.log("PLAYLIST RESULT", result);
return result.items;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ async function updateAlbumStars() {
albumId = isAlbumPage();
albumStarData[0].style.display = albumId ? "flex" : "none";
if (!albumId) return;
album = await api.getAlbum(albumId);
album = await api.getAlbum(`spotify:album:${albumId}`);
updateAlbumRating();
}

Expand Down
6 changes: 3 additions & 3 deletions src/ratings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ export async function deleteLowestRatings(playlistUris, ratings) {
}

export function getAlbumRating(ratings, album) {
const tracks = album.discs[0].tracks;
const items = album.albumUnion.tracks.items;
let sumRatings = 0.0;
let numRatings = 0;
for (const track of tracks) {
const rating = ratings[track.uri];
for (const item of items) {
const rating = ratings[item.track.uri];
if (!rating) continue;
sumRatings += parseFloat(rating);
numRatings += 1;
Expand Down

0 comments on commit c77fbfc

Please sign in to comment.