add watchlist to home fragment
This commit is contained in:
@ -211,6 +211,30 @@ object Crunchyroll {
|
||||
} ?: NoneSearchResult
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a collection of series objects.
|
||||
* Note: episode objects are currently not supported
|
||||
*
|
||||
* @param objects The object IDs as list of Strings
|
||||
* @return A Collection of Panels
|
||||
*/
|
||||
suspend fun objects(objects: List<String>): Collection {
|
||||
val episodesEndpoint = "/cms/v2/DE/M3/crunchyroll/objects/${objects.joinToString(",")}"
|
||||
val parameters = listOf(
|
||||
"locale" to locale,
|
||||
"Signature" to signature,
|
||||
"Policy" to policy,
|
||||
"Key-Pair-Id" to keyPairID
|
||||
)
|
||||
|
||||
val result = request(episodesEndpoint, parameters)
|
||||
println(result.component1()?.obj()?.toString())
|
||||
|
||||
return result.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneCollection
|
||||
}
|
||||
|
||||
/**
|
||||
* series id == crunchyroll id?
|
||||
*/
|
||||
@ -273,7 +297,7 @@ object Crunchyroll {
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional media functions: watchlist, playhead
|
||||
* Additional media functions: watchlist (series), playhead
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -283,10 +307,10 @@ object Crunchyroll {
|
||||
* @return Boolean: ture if it was found, else false
|
||||
*/
|
||||
suspend fun isWatchlist(seriesId: String): Boolean {
|
||||
val watchlistEndpoint = "/content/v1/watchlist/$accountID/$seriesId"
|
||||
val watchlistSeriesEndpoint = "/content/v1/watchlist/$accountID/$seriesId"
|
||||
val parameters = listOf("locale" to locale)
|
||||
|
||||
val result = request(watchlistEndpoint, parameters)
|
||||
val result = request(watchlistSeriesEndpoint, parameters)
|
||||
// if needed implement parsing
|
||||
|
||||
return result.component1()?.obj()?.has(seriesId) ?: false
|
||||
@ -298,14 +322,14 @@ object Crunchyroll {
|
||||
* @param seriesId The crunchyroll series id of the media to check
|
||||
*/
|
||||
suspend fun postWatchlist(seriesId: String) {
|
||||
val watchlistEndpoint = "/content/v1/watchlist/$accountID"
|
||||
val watchlistPostEndpoint = "/content/v1/watchlist/$accountID"
|
||||
val parameters = listOf("locale" to locale)
|
||||
|
||||
val json = buildJsonObject {
|
||||
put("content_id", seriesId)
|
||||
}
|
||||
|
||||
requestPost(watchlistEndpoint, parameters, json.toString())
|
||||
requestPost(watchlistPostEndpoint, parameters, json.toString())
|
||||
}
|
||||
|
||||
/**
|
||||
@ -314,10 +338,10 @@ object Crunchyroll {
|
||||
* @param seriesId The crunchyroll series id of the media to check
|
||||
*/
|
||||
suspend fun deleteWatchlist(seriesId: String) {
|
||||
val watchlistEndpoint = "/content/v1/watchlist/$accountID/$seriesId"
|
||||
val watchlistDeleteEndpoint = "/content/v1/watchlist/$accountID/$seriesId"
|
||||
val parameters = listOf("locale" to locale)
|
||||
|
||||
requestDelete(watchlistEndpoint, parameters)
|
||||
requestDelete(watchlistDeleteEndpoint, parameters)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -327,4 +351,21 @@ object Crunchyroll {
|
||||
// implement
|
||||
}
|
||||
|
||||
/**
|
||||
* Listing functions: watchlist (list), up_next_account
|
||||
*/
|
||||
|
||||
suspend fun watchlist(n: Int = 20): Watchlist {
|
||||
val watchlistEndpoint = "/content/v1/$accountID/watchlist"
|
||||
val parameters = listOf("locale" to locale, "n" to n)
|
||||
|
||||
val watchlistResult = request(watchlistEndpoint, parameters)
|
||||
val list: ContinueWatchingList = watchlistResult.component1()?.obj()?.let {
|
||||
json.decodeFromString(it.toString())
|
||||
} ?: NoneContinueWatchingList
|
||||
|
||||
val objects = list.items.map{ it.panel.episodeMetadata.seriesId }
|
||||
return objects(objects)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,8 +15,18 @@ enum class SortBy(val str: String) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Search data type
|
||||
* search, browse, watchlist data types (all collections)
|
||||
*/
|
||||
@Serializable
|
||||
data class Collection(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("items") val items: List<Item>
|
||||
)
|
||||
|
||||
typealias SearchCollection = Collection
|
||||
typealias BrowseResult = Collection
|
||||
typealias Watchlist = Collection
|
||||
|
||||
@Serializable
|
||||
data class SearchResult(
|
||||
@SerialName("total") val total: Int,
|
||||
@ -24,17 +34,21 @@ data class SearchResult(
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SearchCollection(
|
||||
@SerialName("type") val type: String,
|
||||
@SerialName("items") val items: List<Item>
|
||||
data class ContinueWatchingList(
|
||||
@SerialName("total") val total: Int,
|
||||
@SerialName("items") val items: List<ContinueWatchingItem>
|
||||
)
|
||||
|
||||
val NoneSearchResult = SearchResult(0, emptyList())
|
||||
|
||||
|
||||
|
||||
@Serializable
|
||||
data class BrowseResult(val total: Int, val items: List<Item>)
|
||||
data class ContinueWatchingItem(
|
||||
@SerialName("panel") val panel: EpisodePanel,
|
||||
@SerialName("new") val new: Boolean,
|
||||
@SerialName("new_content") val newContent: Boolean,
|
||||
@SerialName("is_favorite") val isFavorite: Boolean,
|
||||
@SerialName("never_watched") val neverWatched: Boolean,
|
||||
@SerialName("completion_status") val completionStatus: Boolean,
|
||||
@SerialName("playhead") val playhead: Int,
|
||||
)
|
||||
|
||||
// the data class Item is used in browse and search
|
||||
// TODO rename to MediaPanel
|
||||
@ -49,8 +63,17 @@ data class Item(
|
||||
// TODO metadata etc.
|
||||
)
|
||||
|
||||
val NoneItem = Item("", "", "", "", "", Images(listOf(), listOf()))
|
||||
val NoneBrowseResult = BrowseResult(0, listOf())
|
||||
// EpisodePanel is used in ContinueWatchingItem
|
||||
@Serializable
|
||||
data class EpisodePanel(
|
||||
@SerialName("id") val id: String,
|
||||
@SerialName("title") val title: String,
|
||||
@SerialName("type") val type: String,
|
||||
@SerialName("channel_id") val channelId: String,
|
||||
@SerialName("description") val description: String,
|
||||
@SerialName("images") val images: Thumbnail,
|
||||
@SerialName("episode_metadata") val episodeMetadata: EpisodeMetadata,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Images(val poster_tall: List<List<Poster>>, val poster_wide: List<List<Poster>>)
|
||||
@ -59,6 +82,18 @@ data class Images(val poster_tall: List<List<Poster>>, val poster_wide: List<Lis
|
||||
@Serializable
|
||||
data class Poster(val height: Int, val width: Int, val source: String, val type: String)
|
||||
|
||||
@Serializable
|
||||
data class EpisodeMetadata(
|
||||
@SerialName("series_id") val seriesId: String,
|
||||
@SerialName("series_title") val seriesTitle: String,
|
||||
)
|
||||
|
||||
val NoneItem = Item("", "", "", "", "", Images(emptyList(), emptyList()))
|
||||
val NoneCollection = Collection(0, emptyList())
|
||||
val NoneSearchResult = SearchResult(0, emptyList())
|
||||
val NoneBrowseResult = BrowseResult(0, emptyList())
|
||||
val NoneContinueWatchingList = ContinueWatchingList(0, emptyList())
|
||||
|
||||
/**
|
||||
* Series data type
|
||||
*/
|
||||
|
Reference in New Issue
Block a user