add search for tv shows

media items are currently not selectable, the app will crash
This commit is contained in:
2021-12-27 22:50:29 +01:00
parent 63ce910ec5
commit 4fd6f9ca7e
8 changed files with 112 additions and 78 deletions

View File

@ -134,18 +134,20 @@ object Crunchyroll {
return browseResult
}
// // TODO locale de-DE, type
suspend fun search(query: String, n: Int = 10) {
/**
* TODO
*/
suspend fun search(query: String, n: Int = 10): SearchResult {
val searchEndpoint = "/content/v1/search"
val parameters = listOf("q" to query, "n" to n)
val parameters = listOf("q" to query, "n" to n, "locale" to locale, "type" to "series")
val result = request(searchEndpoint, parameters)
println("${result.component1()?.obj()?.get("total")}")
// TODO episodes have thumbnails as image, and not poster_tall/poster_tall,
// to work around this, for now only tv shows are supported
val test = json.decodeFromString<BrowseResult>(result.component1()?.obj()?.toString()!!)
println(test.items.size)
// TODO return
return result.component1()?.obj()?.let {
json.decodeFromString(it.toString())
} ?: NoneSearchResult
}
/**

View File

@ -13,9 +13,29 @@ enum class SortBy(val str: String) {
POPULARITY("popularity")
}
/**
* Search data type
*/
@Serializable
data class SearchResult(
@SerialName("total") val total: Int,
@SerialName("items") val items: List<SearchCollection>
)
@Serializable
data class SearchCollection(
@SerialName("type") val type: String,
@SerialName("items") val items: List<Item>
)
val NoneSearchResult = SearchResult(0, emptyList())
@Serializable
data class BrowseResult(val total: Int, val items: List<Item>)
// the data class Item is used in browse and search
@Serializable
data class Item(
val id: String,
@ -38,7 +58,7 @@ data class Images(val poster_tall: List<List<Poster>>, val poster_wide: List<Lis
data class Poster(val height: Int, val width: Int, val source: String, val type: String)
/**
* Series return type
* Series data type
*/
@Serializable
data class Series(