Skip to content

Commit

Permalink
fix(new-releases): use PlatformAPI to fetch podcasts
Browse files Browse the repository at this point in the history
Fixes #3149
  • Loading branch information
rxri committed Sep 7, 2024
1 parent 9d02e7f commit 8862426
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions CustomApps/new-releases/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,13 @@ class Grid extends react.Component {
}

render() {
const expFeatures = JSON.parse(localStorage.getItem("spicetify-exp-features") || "{}");
const isGlobalNav = expFeatures?.enableGlobalNavBar?.value !== "control";
const version = Spicetify.Platform.version.split(".").map((i) => Number.parseInt(i));

const tabBarMargin = {
marginTop: isGlobalNav || (version[0] === 1 && version[1] === 2 && version[2] >= 45) ? "60px" : "0px",
};
return react.createElement(
"section",
{
Expand All @@ -246,6 +253,7 @@ class Grid extends react.Component {
"div",
{
className: "new-releases-header",
style: tabBarMargin,
},
react.createElement("h1", null, Spicetify.Locale.get("new_releases")),
react.createElement(
Expand Down Expand Up @@ -318,14 +326,12 @@ async function getArtistEverything(artist) {
}

async function getPodcastList() {
const body = await CosmosAsync.get("sp://core-collection/unstable/@/list/shows/all?responseFormat=protobufJson");
return body.item ?? [];
const body = await Spicetify.Platform.LibraryAPI.getShows({ limit: 50000 });
return body.items ?? [];
}

async function getPodcastRelease(uri) {
const body = await CosmosAsync.get(`sp://core-show/v1/shows/${uri}?responseFormat=protobufJson`, {
policy: { list: { link: true, name: true, publishDate: true } },
});
const body = await Spicetify.Platform.ShowAPI.getContents(uri, { limit: 50000 });
return body.items;
}

Expand Down Expand Up @@ -372,28 +378,25 @@ async function fetchTracks() {
async function fetchPodcasts() {
const items = [];
const itemTypeStr = Spicetify.Locale.get("card.tag.episode");
for (const obj of await getPodcastList()) {
const podcast = obj.showMetadata;
const id = podcast.link.replace("spotify:show:", "");

const tracks = await getPodcastRelease(id);
for (const podcast of await getPodcastList()) {
const tracks = await getPodcastRelease(podcast.uri);
if (!tracks) continue;

for (const track of tracks) {
const time = new Date(track.episodeMetadata.publishDate * 1000);
const time = new Date(track.releaseDate.isoString);

if (today - time.getTime() > limitInMs) {
break;
}

items.push({
uri: track.episodeMetadata.link,
title: track.episodeMetadata.name,
uri: track.uri,
title: track.name,
artist: {
name: podcast.name,
uri: podcast.link,
uri: podcast.uri,
},
imageURL: podcast.covers.standardLink,
imageURL: track.coverArt.reduce((prev, curr) => (prev.width > curr.width ? prev : curr)).url,
time,
type: itemTypeStr,
});
Expand Down

0 comments on commit 8862426

Please sign in to comment.