fix(en/animeflixlive): Fix video extraction (#3057)

This commit is contained in:
Secozzi
2024-03-16 19:29:10 +00:00
committed by GitHub
parent ac4937a61e
commit ed2f4d6d13
2 changed files with 18 additions and 6 deletions

View File

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

View File

@ -36,6 +36,7 @@ import org.jsoup.nodes.Document
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
import java.net.URLDecoder
import java.util.Calendar import java.util.Calendar
import java.util.Locale import java.util.Locale
import java.util.TimeZone import java.util.TimeZone
@ -226,7 +227,7 @@ class AnimeflixLive : ConfigurableAnimeSource, AnimeHttpSource() {
val initialPlayerDocument = client.newCall( val initialPlayerDocument = client.newCall(
GET(initialPlayerUrl, docHeaders), GET(initialPlayerUrl, docHeaders),
).execute().asJsoup() ).execute().asJsoup().unescape()
videoList.addAll( videoList.addAll(
videosFromPlayer( videosFromPlayer(
@ -266,7 +267,7 @@ class AnimeflixLive : ConfigurableAnimeSource, AnimeHttpSource() {
val playerDocument = client.newCall( val playerDocument = client.newCall(
GET(playerUrl, docHeaders), GET(playerUrl, docHeaders),
).execute().asJsoup() ).execute().asJsoup().unescape()
videosFromPlayer( videosFromPlayer(
playerDocument, playerDocument,
@ -300,16 +301,26 @@ class AnimeflixLive : ConfigurableAnimeSource, AnimeHttpSource() {
}.build() }.build()
} }
private fun Document.unescape(): Document {
val unescapeScript = this.selectFirst("script:containsData(unescape)")
return if (unescapeScript == null) {
this
} else {
val data = URLDecoder.decode(unescapeScript.data(), "UTF-8")
Jsoup.parse(data, this.location())
}
}
private fun videosFromPlayer(document: Document, name: String): List<Video> { private fun videosFromPlayer(document: Document, name: String): List<Video> {
val dataScript = document.selectFirst("script:containsData(const source)") val dataScript = document.selectFirst("script:containsData(m3u8)")
?.data() ?: return emptyList() ?.data() ?: return emptyList()
val subtitleList = document.select("video > track[kind=captions]").map { val subtitleList = document.select("video > track[kind=captions]").map {
Track(it.attr("id"), it.attr("label")) Track(it.attr("id"), it.attr("label"))
} }
var masterPlaylist = dataScript.substringAfter("const source = `") var masterPlaylist = M3U8_REGEX.find(dataScript)?.groupValues?.get(1)
.substringBefore("`") ?: return emptyList()
if (name.equals("moon", true)) { if (name.equals("moon", true)) {
masterPlaylist += dataScript.substringAfter("`${'$'}{url}") masterPlaylist += dataScript.substringAfter("`${'$'}{url}")
@ -357,6 +368,7 @@ class AnimeflixLive : ConfigurableAnimeSource, AnimeHttpSource() {
companion object { companion object {
private val SERVER_REGEX = Regex("""'1' === '1'.*?(<button.*?</button>)""", RegexOption.DOT_MATCHES_ALL) private val SERVER_REGEX = Regex("""'1' === '1'.*?(<button.*?</button>)""", RegexOption.DOT_MATCHES_ALL)
private val M3U8_REGEX = Regex("""const ?\w*? ?= ?`(.*?)`""")
private const val PAGE_SIZE = 24 private const val PAGE_SIZE = 24
private const val PREF_DOMAIN_KEY = "pref_domain_key" private const val PREF_DOMAIN_KEY = "pref_domain_key"