Convert FembedExtractor to lib (#965)
This commit is contained in:
26
lib/fembed-extractor/build.gradle.kts
Normal file
26
lib/fembed-extractor/build.gradle.kts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
plugins {
|
||||||
|
id("com.android.library")
|
||||||
|
id("kotlinx-serialization") // for the DTO
|
||||||
|
kotlin("android")
|
||||||
|
}
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdk = AndroidConfig.compileSdk
|
||||||
|
|
||||||
|
defaultConfig {
|
||||||
|
minSdk = AndroidConfig.minSdk
|
||||||
|
targetSdk = AndroidConfig.targetSdk
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compileOnly(libs.kotlin.stdlib)
|
||||||
|
compileOnly(libs.kotlin.json)
|
||||||
|
compileOnly(libs.okhttp)
|
||||||
|
compileOnly(libs.aniyomi.lib)
|
||||||
|
}
|
||||||
|
// BUMPS: 0
|
2
lib/fembed-extractor/src/main/AndroidManifest.xml
Normal file
2
lib/fembed-extractor/src/main/AndroidManifest.xml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="eu.kanade.tachiyomi.lib.fembedextractor" />
|
@ -0,0 +1,28 @@
|
|||||||
|
package eu.kanade.tachiyomi.lib.fembedextractor
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.Video
|
||||||
|
import eu.kanade.tachiyomi.network.POST
|
||||||
|
import kotlinx.serialization.decodeFromString
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
|
||||||
|
class FembedExtractor(private val client: OkHttpClient) {
|
||||||
|
fun videosFromUrl(url: String, prefix: String = ""): List<Video> {
|
||||||
|
val videoApi = url.replace("/v/", "/api/source/")
|
||||||
|
val body = client.newCall(POST(videoApi)).execute()
|
||||||
|
.body?.string().orEmpty()
|
||||||
|
|
||||||
|
val jsonResponse = Json { ignoreUnknownKeys = true }
|
||||||
|
.decodeFromString<FembedResponse>(body)
|
||||||
|
|
||||||
|
return if (jsonResponse.success) {
|
||||||
|
jsonResponse.data.map {
|
||||||
|
val quality = ("Fembed:${it.label}").let {
|
||||||
|
if (prefix.isNotBlank()) "$prefix $it"
|
||||||
|
else it
|
||||||
|
}
|
||||||
|
Video(it.file, quality, it.file)
|
||||||
|
}
|
||||||
|
} else { emptyList<Video>() }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package eu.kanade.tachiyomi.lib.fembedextractor
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class FembedResponse(
|
||||||
|
val success: Boolean,
|
||||||
|
val data: List<FembedVideo> = emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data class FembedVideo(
|
||||||
|
val file: String,
|
||||||
|
val label: String
|
||||||
|
)
|
Reference in New Issue
Block a user