Add server preference for gogo (#1140)
This commit is contained in:
@ -5,7 +5,7 @@ ext {
|
|||||||
extName = 'Gogoanime'
|
extName = 'Gogoanime'
|
||||||
pkgNameSuffix = 'en.gogoanime'
|
pkgNameSuffix = 'en.gogoanime'
|
||||||
extClass = '.GogoAnime'
|
extClass = '.GogoAnime'
|
||||||
extVersionCode = 51
|
extVersionCode = 52
|
||||||
libVersion = '13'
|
libVersion = '13'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,8 +27,6 @@ import uy.kohesive.injekt.Injekt
|
|||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.lang.Exception
|
import java.lang.Exception
|
||||||
import java.lang.NumberFormatException
|
|
||||||
import kotlin.math.abs
|
|
||||||
|
|
||||||
@ExperimentalSerializationApi
|
@ExperimentalSerializationApi
|
||||||
class GogoAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
class GogoAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||||
@ -108,7 +106,7 @@ class GogoAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
document.select("div.anime_muti_link > ul > li.streamsb > a")
|
document.select("div.anime_muti_link > ul > li.streamsb > a")
|
||||||
.firstOrNull()?.attr("data-video")
|
.firstOrNull()?.attr("data-video")
|
||||||
?.let { videoList.addAll(StreamSBExtractor(client).videosFromUrl(it, headers)) }
|
?.let { videoList.addAll(StreamSBExtractor(client).videosFromUrl(it, headers)) }
|
||||||
return videoList
|
return videoList.sort()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun videoListSelector() = throw Exception("not used")
|
override fun videoListSelector() = throw Exception("not used")
|
||||||
@ -118,35 +116,15 @@ class GogoAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
override fun videoUrlParse(document: Document) = throw Exception("not used")
|
override fun videoUrlParse(document: Document) = throw Exception("not used")
|
||||||
|
|
||||||
override fun List<Video>.sort(): List<Video> {
|
override fun List<Video>.sort(): List<Video> {
|
||||||
val quality = preferences.getString("preferred_quality", "1080")
|
val quality = preferences.getString("preferred_quality", "1080")!!
|
||||||
if (quality != null) {
|
val server = preferences.getString("preferred_server", "Gogostream")!!
|
||||||
val newList = mutableListOf<Video>()
|
|
||||||
var preferred = 0
|
|
||||||
for (video in this) {
|
|
||||||
when {
|
|
||||||
video.quality.contains(quality) -> {
|
|
||||||
newList.add(preferred, video)
|
|
||||||
preferred++
|
|
||||||
}
|
|
||||||
abs(qualityToInt(video.quality) - quality.toInt()) < 100 -> {
|
|
||||||
newList.add(preferred, video)
|
|
||||||
}
|
|
||||||
else -> {
|
|
||||||
newList.add(video)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newList
|
|
||||||
}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun qualityToInt(quality: String): Int {
|
return this.sortedWith(
|
||||||
return try {
|
compareBy(
|
||||||
quality.filter { it.isDigit() }.toInt()
|
{ it.quality.contains(quality) },
|
||||||
} catch (e: NumberFormatException) {
|
{ it.quality.contains(server) }
|
||||||
-100
|
)
|
||||||
}
|
).reversed()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun searchAnimeFromElement(element: Element): SAnime {
|
override fun searchAnimeFromElement(element: Element): SAnime {
|
||||||
@ -247,8 +225,24 @@ class GogoAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
|||||||
preferences.edit().putString(key, entry).commit()
|
preferences.edit().putString(key, entry).commit()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
val videoServerPref = ListPreference(screen.context).apply {
|
||||||
|
key = "preferred_server"
|
||||||
|
title = "Preferred server"
|
||||||
|
entries = arrayOf("Gogostream", "Vidstreaming", "Doodstream", "StreamSB")
|
||||||
|
entryValues = arrayOf("Gogostream", "Vidstreaming", "Doodstream", "StreamSB")
|
||||||
|
setDefaultValue("Gogostream")
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
screen.addPreference(domainPref)
|
screen.addPreference(domainPref)
|
||||||
screen.addPreference(videoQualityPref)
|
screen.addPreference(videoQualityPref)
|
||||||
|
screen.addPreference(videoServerPref)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filters
|
// Filters
|
||||||
|
Reference in New Issue
Block a user