This commit is contained in:
parent
ab660d0ae7
commit
a092c5b8be
|
@ -68,8 +68,8 @@ dependencies {
|
||||||
|
|
||||||
implementation 'com.github.bumptech.glide:glide:4.12.0'
|
implementation 'com.github.bumptech.glide:glide:4.12.0'
|
||||||
implementation 'jp.wasabeef:glide-transformations:4.3.0'
|
implementation 'jp.wasabeef:glide-transformations:4.3.0'
|
||||||
implementation 'com.afollestad.material-dialogs:core:3.3.0'
|
implementation 'com.afollestad.material-dialogs:core:3.3.0' // TODO remove once unused
|
||||||
implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0'
|
implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0' // TODO remove once unused
|
||||||
|
|
||||||
implementation "io.ktor:ktor-client-core:$ktor_version"
|
implementation "io.ktor:ktor-client-core:$ktor_version"
|
||||||
implementation "io.ktor:ktor-client-android:$ktor_version"
|
implementation "io.ktor:ktor-client-android:$ktor_version"
|
||||||
|
|
|
@ -52,6 +52,8 @@ object Crunchyroll {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private const val baseUrl = "https://beta-api.crunchyroll.com"
|
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 lateinit var token: Token
|
||||||
private var tokenValidUntil: Long = 0
|
private var tokenValidUntil: Long = 0
|
||||||
|
@ -64,6 +66,19 @@ object Crunchyroll {
|
||||||
|
|
||||||
private val browsingCache = arrayListOf<Item>()
|
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.
|
* Login to the crunchyroll API.
|
||||||
*
|
*
|
||||||
|
@ -85,7 +100,7 @@ object Crunchyroll {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
// TODO handle exceptions
|
// TODO handle exceptions
|
||||||
val response: HttpResponse = client.submitForm("$baseUrl$tokenEndpoint", formParameters = formData) {
|
val response: HttpResponse = client.submitForm("$baseUrl$tokenEndpoint", formParameters = formData) {
|
||||||
header("Authorization", "Basic ")
|
header("Authorization", "Basic $basicApiToken")
|
||||||
}
|
}
|
||||||
token = response.receive()
|
token = response.receive()
|
||||||
tokenValidUntil = System.currentTimeMillis() + (token.expiresIn * 1000)
|
tokenValidUntil = System.currentTimeMillis() + (token.expiresIn * 1000)
|
||||||
|
|
|
@ -137,6 +137,9 @@ class MainActivity : AppCompatActivity(), NavigationBarView.OnItemSelectedListen
|
||||||
Preferences.load(this)
|
Preferences.load(this)
|
||||||
EncryptedPreferences.readCredentials(this)
|
EncryptedPreferences.readCredentials(this)
|
||||||
|
|
||||||
|
// always initialize the api token
|
||||||
|
Crunchyroll.initBasicApiToken()
|
||||||
|
|
||||||
// show onboarding if no password is set, or login fails
|
// show onboarding if no password is set, or login fails
|
||||||
if (EncryptedPreferences.password.isEmpty() || !Crunchyroll.login(
|
if (EncryptedPreferences.password.isEmpty() || !Crunchyroll.login(
|
||||||
EncryptedPreferences.login,
|
EncryptedPreferences.login,
|
||||||
|
|
Loading…
Reference in New Issue