This commit is contained in:
		| @ -52,6 +52,8 @@ object Crunchyroll { | ||||
|         } | ||||
|     } | ||||
|     private const val baseUrl = "https://beta-api.crunchyroll.com" | ||||
|     private const val basicApiTokenUrl = "https://gitlab.com/-/snippets/2274956/raw/main/snippetfile1.txt" | ||||
|     private var basicApiToken: String = "" | ||||
|  | ||||
|     private lateinit var token: Token | ||||
|     private var tokenValidUntil: Long = 0 | ||||
| @ -64,6 +66,19 @@ object Crunchyroll { | ||||
|  | ||||
|     private val browsingCache = arrayListOf<Item>() | ||||
|  | ||||
|     /** | ||||
|      * Load the pai token, see: | ||||
|      * https://git.mosad.xyz/mosad/NonePublicIssues/issues/1 | ||||
|      * | ||||
|      * TODO handle empty file | ||||
|      */ | ||||
|     fun initBasicApiToken() = runBlocking { | ||||
|         withContext(Dispatchers.IO) { | ||||
|             basicApiToken = (client.get(basicApiTokenUrl) as HttpResponse).readText() | ||||
|             Log.i(TAG, "basic auth token: $basicApiToken") | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Login to the crunchyroll API. | ||||
|      * | ||||
| @ -85,7 +100,7 @@ object Crunchyroll { | ||||
|         withContext(Dispatchers.IO) { | ||||
|             // TODO handle exceptions | ||||
|             val response: HttpResponse = client.submitForm("$baseUrl$tokenEndpoint", formParameters = formData) { | ||||
|                 header("Authorization", "Basic ") | ||||
|                 header("Authorization", "Basic $basicApiToken") | ||||
|             } | ||||
|             token = response.receive() | ||||
|             tokenValidUntil = System.currentTimeMillis() + (token.expiresIn * 1000) | ||||
|  | ||||
| @ -137,6 +137,9 @@ class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListen | ||||
|             Preferences.load(this) | ||||
|             EncryptedPreferences.readCredentials(this) | ||||
|  | ||||
|             // always initialize the api token | ||||
|             Crunchyroll.initBasicApiToken() | ||||
|  | ||||
|             // show onboarding if no password is set, or login fails | ||||
|             if (EncryptedPreferences.password.isEmpty() || !Crunchyroll.login( | ||||
|                     EncryptedPreferences.login, | ||||
|  | ||||
		Reference in New Issue
	
	Block a user