@@ -18,6 +18,7 @@ import com.adamratzman.spotify.models.SpotifySearchResult
18
18
import com.adamratzman.spotify.models.Track
19
19
import com.adamratzman.spotify.models.serialization.toNonNullablePagingObject
20
20
import com.adamratzman.spotify.models.serialization.toNullablePagingObject
21
+ import com.adamratzman.spotify.utils.Language
21
22
import com.adamratzman.spotify.utils.Market
22
23
import com.adamratzman.spotify.utils.encodeUrl
23
24
import com.adamratzman.spotify.utils.getSpotifyId
@@ -129,15 +130,16 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
129
130
limit : Int? = api.spotifyApiOptions.defaultLimit,
130
131
offset : Int? = null,
131
132
market : Market ? = null,
132
- includeExternal : Boolean? = null
133
+ includeExternal : Boolean? = null,
134
+ language : Language ? = null
133
135
): SpotifySearchResult {
134
136
require(searchTypes.isNotEmpty()) { " At least one search type must be provided" }
135
137
if (SearchType .Episode in searchTypes) {
136
138
requireNotNull(market) { " Market must be provided when SearchType.EPISODE is requested" }
137
139
}
138
140
139
141
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 ))
141
143
val map = json.decodeFromString(MapSerializer (String .serializer(), JsonObject .serializer()), jsonString)
142
144
143
145
return SpotifySearchResult (
@@ -173,8 +175,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
173
175
filters : List <SearchFilter > = listOf(),
174
176
limit : Int? = api.spotifyApiOptions.defaultLimit,
175
177
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))
178
181
.toNonNullablePagingObject(SimplePlaylist .serializer(), " playlists" , api, json)
179
182
180
183
/* *
@@ -199,8 +202,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
199
202
filters : List <SearchFilter > = listOf(),
200
203
limit : Int? = api.spotifyApiOptions.defaultLimit,
201
204
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))
204
208
.toNonNullablePagingObject(Artist .serializer(), " artists" , api, json)
205
209
206
210
/* *
@@ -225,8 +229,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
225
229
filters : List <SearchFilter > = listOf(),
226
230
limit : Int? = api.spotifyApiOptions.defaultLimit,
227
231
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))
230
235
.toNonNullablePagingObject(SimpleAlbum .serializer(), " albums" , api, json)
231
236
232
237
/* *
@@ -251,8 +256,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
251
256
filters : List <SearchFilter > = listOf(),
252
257
limit : Int? = api.spotifyApiOptions.defaultLimit,
253
258
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))
256
262
.toNonNullablePagingObject(Track .serializer(), " tracks" , api, json)
257
263
258
264
/* *
@@ -277,8 +283,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
277
283
filters : List <SearchFilter > = listOf(),
278
284
limit : Int? = api.spotifyApiOptions.defaultLimit,
279
285
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))
282
289
.toNonNullablePagingObject(SimpleShow .serializer(), " shows" , api, json)
283
290
284
291
/* *
@@ -303,8 +310,9 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
303
310
filters : List <SearchFilter > = listOf(),
304
311
limit : Int? = api.spotifyApiOptions.defaultLimit,
305
312
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))
308
316
.toNonNullablePagingObject(SimpleEpisode .serializer(), " episodes" , api, json)
309
317
310
318
/* *
@@ -327,7 +335,8 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
327
335
filters : List <SearchFilter > = listOf(),
328
336
limit : Int? = api.spotifyApiOptions.defaultLimit,
329
337
offset : Int? = null,
330
- market : Market
338
+ market : Market ,
339
+ language : Language ? = null
331
340
): SpotifySearchResult =
332
341
search(query, filters = filters, searchTypes = SearchType .values(), limit = limit, offset = offset, market = market)
333
342
@@ -338,7 +347,8 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
338
347
offset : Int? ,
339
348
filters : List <SearchFilter > = listOf(),
340
349
vararg types : SearchType ,
341
- includeExternal : Boolean? = null
350
+ includeExternal : Boolean? = null,
351
+ language : Language ? = null
342
352
): String {
343
353
val queryString = if (filters.isEmpty()) query
344
354
else " $query ${filters.joinToString(" " ) { " ${it.filterType.id} :${it.filterValue} " }} "
@@ -347,6 +357,7 @@ public open class SearchApi(api: GenericSpotifyApi) : SpotifyEndpoint(api) {
347
357
.with (" q" , queryString.encodeUrl())
348
358
.with (" type" , types.joinToString(" ," ) { it.id })
349
359
.with (" market" , market?.getSpotifyId()).with (" limit" , limit).with (" offset" , offset)
360
+ .with (" locale" , language?.name)
350
361
.with (" include_external" , if (includeExternal == true ) " audio" else null ).toString()
351
362
}
352
363
}
0 commit comments