| @ -34,7 +34,6 @@ import io.ktor.http.* | ||||
| import io.ktor.serialization.* | ||||
| import io.ktor.serialization.kotlinx.json.* | ||||
| import kotlinx.coroutines.* | ||||
| import kotlinx.serialization.decodeFromString | ||||
| import kotlinx.serialization.json.Json | ||||
| import kotlinx.serialization.json.JsonObject | ||||
| import kotlinx.serialization.json.buildJsonObject | ||||
| @ -261,6 +260,8 @@ object Crunchyroll { | ||||
|     /** | ||||
|      * Browse the media available on crunchyroll. | ||||
|      * | ||||
|      * TODO migrate to v2 | ||||
|      * | ||||
|      * @param sortBy | ||||
|      * @param n Number of items to return, defaults to 10 | ||||
|      * | ||||
| @ -352,22 +353,22 @@ object Crunchyroll { | ||||
|      * Note: episode objects are currently not supported | ||||
|      * | ||||
|      * @param objects The object IDs as list of Strings | ||||
|      * @param ratings the user rating of the object | ||||
|      * @return A **[Collection]** of Panels | ||||
|      */ | ||||
|     suspend fun objects(objects: List<String>): Collection<Item> { | ||||
|         val episodesEndpoint = "/cms/v2/DE/M3/crunchyroll/objects/${objects.joinToString(",")}" | ||||
|     suspend fun objects(objects: List<String>, ratings: Boolean = false): Collection2<Item> { | ||||
|         val episodesEndpoint = "/content/v2/cms/objects/${objects.joinToString(",")}" | ||||
|         val parameters = listOf( | ||||
|             "locale" to Preferences.preferredSubtitleLocale.toLanguageTag(), | ||||
|             "Signature" to signature, | ||||
|             "Policy" to policy, | ||||
|             "Key-Pair-Id" to keyPairID | ||||
|             "ratings" to ratings, | ||||
|             "preferred_audio_language" to Preferences.preferredAudioLocale.toLanguageTag(), | ||||
|             "locale" to Preferences.preferredSubtitleLocale.toLanguageTag() | ||||
|         ) | ||||
|  | ||||
|         return try { | ||||
|             requestGet(episodesEndpoint, parameters) | ||||
|         } catch (ex: Exception) { | ||||
|             Log.e(TAG, "Exception in objects().", ex) | ||||
|             NoneCollection | ||||
|             NoneCollection2 | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -658,7 +659,7 @@ object Crunchyroll { | ||||
|      * @param n Number of items to return, defaults to 20. | ||||
|      * @return A **[Collection]** containing up to n **[Item]**. | ||||
|      */ | ||||
|     suspend fun watchlist(n: Int = 20): Collection<Item> { | ||||
|     suspend fun watchlist(n: Int = 20): Collection2<Item> { | ||||
|         val watchlistEndpoint = "/content/v2/discover/$accountID/watchlist" | ||||
|         val parameters = listOf( | ||||
|             "locale" to Preferences.preferredSubtitleLocale.toLanguageTag(), | ||||
|  | ||||
| @ -222,6 +222,7 @@ data class EpisodeMetadata( | ||||
| ) | ||||
|  | ||||
| val NoneCollection = Collection<Item>(0, emptyList()) | ||||
| val NoneCollection2 = Collection2<Item>(0, emptyList()) | ||||
| val NoneSearchResult = SearchResult(0, emptyList()) | ||||
| val NoneBrowseResult = BrowseResult(0, emptyList()) | ||||
| val NoneSimilarToResult = SimilarToResult(0, emptyList()) | ||||
|  | ||||
| @ -67,7 +67,7 @@ class HomeViewModel : ViewModel()  { | ||||
|             try { | ||||
|                 // run the loading in parallel to speed up the process | ||||
|                 val upNextJob = viewModelScope.async { Crunchyroll.upNextAccount().data } | ||||
|                 val watchlistJob = viewModelScope.async { Crunchyroll.watchlist(WATCHLIST_LENGTH).items } | ||||
|                 val watchlistJob = viewModelScope.async { Crunchyroll.watchlist(WATCHLIST_LENGTH).data } | ||||
|                 val recommendationsJob = viewModelScope.async { | ||||
|                     Crunchyroll.recommendations(20).items | ||||
|                 } | ||||
| @ -114,7 +114,7 @@ class HomeViewModel : ViewModel()  { | ||||
|                     } | ||||
|  | ||||
|                     // update the watchlist after a item has been added/removed | ||||
|                     val watchlistItems = Crunchyroll.watchlist(WATCHLIST_LENGTH).items | ||||
|                     val watchlistItems = Crunchyroll.watchlist(WATCHLIST_LENGTH).data | ||||
|  | ||||
|                     currentUiState.copy( | ||||
|                         watchlistItems = watchlistItems, | ||||
|  | ||||
| @ -42,6 +42,12 @@ fun Collection<Item>.toItemMediaList(): List<ItemMedia> { | ||||
|     } | ||||
| } | ||||
|  | ||||
| fun Collection2<Item>.toItemMediaList(): List<ItemMedia> { | ||||
|     return this.data.map { | ||||
|         ItemMedia(it.id, it.title, it.images.poster_wide[0][0].source) | ||||
|     } | ||||
| } | ||||
|  | ||||
| @JvmName("toItemMediaListItem") | ||||
| fun List<Item>.toItemMediaList(): List<ItemMedia> { | ||||
|     return this.map { | ||||
|  | ||||
		Reference in New Issue
	
	Block a user