implement index call
index is needed to retrieve identifiers necessary for streaming
This commit is contained in:
		| @ -21,6 +21,10 @@ object Crunchyroll { | ||||
|     private var accessToken = "" | ||||
|     private var tokenType = "" | ||||
|  | ||||
|     private var policy = "" | ||||
|     private var signature = "" | ||||
|     private var keyPairID = "" | ||||
|  | ||||
|     fun login(username: String, password: String): Boolean = runBlocking { | ||||
|         val tokenEndpoint = "/auth/v1/token" | ||||
|  | ||||
| @ -40,6 +44,7 @@ object Crunchyroll { | ||||
|                 ) | ||||
|                 .responseJson() | ||||
|  | ||||
|             // TODO fix JSONException: No value for | ||||
|             result.component1()?.obj()?.let { | ||||
|                 accessToken = it.get("access_token").toString() | ||||
|                 tokenType = it.get("token_type").toString() | ||||
| @ -76,6 +81,14 @@ object Crunchyroll { | ||||
|  | ||||
|  | ||||
|     // TODO sort_by, default alphabetical, n, locale de-DE, categories | ||||
|     /** | ||||
|      * Browse the media available on crunchyroll. | ||||
|      * | ||||
|      * @param sortBy | ||||
|      * @param n Number of items to return, defaults to 10 | ||||
|      * | ||||
|      * @return A **[BrowseResult]** object is returned. | ||||
|      */ | ||||
|     suspend fun browse(sortBy: SortBy = SortBy.ALPHABETICAL, n: Int = 10): BrowseResult { | ||||
|         val browseEndpoint = "/content/v1/browse" | ||||
|         val parameters = listOf("sort_by" to sortBy.str, "n" to n) | ||||
| @ -85,7 +98,7 @@ object Crunchyroll { | ||||
| //        val browseResult = json.decodeFromString<BrowseResult>(result.component1()?.obj()?.toString()!!) | ||||
| //        println(browseResult.items.size) | ||||
|  | ||||
|         return json.decodeFromString<BrowseResult>(result.component1()?.obj()?.toString()!!) | ||||
|         return json.decodeFromString(result.component1()?.obj()?.toString()!!) | ||||
|     } | ||||
|  | ||||
|     // TODO | ||||
| @ -100,4 +113,23 @@ object Crunchyroll { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Retrieve the identifiers necessary for streaming. If the identifiers are | ||||
|      * retrieved, set the corresponding global var. The identifiers are valid for 24h. | ||||
|      */ | ||||
|     suspend fun index() { | ||||
|         val indexEndpoint = "/index/v2" | ||||
|         val result = request(indexEndpoint) | ||||
|  | ||||
|         result.component1()?.obj()?.getJSONObject("cms")?.let { | ||||
|             policy = it.get("policy").toString() | ||||
|             signature = it.get("signature").toString() | ||||
|             keyPairID = it.get("key_pair_id").toString() | ||||
|         } | ||||
|  | ||||
|         println("policy: $policy") | ||||
|         println("signature: $signature") | ||||
|         println("keyPairID: $keyPairID") | ||||
|     } | ||||
|  | ||||
| } | ||||
| @ -152,7 +152,8 @@ class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListen | ||||
|                 showOnboarding() | ||||
|             } else { | ||||
|                 Crunchyroll.login(EncryptedPreferences.login, EncryptedPreferences.password) | ||||
|                 //runBlocking { Crunchyroll.browse() } | ||||
|                 runBlocking { Crunchyroll.browse() } | ||||
|                 runBlocking { Crunchyroll.index() } | ||||
|             } | ||||
|  | ||||
|  | ||||
|  | ||||
		Reference in New Issue
	
	Block a user