URI
Spicetify.URI is Spotify’s own URI class, exposed by spicetify apply. The wrapper adds static parsers, creators and type checks to it. In a module, use client.uri.
A Spotify URI has the form spotify:<type>:<id>, where <id> is a base62 identifier. The matching web link is https://open.spotify.com/<type>/<id>.
class URI { constructor(type: string, props: any); type: string; hasBase62Id: boolean; id?: string; context?: string | URI | null; username?: string; query?: string; anchor?: string;
toURI(): string; toString(): string; toURLPath(opt_leadingSlash: boolean): string; toURL(origin?: string): string; clone(): URI | null; getPath(): string;
static Type: Record<string, string>; static from(value: any): URI | null; static fromString(uri: string): URI; static isSameIdentity(baseUri: URI | string, refUri: URI | string): boolean; static idToHex(id: string): string; static hexToId(hex: string): string;}Which other properties an instance has depends on its type. type is one of the URI.Type values.
Instance methods
Every URI instance has these methods.
toURIandtoStringreturn the URI string, including query parameters such ascontext.toURLPathreturns the path insideopen.spotify.com. Passtrueto start it with a slash.toURLreturns the web link.origindefaults tohttps://open.spotify.com.clonereturns a copy.getPathreturns the URI without its query and hash.
const uri = new Spicetify.URI('track', { id: '6rqhFgbbKwnb9MLmUQDhG6', context: 'spotify:album:1Je1IMUlBXcx1Fz0WE7oPT',});
uri.getPath(); // "spotify:track:6rqhFgbbKwnb9MLmUQDhG6"Static methods
These methods are on the Spicetify.URI class itself.
fromparses a URI string, a web link or aURIinstance, and returnsnullwhen it cannot parse the value.fromStringparses a string and throws aTypeErrorfor any other value.isSameIdentityreturnstruewhen both URIs point to the same item.idToHexconverts a 22 character base62 ID to 32 hex characters, andhexToIdconverts it back.Typemaps each type name to its value, soSpicetify.URI.Type.TRACKis"track".
const parsed = Spicetify.URI.from('https://open.spotify.com/track/6rqhFgbbKwnb9MLmUQDhG6');parsed?.type === Spicetify.URI.Type.TRACK; // trueThe wrapper also adds two families of functions, named after the keys of Type:
- A check for every type, such as
isTrackandisPlaylistV2, plusisPlaylistV1OrV2. See Validation functions. - A creator such as
trackURI,albumURIorplaylistV2URIfor each type where Spotify ships one.
Almost every playlist has the playlist-v2 type, so check playlists with isPlaylistV1OrV2.
Spicetify.URI.isAlbum('spotify:album:1Je1IMUlBXcx1Fz0WE7oPT'); // true