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

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

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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