Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(es/*): Improvements for the main spanish extensions #2446

Merged
merged 13 commits into from
Oct 30, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.OkHttpClient

class VoeExtractor(private val client: OkHttpClient) {
fun videoFromUrl(url: String, quality: String? = null): Video? {
fun videoFromUrl(url: String, quality: String? = null, prefix: String = ""): Video? {
val document = client.newCall(GET(url)).execute().asJsoup()
val script = document.selectFirst("script:containsData(const sources),script:containsData(var sources)")
?.data()
?: return null
val videoUrl = script.substringAfter("hls': '").substringBefore("'")
val resolution = script.substringAfter("video_height': ").substringBefore(",")
val qualityStr = quality ?: "VoeCDN(${resolution}p)"
val qualityStr = when {
prefix.isNotEmpty() -> "$prefix${resolution}p"
else -> quality ?: "VoeCDN(${resolution}p)"
}
return Video(url, qualityStr, videoUrl)
}
}
8 changes: 7 additions & 1 deletion src/es/animefenix/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@ ext {
extName = 'Animefenix'
pkgNameSuffix = 'es.animefenix'
extClass = '.Animefenix'
extVersionCode = 29
extVersionCode = 30
libVersion = '13'
}

dependencies {
implementation(project(':lib-mp4upload-extractor'))
implementation(project(':lib-streamtape-extractor'))
implementation(project(':lib-yourupload-extractor'))
implementation(project(':lib-uqload-extractor'))
implementation(project(':lib-okru-extractor'))
implementation(project(':lib-burstcloud-extractor'))
implementation(project(':lib-streamwish-extractor'))
implementation(project(':lib-filemoon-extractor'))
implementation(project(':lib-voe-extractor'))
implementation(project(':lib-streamlare-extractor'))
implementation(project(':lib-fastream-extractor'))
implementation(project(':lib-dood-extractor'))
implementation(project(':lib-upstream-extractor'))
implementation(project(':lib-streamhidevid-extractor'))
}


Expand Down

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/es/animeflv/build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlinx-serialization'

ext {
extName = 'AnimeFLV'
pkgNameSuffix = 'es.animeflv'
extClass = '.AnimeFlv'
extVersionCode = 50
extVersionCode = 51
libVersion = '13'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AnimeFlv : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override val lang = "es"

override val supportsLatest = false
override val supportsLatest = true

override val client: OkHttpClient = network.cloudflareClient

Expand All @@ -51,24 +51,30 @@ class AnimeFlv : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}

companion object {
private const val PREF_QUALITY_KEY = "preferred_quality"
private const val PREF_QUALITY_DEFAULT = "1080"
private val QUALITY_LIST = arrayOf("1080", "720", "480", "360")

private const val PREF_SERVER_KEY = "preferred_server"
private const val PREF_SERVER_DEFAULT = "YourUpload"
private val SERVER_LIST = arrayOf("MailRu", "Okru", "YourUpload", "DoodStream", "StreamTape")
}

override fun popularAnimeSelector(): String = "div.Container ul.ListAnimes li article"

override fun popularAnimeRequest(page: Int): Request = GET("$baseUrl/browse?order=rating&page=$page")

override fun popularAnimeFromElement(element: Element): SAnime {
val anime = SAnime.create()
anime.setUrlWithoutDomain(
baseUrl + element.select("div.Description a.Button")
.attr("href"),
)
anime.setUrlWithoutDomain(element.select("div.Description a.Button").attr("abs:href"))
anime.title = element.select("a h3").text()
anime.thumbnail_url = try {
element.select("a div.Image figure img").attr("src")
} catch (e: Exception) {
element.select("a div.Image figure img").attr("data-cfsrc")
}
anime.description =
element.select("div.Description p:eq(2)").text().removeSurrounding("\"")
anime.description = element.select("div.Description p:eq(2)").text().removeSurrounding("\"")
return anime
}

Expand Down Expand Up @@ -127,7 +133,7 @@ class AnimeFlv : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val docHeaders = headers.newBuilder()
.add("Referer", "$baseUrl/")
.build()
StreamWishExtractor(client, docHeaders).videosFromUrl(url, "StreamWish")
StreamWishExtractor(client, docHeaders).videosFromUrl(url, videoNameGen = { "StreamWish:$it" })
}
else -> null
}
Expand All @@ -145,27 +151,6 @@ class AnimeFlv : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override fun videoFromElement(element: Element) = throw Exception("not used")

override fun List<Video>.sort(): List<Video> {
return try {
val videoSorted = this.sortedWith(
compareBy<Video> { it.quality.replace("[0-9]".toRegex(), "") }.thenByDescending { getNumberFromString(it.quality) },
).toTypedArray()
val userPreferredQuality = preferences.getString("preferred_quality", "Okru:720p")
val preferredIdx = videoSorted.indexOfFirst { x -> x.quality == userPreferredQuality }
if (preferredIdx != -1) {
videoSorted.drop(preferredIdx + 1)
videoSorted[0] = videoSorted[preferredIdx]
}
videoSorted.toList()
} catch (e: Exception) {
this
}
}

private fun getNumberFromString(epsStr: String): String {
return epsStr.filter { it.isDigit() }.ifEmpty { "0" }
}

override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
val filterList = if (filters.isEmpty()) getFilterList() else filters
val genreFilter = filterList.find { it is GenreFilter } as GenreFilter
Expand Down Expand Up @@ -278,28 +263,22 @@ class AnimeFlv : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
fun toUriPart() = vals[state].second
}

override fun searchAnimeFromElement(element: Element): SAnime {
return popularAnimeFromElement(element)
}
override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element)

override fun searchAnimeNextPageSelector(): String = popularAnimeNextPageSelector()

override fun searchAnimeSelector(): String = popularAnimeSelector()

override fun animeDetailsParse(document: Document): SAnime {
val anime = SAnime.create()
anime.thumbnail_url = externalOrInternalImg(document.selectFirst("div.AnimeCover div.Image figure img")!!.attr("src"))
anime.thumbnail_url = document.selectFirst("div.AnimeCover div.Image figure img")!!.attr("abs:src")
anime.title = document.selectFirst("div.Ficha.fchlt div.Container .Title")!!.text()
anime.description = document.selectFirst("div.Description")!!.text().removeSurrounding("\"")
anime.genre = document.select("nav.Nvgnrs a").joinToString { it.text() }
anime.status = parseStatus(document.select("span.fa-tv").text())
return anime
}

private fun externalOrInternalImg(url: String): String {
return if (url.contains("https")) url else "$baseUrl/$url"
}

private fun parseStatus(statusString: String): Int {
return when {
statusString.contains("En emision") -> SAnime.ONGOING
Expand All @@ -316,19 +295,41 @@ class AnimeFlv : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override fun latestUpdatesSelector() = popularAnimeSelector()

override fun List<Video>.sort(): List<Video> {
val quality = preferences.getString(PREF_QUALITY_KEY, PREF_QUALITY_DEFAULT)!!
val server = preferences.getString(PREF_SERVER_KEY, PREF_SERVER_DEFAULT)!!
return this.sortedWith(
compareBy(
{ it.quality.contains(server, true) },
{ it.quality.contains(quality) },
{ Regex("""(\d+)p""").find(it.quality)?.groupValues?.get(1)?.toIntOrNull() ?: 0 },
),
).reversed()
}

override fun setupPreferenceScreen(screen: PreferenceScreen) {
val videoQualityPref = ListPreference(screen.context).apply {
key = "preferred_quality"
ListPreference(screen.context).apply {
key = PREF_SERVER_KEY
title = "Preferred server"
entries = SERVER_LIST
entryValues = SERVER_LIST
setDefaultValue(PREF_SERVER_DEFAULT)
summary = "%s"

setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String
val index = findIndexOfValue(selected)
val entry = entryValues[index] as String
preferences.edit().putString(key, entry).commit()
}
}.also(screen::addPreference)

ListPreference(screen.context).apply {
key = PREF_QUALITY_KEY
title = "Preferred quality"
entries = arrayOf(
"Okru:1080p", "Okru:720p", "Okru:480p", "Okru:360p", "Okru:240p", "Okru:144p", // Okru
"YourUpload", "DoodStream", "StreamTape",
) // video servers without resolution
entryValues = arrayOf(
"Okru:1080p", "Okru:720p", "Okru:480p", "Okru:360p", "Okru:240p", "Okru:144p", // Okru
"YourUpload", "DoodStream", "StreamTape",
) // video servers without resolution
setDefaultValue("Okru:720p")
entries = QUALITY_LIST
entryValues = QUALITY_LIST
setDefaultValue(PREF_QUALITY_DEFAULT)
summary = "%s"

setOnPreferenceChangeListener { _, newValue ->
Expand All @@ -337,7 +338,6 @@ class AnimeFlv : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
val entry = entryValues[index] as String
preferences.edit().putString(key, entry).commit()
}
}
screen.addPreference(videoQualityPref)
}.also(screen::addPreference)
}
}
2 changes: 1 addition & 1 deletion src/es/animeid/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
extName = 'AnimeID'
pkgNameSuffix = 'es.animeid'
extClass = '.AnimeID'
extVersionCode = 6
extVersionCode = 7
libVersion = '13'
}

Expand Down
Loading