Skip to content

Commit bb32849

Browse files
committed
remove :recommended suffix from spotify uri if exists
Signed-off-by: Adam Ratzman <[email protected]>
1 parent 52f92f2 commit bb32849

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/commonMain/kotlin/com.adamratzman.spotify/models/SpotifyUris.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public sealed class SpotifyUri(input: String, public val type: String, allowColo
107107
* Creates a abstract SpotifyUri of given input. Doesn't allow ambiguity by disallowing creation by id.
108108
* */
109109
public operator fun invoke(input: String): SpotifyUri {
110+
val inputUriModified = input.removeSuffix(":recommended")
111+
110112
val constructors = listOf(
111113
::ArtistUri,
112114
PlayableUri.Companion::invoke,
@@ -115,10 +117,10 @@ public sealed class SpotifyUri(input: String, public val type: String, allowColo
115117
::PlaylistUri
116118
)
117119
for (ctor in constructors) {
118-
safeInitiate(input, ctor)?.takeIf { it.uri == input }?.also { return it }
120+
safeInitiate(inputUriModified, ctor)?.takeIf { it.uri == inputUriModified }?.also { return it }
119121
}
120122

121-
throw SpotifyUriException("Illegal Spotify ID/URI: '$input' isn't convertible to any arbitrary id")
123+
throw SpotifyUriException("Illegal Spotify ID/URI: '$inputUriModified' isn't convertible to any arbitrary id")
122124
}
123125

124126
/**

0 commit comments

Comments
 (0)