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

Xfani: Fix video list parse #177

Merged
merged 1 commit into from
Jan 6, 2025
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 src/zh/xfani/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Xfani'
extClass = '.Xfani'
extVersionCode = 2
extVersionCode = 3
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.select.Elements
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
Expand Down Expand Up @@ -143,25 +144,46 @@ class Xfani : AnimeHttpSource(), ConfigurableAnimeSource {
override fun videoListParse(response: Response): List<Video> {
val requestUrl = response.request.url
val currentPath = requestUrl.encodedPath
val currentAnthology = response.request.url.pathSegments.last()
val currentEpisodePathName = response.request.url.pathSegments.last()
val document = response.asJsoup()
val videoUrl = findVideoUrl(document)
val sourceList =
val allEpisodeElements =
document.select(".player-anthology .anthology-list .anthology-list-box")
.map { element ->
element.select(".anthology-list-play li a").eachAttr("href")
.first { it.endsWith(currentAnthology) }
element.select(".anthology-list-play li a")
}
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 {
it.ownText().trim()
}
return sourceList.zip(sourceNameList) { url, name ->
if (url.endsWith(currentPath)) {
Video("$baseUrl$url", name, videoUrl = videoUrl)
return sourceList.zip(sourceNameList) { source, name ->
if (source == null) {
Video("", "", null)
} else if (source.second.endsWith(currentPath)) {
Video("$baseUrl${source.second}", "$name-${source.first}", videoUrl = videoUrl)
} else {
Video("$baseUrl$url", name, videoUrl = null)
Video("$baseUrl${source.second}", "$name-${source.first}", videoUrl = null)
}
}.sortedByDescending { it.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
}
}
}

override fun videoUrlParse(response: Response): String {
Expand Down
Loading