Skip to content

Commit

Permalink
feat(multisrc/zorotheme): force clear outdated hosts
Browse files Browse the repository at this point in the history
  • Loading branch information
Secozzi committed Mar 11, 2024
1 parent ac22fc5 commit e6b211f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib-multisrc/zorotheme/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ plugins {
id("lib-multisrc")
}

baseVersionCode = 1
baseVersionCode = 2

dependencies {
api(project(":lib:megacloud-extractor"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ abstract class ZoroTheme(
override val lang: String,
override val name: String,
override val baseUrl: String,
private val hosterNames: List<String>,
) : ConfigurableAnimeSource, ParsedAnimeHttpSource() {

override val supportsLatest = true
Expand All @@ -44,6 +45,7 @@ abstract class ZoroTheme(

val preferences: SharedPreferences by lazy {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
.clearOldHosts()
}

private val docHeaders = headers.newBuilder().apply {
Expand All @@ -54,8 +56,6 @@ abstract class ZoroTheme(

protected open val ajaxRoute = ""

abstract val hosterNames: List<String>

private val useEnglish by lazy { preferences.getTitleLang == "English" }
private val markFiller by lazy { preferences.markFiller }

Expand Down Expand Up @@ -238,9 +238,7 @@ abstract class ZoroTheme(
return embedLinks.parallelCatchingFlatMap(::extractVideo)
}

protected open fun extractVideo(server: VideoData): List<Video> {
return emptyList()
}
abstract fun extractVideo(server: VideoData): List<Video>

override fun videoListSelector() = throw UnsupportedOperationException()

Expand All @@ -249,6 +247,21 @@ abstract class ZoroTheme(
override fun videoUrlParse(document: Document) = throw UnsupportedOperationException()

// ============================= 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 {
return any { it.equals(s, ignoreCase) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ class Kaido : ZoroTheme(
"en",
"Kaido",
"https://kaido.to",
) {
override val hosterNames: List<String> = listOf(
hosterNames = listOf(
"Vidstreaming",
"Vidcloud",
"StreamTape",
)

),
) {
private val streamtapeExtractor by lazy { StreamTapeExtractor(client) }
private val megaCloudExtractor by lazy { MegaCloudExtractor(client, headers, preferences) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ class HiAnime : ZoroTheme(
"en",
"HiAnime",
"https://hianime.to",
hosterNames = listOf(
"HD-1",
"HD-2",
"StreamTape",
),
) {
override val id = 6706411382606718900L

override val ajaxRoute = "/v2"

override val hosterNames: List<String> = listOf(
"HD-1",
"HD-2",
"StreamTape",
)

private val streamtapeExtractor by lazy { StreamTapeExtractor(client) }
private val megaCloudExtractor by lazy { MegaCloudExtractor(client, headers, preferences) }

Expand Down

0 comments on commit e6b211f

Please sign in to comment.