Hanime1: Filter ads from search results and more (#846)

* Hanime1:Filter advertisement items from search results.

* Hanime1:Fix the missing source for some videos.

* Hanime1:Add subtitle preference setting.

* Hanime1:Bump version.
This commit is contained in:
AlphaBoom 2025-03-25 03:29:26 +09:00 committed by GitHub
parent f4c6e113bb
commit faf9d63d75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 55 additions and 19 deletions

View file

@ -1,7 +1,7 @@
ext { ext {
extName = 'Hanime1' extName = 'Hanime1'
extClass = '.Hanime1' extClass = '.Hanime1'
extVersionCode = 3 extVersionCode = 4
isNsfw = true isNsfw = true
} }

View file

@ -24,6 +24,7 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.jsonPrimitive
import okhttp3.Cookie
import okhttp3.HttpUrl.Companion.toHttpUrl import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.Request import okhttp3.Request
@ -100,13 +101,23 @@ class Hanime1 : AnimeHttpSource(), ConfigurableAnimeSource {
} }
override fun videoListParse(response: Response): List<Video> { override fun videoListParse(response: Response): List<Video> {
val sourceList = response.asJsoup().select("video source") val doc = response.asJsoup()
val sourceList = doc.select("video source")
val preferQuality = preferences.getString(PREF_KEY_VIDEO_QUALITY, DEFAULT_QUALITY) val preferQuality = preferences.getString(PREF_KEY_VIDEO_QUALITY, DEFAULT_QUALITY)
return sourceList.map { return sourceList.map {
val quality = it.attr("size") val quality = it.attr("size")
val url = it.attr("src") val url = it.attr("src")
Video(url, "${quality}P", videoUrl = url) Video(url, "${quality}P", videoUrl = url)
}.sortedByDescending { preferQuality == it.quality } }.filterNot { it.videoUrl?.startsWith("blob") == true }
.sortedByDescending { preferQuality == it.quality }
.ifEmpty {
// Try to find the source from the script content.
val videoUrl = doc.select("script[type=application/ld+json]").first()!!.data().let {
val info = json.decodeFromString<JsonElement>(it).jsonObject
info["contentUrl"]!!.jsonPrimitive.content
}
listOf(Video(videoUrl, "Raw", videoUrl = videoUrl))
}
} }
override fun latestUpdatesParse(response: Response): AnimesPage = searchAnimeParse(response) override fun latestUpdatesParse(response: Response): AnimesPage = searchAnimeParse(response)
@ -137,7 +148,7 @@ class Hanime1 : AnimeHttpSource(), ConfigurableAnimeSource {
} }
} }
} else { } else {
jsoup.select(".search-videos").map { jsoup.select("a:not([target]) > .search-videos").map {
SAnime.create().apply { SAnime.create().apply {
setUrlWithoutDomain(it.parent()!!.attr("href")) setUrlWithoutDomain(it.parent()!!.attr("href"))
thumbnail_url = it.select("img").attr("src") thumbnail_url = it.select("img").attr("src")
@ -277,8 +288,9 @@ class Hanime1 : AnimeHttpSource(), ConfigurableAnimeSource {
} }
override fun setupPreferenceScreen(screen: PreferenceScreen) { override fun setupPreferenceScreen(screen: PreferenceScreen) {
screen.addPreference( screen.apply {
ListPreference(screen.context).apply { addPreference(
ListPreference(context).apply {
key = PREF_KEY_VIDEO_QUALITY key = PREF_KEY_VIDEO_QUALITY
title = "設置首選畫質" title = "設置首選畫質"
entries = arrayOf("1080P", "720P", "480P") entries = arrayOf("1080P", "720P", "480P")
@ -292,10 +304,34 @@ class Hanime1 : AnimeHttpSource(), ConfigurableAnimeSource {
} }
}, },
) )
addPreference(
ListPreference(context).apply {
key = PREF_KEY_LANG
title = "設置首選語言"
summary = "該設置僅影響影片字幕"
entries = arrayOf("繁體中文", "簡體中文")
entryValues = arrayOf("zh-CHT", "zh-CHS")
setOnPreferenceChangeListener { _, newValue ->
val baseHttpUrl = baseUrl.toHttpUrl()
client.cookieJar.saveFromResponse(
baseHttpUrl,
listOf(
Cookie.parse(
baseHttpUrl,
"user_lang=${newValue as String}",
)!!,
),
)
true
}
},
)
}
} }
companion object { companion object {
const val PREF_KEY_VIDEO_QUALITY = "PREF_KEY_VIDEO_QUALITY" const val PREF_KEY_VIDEO_QUALITY = "PREF_KEY_VIDEO_QUALITY"
const val PREF_KEY_LANG = "PREF_KEY_LANG"
const val PREF_KEY_GENRE_LIST = "PREF_KEY_GENRE_LIST" const val PREF_KEY_GENRE_LIST = "PREF_KEY_GENRE_LIST"
const val PREF_KEY_SORT_LIST = "PREF_KEY_SORT_LIST" const val PREF_KEY_SORT_LIST = "PREF_KEY_SORT_LIST"