Newer
Older
return playlists_response.public_playlists.map(function (playlist) {
const image_uri = playlist.image_url
return new PlatformPlaylist({
id: new PlatformID(PLATFORM, id_from_uri(playlist.uri), plugin.config.id),
name: playlist.name,
author: new PlatformAuthorLink(
new PlatformID(PLATFORM, id_from_uri(playlist.owner_uri), plugin.config.id),
playlist.owner_name,
`${USER_URL_PREFIX}${id_from_uri(playlist.owner_uri)}`,
// TODO load the owner's image somehow
),
// TODO load the playlist creation or modificiation date somehow datetime?: number
url: `${PLAYLIST_URL_PREFIX}${id_from_uri(playlist.uri)}`,
// TODO load the video count somehow videoCount?: number
thumbnail: url_from_image_uri(image_uri)
})
})
}
//#endregion
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
function url_from_image_uri(image_uri: string) {
const match_result = image_uri.match(/^spotify:(image|mosaic):([0-9a-zA-Z:]*)$/)
if (match_result === null) {
throw new ScriptException("regex error")
}
const image_type: "image" | "mosaic" = match_result[1] as "image" | "mosaic"
if (image_type === undefined) {
throw new ScriptException("regex error")
}
const uri_id = match_result[2]
if (uri_id === undefined) {
throw new ScriptException("regex error")
}
switch (image_type) {
case "image":
return `https://i.scdn.co/image/${uri_id}`
case "mosaic":
return `https://mosaic.scdn.co/300/${uri_id.split(":").join("")}`
default:
throw assert_exhaustive(image_type)
}
}
function id_from_uri(uri: string): string {
const match_result = uri.match(/^spotify:(show|album|track|artist|playlist|section|episode|user):([0-9a-zA-Z]*)$/)
if (match_result === null) {
throw new ScriptException("regex error")
}
const uri_id = match_result[2]
if (uri_id === undefined) {
throw new ScriptException("regex error")
}
return uri_id
}
/**
* Converts seconds to the timestamp format used in WebVTT
* @param seconds
* @returns
*/
function milliseconds_to_WebVTT_timestamp(milliseconds: number) {
return new Date(milliseconds).toISOString().substring(11, 23)
}
function assert_never(value: never) {
log(value)
}
function log_passthrough<T>(value: T): T {
log(value)
return value
}
function assert_exhaustive(value: never): void
function assert_exhaustive(value: never, exception_message: string): ScriptException
function assert_exhaustive(value: never, exception_message?: string): ScriptException | undefined {
log(["Spotify log:", value])
if (exception_message !== undefined) {
return new ScriptException(exception_message)
}
return
}
//#endregion
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
// https://open.spotifycdn.com/cdn/build/web-player/vendor~web-player.391a2438.js
const Z = "0123456789abcdef"
const Q = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const ee: string[] = []
ee.length = 256
for (let ke = 0; ke < 256; ke++)
// @ts-expect-error
ee[ke] = Z[ke >> 4] + Z[15 & ke]
const te: number[] = []
te.length = 128
for (let ke = 0; ke < Q.length; ++ke)
te[Q.charCodeAt(ke)] = ke
function get_gid(song_uri_id: string) {
return 22 === song_uri_id.length ? function (e) {
if (22 !== e.length)
return null
const t = 2.3283064365386963e-10
, n = 4294967296
, i = 238328
let o, r, a, s, c
// @ts-expect-error
return o = 56800235584 * te[e.charCodeAt(0)] + 916132832 * te[e.charCodeAt(1)] + 14776336 * te[e.charCodeAt(2)] + 238328 * te[e.charCodeAt(3)] + 3844 * te[e.charCodeAt(4)] + 62 * te[e.charCodeAt(5)] + te[e.charCodeAt(6)],
r = o * t | 0,
o -= r * n,
// @ts-expect-error
c = 3844 * te[e.charCodeAt(7)] + 62 * te[e.charCodeAt(8)] + te[e.charCodeAt(9)],
o = o * i + c,
o -= (c = o * t | 0) * n,
r = r * i + c,
// @ts-expect-error
c = 3844 * te[e.charCodeAt(10)] + 62 * te[e.charCodeAt(11)] + te[e.charCodeAt(12)],
o = o * i + c,
o -= (c = o * t | 0) * n,
r = r * i + c,
r -= (c = r * t | 0) * n,
a = c,
// @ts-expect-error
c = 3844 * te[e.charCodeAt(13)] + 62 * te[e.charCodeAt(14)] + te[e.charCodeAt(15)],
o = o * i + c,
o -= (c = o * t | 0) * n,
r = r * i + c,
r -= (c = r * t | 0) * n,
a = a * i + c,
// @ts-expect-error
c = 3844 * te[e.charCodeAt(16)] + 62 * te[e.charCodeAt(17)] + te[e.charCodeAt(18)],
o = o * i + c,
o -= (c = o * t | 0) * n,
r = r * i + c,
r -= (c = r * t | 0) * n,
a = a * i + c,
a -= (c = a * t | 0) * n,
s = c,
// @ts-expect-error
c = 3844 * te[e.charCodeAt(19)] + 62 * te[e.charCodeAt(20)] + te[e.charCodeAt(21)],
o = o * i + c,
o -= (c = o * t | 0) * n,
r = r * i + c,
r -= (c = r * t | 0) * n,
a = a * i + c,
a -= (c = a * t | 0) * n,
s = s * i + c,
s -= (c = s * t | 0) * n,
// @ts-expect-error
c ? null : ee[s >>> 24] + ee[s >>> 16 & 255] + ee[s >>> 8 & 255] + ee[255 & s] + ee[a >>> 24] + ee[a >>> 16 & 255] + ee[a >>> 8 & 255] + ee[255 & a] + ee[r >>> 24] + ee[r >>> 16 & 255] + ee[r >>> 8 & 255] + ee[255 & r] + ee[o >>> 24] + ee[o >>> 16 & 255] + ee[o >>> 8 & 255] + ee[255 & o]
}(song_uri_id) : song_uri_id
}
// export statements are removed during build step
// used for unit testing in SpotifyScript.test.ts
// export {
get_gid,
assert_never,
log_passthrough