Xfani: Fix video list parse (#480)

This commit is contained in:
AlphaBoom 2025-01-05 23:33:54 +08:00 committed by GitHub
parent b00b450fa2
commit 9b0e6b264c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 10 deletions

View file

@ -1,7 +1,7 @@
ext { ext {
extName = 'Xfani' extName = 'Xfani'
extClass = '.Xfani' extClass = '.Xfani'
extVersionCode = 3 extVersionCode = 4
} }
apply from: "$rootDir/common.gradle" apply from: "$rootDir/common.gradle"

View file

@ -33,6 +33,7 @@ import okhttp3.OkHttpClient
import okhttp3.Request import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.select.Elements
import uy.kohesive.injekt.Injekt 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
@ -143,25 +144,46 @@ class Xfani : AnimeHttpSource(), ConfigurableAnimeSource {
override fun videoListParse(response: Response): List<Video> { override fun videoListParse(response: Response): List<Video> {
val requestUrl = response.request.url val requestUrl = response.request.url
val currentPath = requestUrl.encodedPath val currentPath = requestUrl.encodedPath
val currentAnthology = response.request.url.pathSegments.last() val currentEpisodePathName = response.request.url.pathSegments.last()
val document = response.asJsoup() val document = response.asJsoup()
val videoUrl = findVideoUrl(document) val videoUrl = findVideoUrl(document)
val sourceList = val allEpisodeElements =
document.select(".player-anthology .anthology-list .anthology-list-box") document.select(".player-anthology .anthology-list .anthology-list-box")
.map { element -> .map { element ->
element.select(".anthology-list-play li a").eachAttr("href") element.select(".anthology-list-play li a")
.first { it.endsWith(currentAnthology) } }
val currentEpisodeName = allEpisodeElements.firstNotNullOfOrNull { elements ->
elements.firstOrNull { it.attr("href") == currentPath }?.select("span")?.text()
}
val targetEpisodeNumber = currentEpisodeName?.let { numberRegex.find(it)?.value?.toIntOrNull() } ?: -1
val sourceList = allEpisodeElements.map { elements ->
elements.findSourceOrNull { name, _ -> numberRegex.find(name)?.value?.toIntOrNull() == targetEpisodeNumber }
?: elements.findSourceOrNull { _, url -> url.endsWith(currentEpisodePathName) }
} }
val sourceNameList = document.select(".anthology-tab .swiper-wrapper a").map { val sourceNameList = document.select(".anthology-tab .swiper-wrapper a").map {
it.ownText().trim() it.ownText().trim()
} }
return sourceList.zip(sourceNameList) { url, name -> return sourceList.zip(sourceNameList) { source, name ->
if (url.endsWith(currentPath)) { if (source == null) {
Video("$baseUrl$url", name, videoUrl = videoUrl) Video("", "", null)
} else if (source.second.endsWith(currentPath)) {
Video("$baseUrl${source.second}", "$name-${source.first}", videoUrl = videoUrl)
} else { } else {
Video("$baseUrl$url", name, videoUrl = null) Video("$baseUrl${source.second}", "$name-${source.first}", videoUrl = null)
}
}.filter { it.quality.isNotEmpty() }.sortedByDescending { it.videoUrl != null }
}
private fun Elements.findSourceOrNull(predicate: (name: String, url: String) -> Boolean): Pair<String, String>? {
return firstNotNullOfOrNull {
val name = it.selectFirst("span")?.text() ?: ""
val url = it.attr("href")
if (predicate(name, url)) {
name to url
} else {
null
}
} }
}.sortedByDescending { it.videoUrl != null }
} }
override fun videoUrlParse(response: Response): String { override fun videoUrlParse(response: Response): String {