feat(multisrc/zorotheme): Force clear outdated hosts (#3043)

This commit is contained in:
Secozzi 2024-03-11 09:58:14 +00:00 committed by GitHub
parent 6f85b879ee
commit c61a4478cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 16 deletions

View File

@ -2,7 +2,7 @@ plugins {
id("lib-multisrc") id("lib-multisrc")
} }
baseVersionCode = 1 baseVersionCode = 2
dependencies { dependencies {
api(project(":lib:megacloud-extractor")) api(project(":lib:megacloud-extractor"))

View File

@ -36,6 +36,7 @@ abstract class ZoroTheme(
override val lang: String, override val lang: String,
override val name: String, override val name: String,
override val baseUrl: String, override val baseUrl: String,
private val hosterNames: List<String>,
) : ConfigurableAnimeSource, ParsedAnimeHttpSource() { ) : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override val supportsLatest = true override val supportsLatest = true
@ -44,6 +45,7 @@ abstract class ZoroTheme(
val preferences: SharedPreferences by lazy { val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000) Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
.clearOldHosts()
} }
private val docHeaders = headers.newBuilder().apply { private val docHeaders = headers.newBuilder().apply {
@ -54,8 +56,6 @@ abstract class ZoroTheme(
protected open val ajaxRoute = "" protected open val ajaxRoute = ""
abstract val hosterNames: List<String>
private val useEnglish by lazy { preferences.getTitleLang == "English" } private val useEnglish by lazy { preferences.getTitleLang == "English" }
private val markFiller by lazy { preferences.markFiller } private val markFiller by lazy { preferences.markFiller }
@ -238,9 +238,7 @@ abstract class ZoroTheme(
return embedLinks.parallelCatchingFlatMap(::extractVideo) return embedLinks.parallelCatchingFlatMap(::extractVideo)
} }
protected open fun extractVideo(server: VideoData): List<Video> { abstract fun extractVideo(server: VideoData): List<Video>
return emptyList()
}
override fun videoListSelector() = throw UnsupportedOperationException() override fun videoListSelector() = throw UnsupportedOperationException()
@ -249,6 +247,21 @@ abstract class ZoroTheme(
override fun videoUrlParse(document: Document) = throw UnsupportedOperationException() override fun videoUrlParse(document: Document) = throw UnsupportedOperationException()
// ============================= Utilities ============================== // ============================= Utilities ==============================
private fun SharedPreferences.clearOldHosts(): SharedPreferences {
if (hostToggle.all { hosterNames.contains(it) }) {
return this
}
edit()
.remove(PREF_HOSTER_KEY)
.putStringSet(PREF_HOSTER_KEY, hosterNames.toSet())
.remove(PREF_SERVER_KEY)
.putString(PREF_SERVER_KEY, hosterNames.first())
.apply()
return this
}
private fun Set<String>.contains(s: String, ignoreCase: Boolean): Boolean { private fun Set<String>.contains(s: String, ignoreCase: Boolean): Boolean {
return any { it.equals(s, ignoreCase) } return any { it.equals(s, ignoreCase) }
} }

View File

@ -9,13 +9,12 @@ class Kaido : ZoroTheme(
"en", "en",
"Kaido", "Kaido",
"https://kaido.to", "https://kaido.to",
) { hosterNames = listOf(
override val hosterNames: List<String> = listOf(
"Vidstreaming", "Vidstreaming",
"Vidcloud", "Vidcloud",
"StreamTape", "StreamTape",
) ),
) {
private val streamtapeExtractor by lazy { StreamTapeExtractor(client) } private val streamtapeExtractor by lazy { StreamTapeExtractor(client) }
private val megaCloudExtractor by lazy { MegaCloudExtractor(client, headers, preferences) } private val megaCloudExtractor by lazy { MegaCloudExtractor(client, headers, preferences) }

View File

@ -9,17 +9,16 @@ class HiAnime : ZoroTheme(
"en", "en",
"HiAnime", "HiAnime",
"https://hianime.to", "https://hianime.to",
hosterNames = listOf(
"HD-1",
"HD-2",
"StreamTape",
),
) { ) {
override val id = 6706411382606718900L override val id = 6706411382606718900L
override val ajaxRoute = "/v2" override val ajaxRoute = "/v2"
override val hosterNames: List<String> = listOf(
"HD-1",
"HD-2",
"StreamTape",
)
private val streamtapeExtractor by lazy { StreamTapeExtractor(client) } private val streamtapeExtractor by lazy { StreamTapeExtractor(client) }
private val megaCloudExtractor by lazy { MegaCloudExtractor(client, headers, preferences) } private val megaCloudExtractor by lazy { MegaCloudExtractor(client, headers, preferences) }