Skip to content

Commit 8862426

Browse files
committed
fix(new-releases): use PlatformAPI to fetch podcasts
Fixes #3149
1 parent 9d02e7f commit 8862426

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

CustomApps/new-releases/index.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ class Grid extends react.Component {
237237
}
238238

239239
render() {
240+
const expFeatures = JSON.parse(localStorage.getItem("spicetify-exp-features") || "{}");
241+
const isGlobalNav = expFeatures?.enableGlobalNavBar?.value !== "control";
242+
const version = Spicetify.Platform.version.split(".").map((i) => Number.parseInt(i));
243+
244+
const tabBarMargin = {
245+
marginTop: isGlobalNav || (version[0] === 1 && version[1] === 2 && version[2] >= 45) ? "60px" : "0px",
246+
};
240247
return react.createElement(
241248
"section",
242249
{
@@ -246,6 +253,7 @@ class Grid extends react.Component {
246253
"div",
247254
{
248255
className: "new-releases-header",
256+
style: tabBarMargin,
249257
},
250258
react.createElement("h1", null, Spicetify.Locale.get("new_releases")),
251259
react.createElement(
@@ -318,14 +326,12 @@ async function getArtistEverything(artist) {
318326
}
319327

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

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

@@ -372,28 +378,25 @@ async function fetchTracks() {
372378
async function fetchPodcasts() {
373379
const items = [];
374380
const itemTypeStr = Spicetify.Locale.get("card.tag.episode");
375-
for (const obj of await getPodcastList()) {
376-
const podcast = obj.showMetadata;
377-
const id = podcast.link.replace("spotify:show:", "");
378-
379-
const tracks = await getPodcastRelease(id);
381+
for (const podcast of await getPodcastList()) {
382+
const tracks = await getPodcastRelease(podcast.uri);
380383
if (!tracks) continue;
381384

382385
for (const track of tracks) {
383-
const time = new Date(track.episodeMetadata.publishDate * 1000);
386+
const time = new Date(track.releaseDate.isoString);
384387

385388
if (today - time.getTime() > limitInMs) {
386389
break;
387390
}
388391

389392
items.push({
390-
uri: track.episodeMetadata.link,
391-
title: track.episodeMetadata.name,
393+
uri: track.uri,
394+
title: track.name,
392395
artist: {
393396
name: podcast.name,
394-
uri: podcast.link,
397+
uri: podcast.uri,
395398
},
396-
imageURL: podcast.covers.standardLink,
399+
imageURL: track.coverArt.reduce((prev, curr) => (prev.width > curr.width ? prev : curr)).url,
397400
time,
398401
type: itemTypeStr,
399402
});

0 commit comments

Comments
 (0)