update ktor to version 2.x #63
|
@ -74,7 +74,8 @@ dependencies {
|
||||||
|
|
||||||
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"
|
||||||
implementation "io.ktor:ktor-client-serialization:$ktor_version"
|
implementation "io.ktor:ktor-client-content-negotiation:$ktor_version"
|
||||||
|
implementation "io.ktor:ktor-serialization-kotlinx-json:$ktor_version"
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.2'
|
testImplementation 'junit:junit:4.13.2'
|
||||||
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
|
||||||
|
|
|
@ -25,13 +25,13 @@ package org.mosad.teapod.parser.crunchyroll
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.call.*
|
import io.ktor.client.call.*
|
||||||
import io.ktor.client.features.*
|
import io.ktor.client.plugins.*
|
||||||
import io.ktor.client.features.json.*
|
import io.ktor.client.plugins.contentnegotiation.*
|
||||||
import io.ktor.client.features.json.serializer.*
|
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.request.forms.*
|
import io.ktor.client.request.forms.*
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
|
import io.ktor.serialization.kotlinx.json.*
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import kotlinx.serialization.SerializationException
|
import kotlinx.serialization.SerializationException
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
@ -41,14 +41,14 @@ import kotlinx.serialization.json.put
|
||||||
import org.mosad.teapod.preferences.EncryptedPreferences
|
import org.mosad.teapod.preferences.EncryptedPreferences
|
||||||
import org.mosad.teapod.preferences.Preferences
|
import org.mosad.teapod.preferences.Preferences
|
||||||
|
|
||||||
private val json = Json { ignoreUnknownKeys = true }
|
|
||||||
|
|
||||||
object Crunchyroll {
|
object Crunchyroll {
|
||||||
private val TAG = javaClass.name
|
private val TAG = javaClass.name
|
||||||
|
|
||||||
private val client = HttpClient {
|
private val client = HttpClient {
|
||||||
install(JsonFeature) {
|
install(ContentNegotiation) {
|
||||||
serializer = KotlinxSerializer(json)
|
json(Json {
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private const val baseUrl = "https://beta-api.crunchyroll.com"
|
private const val baseUrl = "https://beta-api.crunchyroll.com"
|
||||||
|
@ -77,7 +77,7 @@ object Crunchyroll {
|
||||||
*/
|
*/
|
||||||
fun initBasicApiToken() = runBlocking {
|
fun initBasicApiToken() = runBlocking {
|
||||||
withContext(Dispatchers.IO) {
|
withContext(Dispatchers.IO) {
|
||||||
basicApiToken = (client.get(basicApiTokenUrl) as HttpResponse).readText()
|
basicApiToken = client.get { url(basicApiTokenUrl) }.bodyAsText()
|
||||||
Log.i(TAG, "basic auth token: $basicApiToken")
|
Log.i(TAG, "basic auth token: $basicApiToken")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ object Crunchyroll {
|
||||||
val response: HttpResponse = client.submitForm("$baseUrl$tokenEndpoint", formParameters = formData) {
|
val response: HttpResponse = client.submitForm("$baseUrl$tokenEndpoint", formParameters = formData) {
|
||||||
header("Authorization", "Basic $basicApiToken")
|
header("Authorization", "Basic $basicApiToken")
|
||||||
}
|
}
|
||||||
token = response.receive()
|
token = response.body()
|
||||||
tokenValidUntil = System.currentTimeMillis() + (token.expiresIn * 1000)
|
tokenValidUntil = System.currentTimeMillis() + (token.expiresIn * 1000)
|
||||||
response.status
|
response.status
|
||||||
} catch (ex: ClientRequestException) {
|
} catch (ex: ClientRequestException) {
|
||||||
|
@ -155,10 +155,10 @@ object Crunchyroll {
|
||||||
|
|
||||||
// for json set body and content type
|
// for json set body and content type
|
||||||
if (bodyObject is JsonObject) {
|
if (bodyObject is JsonObject) {
|
||||||
body = bodyObject
|
setBody(bodyObject)
|
||||||
contentType(ContentType.Application.Json)
|
contentType(ContentType.Application.Json)
|
||||||
}
|
}
|
||||||
}
|
}.body()
|
||||||
|
|
||||||
response
|
response
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,8 +135,6 @@ class PlayerViewModel(application: Application) : AndroidViewModel(application)
|
||||||
currentPlayheads = Crunchyroll.playheads(episodeIDs)
|
currentPlayheads = Crunchyroll.playheads(episodeIDs)
|
||||||
}
|
}
|
||||||
).joinAll()
|
).joinAll()
|
||||||
|
|
||||||
|
|
||||||
Log.d(classTag, "meta: $mediaMeta")
|
Log.d(classTag, "meta: $mediaMeta")
|
||||||
|
|
||||||
setCurrentEpisode(episodeId)
|
setCurrentEpisode(episodeId)
|
||||||
|
|
|
@ -24,11 +24,12 @@ package org.mosad.teapod.util.metadb
|
||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.features.*
|
import io.ktor.client.call.*
|
||||||
import io.ktor.client.features.json.*
|
import io.ktor.client.plugins.*
|
||||||
import io.ktor.client.features.json.serializer.*
|
import io.ktor.client.plugins.contentnegotiation.*
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.http.*
|
import io.ktor.http.*
|
||||||
|
import io.ktor.serialization.kotlinx.json.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import kotlinx.serialization.decodeFromString
|
import kotlinx.serialization.decodeFromString
|
||||||
|
@ -40,8 +41,8 @@ object MetaDBController {
|
||||||
private const val repoUrl = "https://gitlab.com/Seil0/teapodmetadb/-/raw/main/crunchy/"
|
private const val repoUrl = "https://gitlab.com/Seil0/teapodmetadb/-/raw/main/crunchy/"
|
||||||
|
|
||||||
private val client = HttpClient {
|
private val client = HttpClient {
|
||||||
install(JsonFeature) {
|
install(ContentNegotiation) {
|
||||||
serializer = KotlinxSerializer(Json)
|
json()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +50,7 @@ object MetaDBController {
|
||||||
private var metaCacheList = arrayListOf<Meta>()
|
private var metaCacheList = arrayListOf<Meta>()
|
||||||
|
|
||||||
suspend fun list() = withContext(Dispatchers.IO) {
|
suspend fun list() = withContext(Dispatchers.IO) {
|
||||||
val raw: String = client.get("$repoUrl/list.json")
|
val raw: String = client.get("$repoUrl/list.json").body()
|
||||||
mediaList = Json.decodeFromString(raw)
|
mediaList = Json.decodeFromString(raw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ object MetaDBController {
|
||||||
|
|
||||||
private suspend fun getTVShowMetadataFromDB(crSeriesId: String): TVShowMeta? = withContext(Dispatchers.IO) {
|
private suspend fun getTVShowMetadataFromDB(crSeriesId: String): TVShowMeta? = withContext(Dispatchers.IO) {
|
||||||
return@withContext try {
|
return@withContext try {
|
||||||
val raw: String = client.get("$repoUrl/tv/$crSeriesId/media.json")
|
val raw: String = client.get("$repoUrl/tv/$crSeriesId/media.json").body()
|
||||||
val meta: TVShowMeta = Json.decodeFromString(raw)
|
val meta: TVShowMeta = Json.decodeFromString(raw)
|
||||||
metaCacheList.add(meta)
|
metaCacheList.add(meta)
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ package org.mosad.teapod.util.tmdb
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import io.ktor.client.*
|
import io.ktor.client.*
|
||||||
import io.ktor.client.call.*
|
import io.ktor.client.call.*
|
||||||
import io.ktor.client.features.json.*
|
import io.ktor.client.plugins.contentnegotiation.*
|
||||||
import io.ktor.client.features.json.serializer.*
|
|
||||||
import io.ktor.client.request.*
|
import io.ktor.client.request.*
|
||||||
import io.ktor.client.statement.*
|
import io.ktor.client.statement.*
|
||||||
|
import io.ktor.serialization.kotlinx.json.*
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.coroutineScope
|
import kotlinx.coroutines.coroutineScope
|
||||||
import kotlinx.coroutines.invoke
|
import kotlinx.coroutines.invoke
|
||||||
|
@ -46,10 +46,11 @@ import org.mosad.teapod.util.concatenate
|
||||||
class TMDBApiController {
|
class TMDBApiController {
|
||||||
private val classTag = javaClass.name
|
private val classTag = javaClass.name
|
||||||
|
|
||||||
private val json = Json { ignoreUnknownKeys = true }
|
|
||||||
private val client = HttpClient {
|
private val client = HttpClient {
|
||||||
install(JsonFeature) {
|
install(ContentNegotiation) {
|
||||||
serializer = KotlinxSerializer(json)
|
json(Json {
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +79,7 @@ class TMDBApiController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
response.receive<T>()
|
response.body<T>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = "1.7.10"
|
ext.kotlin_version = "1.7.10"
|
||||||
ext.ktor_version = "1.6.8"
|
ext.ktor_version = "2.1.0"
|
||||||
ext.exo_version = "2.17.1"
|
ext.exo_version = "2.17.1"
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
|
|
Loading…
Reference in New Issue