@@ -18,6 +18,7 @@ import com.adamratzman.spotify.models.SpotifySearchResult
1818import com.adamratzman.spotify.models.Track
1919import com.adamratzman.spotify.models.serialization.toNonNullablePagingObject
2020import com.adamratzman.spotify.models.serialization.toNullablePagingObject
21+ import com.adamratzman.spotify.utils.Language
2122import com.adamratzman.spotify.utils.Market
2223import com.adamratzman.spotify.utils.encodeUrl
2324import com.adamratzman.spotify.utils.getSpotifyId
@@ -129,15 +130,16 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
129130 limit : Int? = api.spotifyApiOptions.defaultLimit,
130131 offset : Int? = null,
131132 market : Market ? = null,
132- includeExternal : Boolean? = null
133+ includeExternal : Boolean? = null,
134+ language : Language ? = null
133135 ): SpotifySearchResult {
134136 require(searchTypes.isNotEmpty()) { " At least one search type must be provided" }
135137 if (SearchType .Episode in searchTypes) {
136138 requireNotNull(market) { " Market must be provided when SearchType.EPISODE is requested" }
137139 }
138140
139141 val jsonString =
140- get(build(query, market, limit, offset, filters, * searchTypes, includeExternal = includeExternal))
142+ get(build(query, market, limit, offset, filters, * searchTypes, includeExternal = includeExternal, language = language ))
141143 val map = json.decodeFromString(MapSerializer (String .serializer(), JsonObject .serializer()), jsonString)
142144
143145 return SpotifySearchResult (
@@ -173,8 +175,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
173175 filters : List <SearchFilter > = listOf(),
174176 limit : Int? = api.spotifyApiOptions.defaultLimit,
175177 offset : Int? = null,
176- market : Market ? = null
177- ): PagingObject <SimplePlaylist > = get(build(query, market, limit, offset, filters, SearchType .Playlist ))
178+ market : Market ? = null,
179+ language : Language ? = null
180+ ): PagingObject <SimplePlaylist > = get(build(query, market, limit, offset, filters, SearchType .Playlist , language = language))
178181 .toNonNullablePagingObject(SimplePlaylist .serializer(), " playlists" , api, json)
179182
180183 /* *
@@ -199,8 +202,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
199202 filters : List <SearchFilter > = listOf(),
200203 limit : Int? = api.spotifyApiOptions.defaultLimit,
201204 offset : Int? = null,
202- market : Market ? = null
203- ): PagingObject <Artist > = get(build(query, market, limit, offset, filters, SearchType .Artist ))
205+ market : Market ? = null,
206+ language : Language ? = null
207+ ): PagingObject <Artist > = get(build(query, market, limit, offset, filters, SearchType .Artist , language = language))
204208 .toNonNullablePagingObject(Artist .serializer(), " artists" , api, json)
205209
206210 /* *
@@ -225,8 +229,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
225229 filters : List <SearchFilter > = listOf(),
226230 limit : Int? = api.spotifyApiOptions.defaultLimit,
227231 offset : Int? = null,
228- market : Market ? = null
229- ): PagingObject <SimpleAlbum > = get(build(query, market, limit, offset, filters, SearchType .Album ))
232+ market : Market ? = null,
233+ language : Language ? = null
234+ ): PagingObject <SimpleAlbum > = get(build(query, market, limit, offset, filters, SearchType .Album , language = language))
230235 .toNonNullablePagingObject(SimpleAlbum .serializer(), " albums" , api, json)
231236
232237 /* *
@@ -251,8 +256,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
251256 filters : List <SearchFilter > = listOf(),
252257 limit : Int? = api.spotifyApiOptions.defaultLimit,
253258 offset : Int? = null,
254- market : Market ? = null
255- ): PagingObject <Track > = get(build(query, market, limit, offset, filters, SearchType .Track ))
259+ market : Market ? = null,
260+ language : Language ? = null
261+ ): PagingObject <Track > = get(build(query, market, limit, offset, filters, SearchType .Track , language = language))
256262 .toNonNullablePagingObject(Track .serializer(), " tracks" , api, json)
257263
258264 /* *
@@ -277,8 +283,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
277283 filters : List <SearchFilter > = listOf(),
278284 limit : Int? = api.spotifyApiOptions.defaultLimit,
279285 offset : Int? = null,
280- market : Market
281- ): PagingObject <SimpleShow > = get(build(query, market, limit, offset, filters, SearchType .Show ))
286+ market : Market ,
287+ language : Language ? = null
288+ ): PagingObject <SimpleShow > = get(build(query, market, limit, offset, filters, SearchType .Show , language = language))
282289 .toNonNullablePagingObject(SimpleShow .serializer(), " shows" , api, json)
283290
284291 /* *
@@ -303,8 +310,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
303310 filters : List <SearchFilter > = listOf(),
304311 limit : Int? = api.spotifyApiOptions.defaultLimit,
305312 offset : Int? = null,
306- market : Market
307- ): PagingObject <SimpleEpisode > = get(build(query, market, limit, offset, filters, SearchType .Episode ))
313+ market : Market ,
314+ language : Language ? = null
315+ ): PagingObject <SimpleEpisode > = get(build(query, market, limit, offset, filters, SearchType .Episode , language = language))
308316 .toNonNullablePagingObject(SimpleEpisode .serializer(), " episodes" , api, json)
309317
310318 /* *
@@ -327,7 +335,8 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
327335 filters : List <SearchFilter > = listOf(),
328336 limit : Int? = api.spotifyApiOptions.defaultLimit,
329337 offset : Int? = null,
330- market : Market
338+ market : Market ,
339+ language : Language ? = null
331340 ): SpotifySearchResult =
332341 search(query, filters = filters, searchTypes = SearchType .values(), limit = limit, offset = offset, market = market)
333342
@@ -338,7 +347,8 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
338347 offset : Int? ,
339348 filters : List <SearchFilter > = listOf(),
340349 vararg types : SearchType ,
341- includeExternal : Boolean? = null
350+ includeExternal : Boolean? = null,
351+ language : Language ? = null
342352 ): String {
343353 val queryString = if (filters.isEmpty()) query
344354 else " $query ${filters.joinToString(" " ) { " ${it.filterType.id} :${it.filterValue} " }} "
@@ -347,6 +357,7 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
347357 .with (" q" , queryString.encodeUrl())
348358 .with (" type" , types.joinToString(" ," ) { it.id })
349359 .with (" market" , market?.getSpotifyId()).with (" limit" , limit).with (" offset" , offset)
360+ .with (" locale" , language?.name)
350361 .with (" include_external" , if (includeExternal == true ) " audio" else null ).toString()
351362 }
352363}
0 commit comments