fix(lib): Fix chillx-extractor + refactorate tokuzilla (#2303)
This commit is contained in:
@ -19,9 +19,8 @@ class ChillxExtractor(private val client: OkHttpClient, private val headers: Hea
|
|||||||
private val playlistUtils by lazy { PlaylistUtils(client, headers) }
|
private val playlistUtils by lazy { PlaylistUtils(client, headers) }
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val KEY = "m4H6D9%0${'$'}N&F6rQ&"
|
private val REGEX_MASTER_JS by lazy { Regex("""JScript\s*=\s*'([^']+)""") }
|
||||||
|
private val REGEX_EVAL_KEY by lazy { Regex("""eval\(\S+\("(\S+)",\d+,"(\S+)",(\d+),(\d+),""") }
|
||||||
private val REGEX_MASTER_JS by lazy { Regex("""MasterJS\s*=\s*'([^']+)""") }
|
|
||||||
private val REGEX_SOURCES by lazy { Regex("""sources:\s*\[\{"file":"([^"]+)""") }
|
private val REGEX_SOURCES by lazy { Regex("""sources:\s*\[\{"file":"([^"]+)""") }
|
||||||
private val REGEX_FILE by lazy { Regex("""file: ?"([^"]+)"""") }
|
private val REGEX_FILE by lazy { Regex("""file: ?"([^"]+)"""") }
|
||||||
private val REGEX_SOURCE by lazy { Regex("""source = ?"([^"]+)"""")}
|
private val REGEX_SOURCE by lazy { Regex("""source = ?"([^"]+)"""")}
|
||||||
@ -37,7 +36,8 @@ class ChillxExtractor(private val client: OkHttpClient, private val headers: Hea
|
|||||||
|
|
||||||
val master = REGEX_MASTER_JS.find(body)?.groupValues?.get(1) ?: return emptyList()
|
val master = REGEX_MASTER_JS.find(body)?.groupValues?.get(1) ?: return emptyList()
|
||||||
val aesJson = json.decodeFromString<CryptoInfo>(master)
|
val aesJson = json.decodeFromString<CryptoInfo>(master)
|
||||||
val decryptedScript = decryptWithSalt(aesJson.ciphertext, aesJson.salt, KEY)
|
val key = getKey(body)
|
||||||
|
val decryptedScript = decryptWithSalt(aesJson.ciphertext, aesJson.salt, key)
|
||||||
.replace("\\n", "\n")
|
.replace("\\n", "\n")
|
||||||
.replace("\\", "")
|
.replace("\\", "")
|
||||||
|
|
||||||
@ -80,6 +80,24 @@ class ChillxExtractor(private val client: OkHttpClient, private val headers: Hea
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getKey(body: String): String {
|
||||||
|
val (encrypted, pass, offset, index) = REGEX_EVAL_KEY.find(body)!!.groupValues.drop(1)
|
||||||
|
val decrypted = decryptScript(encrypted, pass, offset.toInt(), index.toInt())
|
||||||
|
return decrypted.substringAfter("'").substringBefore("'")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun decryptScript(encrypted: String, pass: String, offset: Int, index: Int): String {
|
||||||
|
val trimmedPass = pass.substring(0, index)
|
||||||
|
val bits = encrypted.split(pass[index]).map { item ->
|
||||||
|
trimmedPass.foldIndexed(item) { index, acc, it ->
|
||||||
|
acc.replace(it.toString(), index.toString())
|
||||||
|
}
|
||||||
|
}.filter(String::isNotBlank)
|
||||||
|
|
||||||
|
return bits.joinToString("") { Char(it.toInt(index) - offset).toString() }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
data class CryptoInfo(
|
data class CryptoInfo(
|
||||||
@SerialName("ct")
|
@SerialName("ct")
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
apply plugin: 'com.android.application'
|
plugins {
|
||||||
apply plugin: 'kotlin-android'
|
alias(libs.plugins.android.application)
|
||||||
|
alias(libs.plugins.kotlin.android)
|
||||||
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
extName = 'Tokuzilla'
|
extName = 'Tokuzilla'
|
||||||
pkgNameSuffix = 'en.tokuzilla'
|
pkgNameSuffix = 'en.tokuzilla'
|
||||||
extClass = '.Tokuzilla'
|
extClass = '.Tokuzilla'
|
||||||
extVersionCode = 9
|
extVersionCode = 10
|
||||||
libVersion = '13'
|
libVersion = '13'
|
||||||
containsNsfw = false
|
containsNsfw = false
|
||||||
}
|
}
|
||||||
@ -14,4 +16,4 @@ dependencies {
|
|||||||
implementation(project(':lib-chillx-extractor'))
|
implementation(project(':lib-chillx-extractor'))
|
||||||
}
|
}
|
||||||
|
|
||||||
apply from: "$rootDir/common.gradle"
|
apply from: "$rootDir/common.gradle"
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package eu.kanade.tachiyomi.animeextension.en.tokuzilla
|
package eu.kanade.tachiyomi.animeextension.en.tokuzilla
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
import android.content.SharedPreferences
|
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.PreferenceScreen
|
import androidx.preference.PreferenceScreen
|
||||||
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
|
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
|
||||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
||||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
||||||
import eu.kanade.tachiyomi.animesource.model.AnimesPage
|
|
||||||
import eu.kanade.tachiyomi.animesource.model.SAnime
|
import eu.kanade.tachiyomi.animesource.model.SAnime
|
||||||
import eu.kanade.tachiyomi.animesource.model.SEpisode
|
import eu.kanade.tachiyomi.animesource.model.SEpisode
|
||||||
import eu.kanade.tachiyomi.animesource.model.Video
|
import eu.kanade.tachiyomi.animesource.model.Video
|
||||||
@ -32,101 +30,42 @@ class Tokuzilla : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
|
|
||||||
override val supportsLatest = false
|
override val supportsLatest = false
|
||||||
|
|
||||||
private val preferences: SharedPreferences by lazy {
|
private val preferences by lazy {
|
||||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ============================== Popular ===============================
|
// ============================== Popular ===============================
|
||||||
|
override fun popularAnimeSelector() = "div.col-sm-4.col-xs-12.item.post"
|
||||||
|
|
||||||
override fun popularAnimeSelector(): String = "div.col-sm-4.col-xs-12.item.post"
|
override fun popularAnimeRequest(page: Int) = GET("$baseUrl/page/$page")
|
||||||
|
|
||||||
override fun popularAnimeRequest(page: Int): Request {
|
override fun popularAnimeFromElement(element: Element) = SAnime.create().apply {
|
||||||
return GET("$baseUrl/page/$page")
|
element.selectFirst("a")!!.run {
|
||||||
}
|
setUrlWithoutDomain(attr("href"))
|
||||||
|
title = attr("title")
|
||||||
override fun popularAnimeFromElement(element: Element): SAnime {
|
|
||||||
val anime = SAnime.create()
|
|
||||||
anime.setUrlWithoutDomain(element.selectFirst("a")!!.attr("href").replace("https://tokuzilla.net", ""))
|
|
||||||
anime.thumbnail_url = element.selectFirst("img")!!.attr("src")
|
|
||||||
anime.title = element.selectFirst("a")!!.attr("title")
|
|
||||||
return anime
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun popularAnimeNextPageSelector(): String = "a.next.page-numbers"
|
|
||||||
|
|
||||||
// ============================== Episodes ==============================
|
|
||||||
|
|
||||||
override fun episodeListSelector() = throw Exception("not used")
|
|
||||||
|
|
||||||
override fun episodeListParse(response: Response): List<SEpisode> {
|
|
||||||
val document = response.asJsoup()
|
|
||||||
val episodeList = mutableListOf<SEpisode>()
|
|
||||||
val infoElement = document.selectFirst("ul.pagination.post-tape")
|
|
||||||
if (infoElement != null) {
|
|
||||||
infoElement.html().split("<a href=\"").drop(1).forEach {
|
|
||||||
val link = it.substringBefore("\"")
|
|
||||||
val episodeNumber = it.substringBefore("</a>").substringAfter(">")
|
|
||||||
val episode = SEpisode.create()
|
|
||||||
episode.setUrlWithoutDomain(link)
|
|
||||||
episode.episode_number = episodeNumber.toFloat()
|
|
||||||
episode.name = "Episode $episodeNumber"
|
|
||||||
episodeList.add(episode)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
val link = document.selectFirst("meta[property=og:url]")!!.attr("content")
|
|
||||||
val episode = SEpisode.create()
|
|
||||||
episode.setUrlWithoutDomain(link)
|
|
||||||
episode.episode_number = 1F
|
|
||||||
episode.name = "Movie"
|
|
||||||
episodeList.add(episode)
|
|
||||||
}
|
}
|
||||||
return episodeList.reversed()
|
thumbnail_url = element.selectFirst("img")!!.attr("src")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun episodeFromElement(element: Element): SEpisode = throw Exception("not used")
|
override fun popularAnimeNextPageSelector() = "a.next.page-numbers"
|
||||||
|
|
||||||
// ============================ Video Links =============================
|
// =============================== Latest ===============================
|
||||||
|
override fun latestUpdatesNextPageSelector() = throw Exception("not used")
|
||||||
|
|
||||||
override fun videoListParse(response: Response): List<Video> {
|
override fun latestUpdatesFromElement(element: Element) = throw Exception("not used")
|
||||||
val document = response.asJsoup()
|
|
||||||
val videoList = mutableListOf<Video>()
|
|
||||||
val frameLink = document.selectFirst("iframe[id=frame]")!!.attr("src")
|
|
||||||
val videos = ChillxExtractor(client, headers).videoFromUrl(frameLink, baseUrl)
|
|
||||||
if (videos != null) {
|
|
||||||
videoList.addAll(videos)
|
|
||||||
}
|
|
||||||
return videoList.reversed()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun List<Video>.sort(): List<Video> {
|
override fun latestUpdatesRequest(page: Int): Request = throw Exception("not used")
|
||||||
val quality = preferences.getString("preferred_quality", null)
|
|
||||||
if (quality != null) {
|
|
||||||
val newList = mutableListOf<Video>()
|
|
||||||
var preferred = 0
|
|
||||||
for (video in this) {
|
|
||||||
if (video.quality.contains(quality)) {
|
|
||||||
newList.add(preferred, video)
|
|
||||||
preferred++
|
|
||||||
} else {
|
|
||||||
newList.add(video)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newList
|
|
||||||
}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun videoListSelector() = throw Exception("not used")
|
override fun latestUpdatesSelector() = throw Exception("not used")
|
||||||
override fun videoFromElement(element: Element) = throw Exception("not used")
|
|
||||||
override fun videoUrlParse(document: Document) = throw Exception("not used")
|
override fun latestUpdatesParse(response: Response) = throw Exception("not used")
|
||||||
|
|
||||||
// =============================== Search ===============================
|
// =============================== Search ===============================
|
||||||
|
|
||||||
override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element)
|
override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element)
|
||||||
|
|
||||||
override fun searchAnimeNextPageSelector(): String = "a.next.page-numbers"
|
override fun searchAnimeNextPageSelector() = popularAnimeNextPageSelector()
|
||||||
|
|
||||||
override fun searchAnimeSelector(): String = "div.col-sm-4.col-xs-12.item"
|
override fun searchAnimeSelector() = popularAnimeSelector()
|
||||||
|
|
||||||
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
|
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
|
||||||
var url = baseUrl
|
var url = baseUrl
|
||||||
@ -167,59 +106,77 @@ class Tokuzilla : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// =========================== Anime Details ============================
|
// =========================== Anime Details ============================
|
||||||
override fun animeDetailsParse(document: Document): SAnime {
|
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
|
||||||
val anime = SAnime.create().apply {
|
val details = document.selectFirst("div.video-details")!!
|
||||||
genre = parseGenres(document.selectFirst("table")!!.html())
|
title = details.selectFirst("h1")!!.text()
|
||||||
description = document.selectFirst("p")!!.text()
|
thumbnail_url = details.selectFirst("img")?.run {
|
||||||
author = parseYear(document.selectFirst("table")!!.html())
|
absUrl("data-src").ifEmpty { absUrl("src") }
|
||||||
status = parseStatus(document.selectFirst("table")!!.text())
|
|
||||||
}
|
}
|
||||||
return anime
|
genre = details.select("span.meta > a").eachText().joinToString().takeIf(String::isNotBlank)
|
||||||
}
|
description = document.selectFirst("h2#plot + p")!!.text()
|
||||||
|
author = details.selectFirst("th:contains(Year) + td")?.text()?.let { "Year $it" }
|
||||||
private fun parseGenres(genreString: String): String {
|
status = details.selectFirst("th:contains(Status) + td")?.text().orEmpty().let {
|
||||||
val genres = buildString {
|
when {
|
||||||
genreString.split("<a href=").drop(1).dropLast(1).forEach {
|
it.contains("Ongoing") -> SAnime.ONGOING
|
||||||
append(it.substringAfter("rel=\"tag\">").substringBefore("</a>"))
|
it.contains("Complete") -> SAnime.COMPLETED
|
||||||
append(", ")
|
else -> SAnime.UNKNOWN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return genres.dropLast(2)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parseYear(yearString: String): String {
|
// ============================== Episodes ==============================
|
||||||
return "Year " + yearString.substringAfter("Year").substring(47, 51)
|
override fun episodeListSelector() = "ul.pagination.post-tape a"
|
||||||
}
|
override fun episodeListParse(response: Response): List<SEpisode> {
|
||||||
|
val document = response.use { it.asJsoup() }
|
||||||
|
|
||||||
private fun parseStatus(statusString: String): Int {
|
val episodes = document.select(episodeListSelector())
|
||||||
return if (statusString.contains("Ongoing")) {
|
return if (episodes.isNotEmpty()) {
|
||||||
SAnime.ONGOING
|
episodes.map {
|
||||||
|
SEpisode.create().apply {
|
||||||
|
setUrlWithoutDomain(it.attr("href"))
|
||||||
|
val epNum = it.text()
|
||||||
|
name = "Episode $epNum"
|
||||||
|
episode_number = epNum.toFloatOrNull() ?: 1F
|
||||||
|
}
|
||||||
|
}.reversed()
|
||||||
} else {
|
} else {
|
||||||
SAnime.COMPLETED
|
SEpisode.create().apply {
|
||||||
|
setUrlWithoutDomain(document.selectFirst("meta[property=og:url]")!!.attr("content"))
|
||||||
|
episode_number = 1F
|
||||||
|
name = "Movie"
|
||||||
|
}.let(::listOf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// =============================== Latest ===============================
|
override fun episodeFromElement(element: Element): SEpisode = throw Exception("not used")
|
||||||
|
|
||||||
override fun latestUpdatesNextPageSelector(): String = throw Exception("not used")
|
// ============================ Video Links =============================
|
||||||
|
override fun videoListParse(response: Response): List<Video> {
|
||||||
|
val document = response.use { it.asJsoup() }
|
||||||
|
val frameLink = document.selectFirst("iframe[id=frame]")!!.attr("src")
|
||||||
|
return ChillxExtractor(client, headers).videoFromUrl(frameLink, baseUrl)
|
||||||
|
}
|
||||||
|
|
||||||
override fun latestUpdatesFromElement(element: Element) = throw Exception("not used")
|
override fun List<Video>.sort(): List<Video> {
|
||||||
|
val quality = preferences.getString(PREF_QUALITY_KEY, PREF_QUALITY_DEFAULT)!!
|
||||||
|
|
||||||
override fun latestUpdatesRequest(page: Int): Request = throw Exception("not used")
|
return sortedWith(
|
||||||
|
compareBy { it.quality.contains(quality) },
|
||||||
|
).reversed()
|
||||||
|
}
|
||||||
|
|
||||||
override fun latestUpdatesSelector(): String = throw Exception("not used")
|
override fun videoListSelector() = throw Exception("not used")
|
||||||
|
override fun videoFromElement(element: Element) = throw Exception("not used")
|
||||||
override fun latestUpdatesParse(response: Response): AnimesPage = throw Exception("not used")
|
override fun videoUrlParse(document: Document) = throw Exception("not used")
|
||||||
|
|
||||||
// ============================= Preference =============================
|
// ============================= Preference =============================
|
||||||
|
|
||||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||||
val videoQualityPref = ListPreference(screen.context).apply {
|
ListPreference(screen.context).apply {
|
||||||
key = "preferred_quality"
|
key = PREF_QUALITY_KEY
|
||||||
title = "Preferred quality"
|
title = PREF_QUALITY_TITLE
|
||||||
entries = arrayOf("1080p", "720p", "480p", "360p")
|
entries = PREF_QUALITY_ENTRIES
|
||||||
entryValues = arrayOf("1080", "720", "480", "360")
|
entryValues = PREF_QUALITY_VALUES
|
||||||
setDefaultValue("1080")
|
setDefaultValue(PREF_QUALITY_DEFAULT)
|
||||||
summary = "%s"
|
summary = "%s"
|
||||||
|
|
||||||
setOnPreferenceChangeListener { _, newValue ->
|
setOnPreferenceChangeListener { _, newValue ->
|
||||||
@ -228,7 +185,14 @@ class Tokuzilla : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
val entry = entryValues[index] as String
|
val entry = entryValues[index] as String
|
||||||
preferences.edit().putString(key, entry).commit()
|
preferences.edit().putString(key, entry).commit()
|
||||||
}
|
}
|
||||||
}
|
}.also(screen::addPreference)
|
||||||
screen.addPreference(videoQualityPref)
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val PREF_QUALITY_KEY = "preferred_quality"
|
||||||
|
private const val PREF_QUALITY_TITLE = "Preferred quality"
|
||||||
|
private const val PREF_QUALITY_DEFAULT = "1080p"
|
||||||
|
private val PREF_QUALITY_ENTRIES = arrayOf("1080p", "720p", "480p", "360p")
|
||||||
|
private val PREF_QUALITY_VALUES = PREF_QUALITY_ENTRIES
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user