- Spotify playlist, library, album and artist browsing with in-app playback - Song, playlist and album downloads via spotdl with YouTube and Bandcamp fallbacks - Electron desktop app (castLabs Widevine) with a permanent sidebar layout - Linux and Windows packaging scripts
41 lines
1.0 KiB
TypeScript
41 lines
1.0 KiB
TypeScript
import superjson from "superjson";
|
|
|
|
export type SpotifyLibrarySection = "tracks" | "albums" | "artists" | "shows";
|
|
|
|
export type SpotifyLibraryItem = {
|
|
id: string;
|
|
type: "track" | "album" | "artist" | "show";
|
|
name: string;
|
|
subtitle?: string;
|
|
detail?: string;
|
|
imageUrl?: string;
|
|
externalUrl?: string;
|
|
uri?: string;
|
|
durationMs?: number;
|
|
addedAt?: string;
|
|
total?: number;
|
|
};
|
|
|
|
export type OutputType = {
|
|
section: SpotifyLibrarySection;
|
|
items: SpotifyLibraryItem[];
|
|
total?: number;
|
|
nextCursor?: string;
|
|
};
|
|
|
|
export async function getSpotifyLibrary(
|
|
section: SpotifyLibrarySection,
|
|
cursor?: string,
|
|
): Promise<OutputType> {
|
|
const params = new URLSearchParams({ section });
|
|
if (cursor) params.set("cursor", cursor);
|
|
const response = await fetch("/_api/spotify-library?" + params.toString(), {
|
|
cache: "no-store",
|
|
});
|
|
if (!response.ok) {
|
|
const parsed = superjson.parse<{ error: string }>(await response.text());
|
|
throw new Error(parsed.error);
|
|
}
|
|
return superjson.parse<OutputType>(await response.text());
|
|
}
|