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

fix(en/animeflix.live): fix video extraction #3057

Merged
merged 1 commit into from
Mar 16, 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 src/en/animeflixlive/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Animeflix.live'
extClass = '.AnimeflixLive'
extVersionCode = 2
extVersionCode = 3
}

apply from: "$rootDir/common.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import org.jsoup.nodes.Document
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.net.URLDecoder
import java.util.Calendar
import java.util.Locale
import java.util.TimeZone
Expand Down Expand Up @@ -226,7 +227,7 @@ class AnimeflixLive : ConfigurableAnimeSource, AnimeHttpSource() {

val initialPlayerDocument = client.newCall(
GET(initialPlayerUrl, docHeaders),
).execute().asJsoup()
).execute().asJsoup().unescape()

videoList.addAll(
videosFromPlayer(
Expand Down Expand Up @@ -266,7 +267,7 @@ class AnimeflixLive : ConfigurableAnimeSource, AnimeHttpSource() {

val playerDocument = client.newCall(
GET(playerUrl, docHeaders),
).execute().asJsoup()
).execute().asJsoup().unescape()

videosFromPlayer(
playerDocument,
Expand Down Expand Up @@ -300,16 +301,26 @@ class AnimeflixLive : ConfigurableAnimeSource, AnimeHttpSource() {
}.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> {
val dataScript = document.selectFirst("script:containsData(const source)")
val dataScript = document.selectFirst("script:containsData(m3u8)")
?.data() ?: return emptyList()

val subtitleList = document.select("video > track[kind=captions]").map {
Track(it.attr("id"), it.attr("label"))
}

var masterPlaylist = dataScript.substringAfter("const source = `")
.substringBefore("`")
var masterPlaylist = M3U8_REGEX.find(dataScript)?.groupValues?.get(1)
?: return emptyList()

if (name.equals("moon", true)) {
masterPlaylist += dataScript.substringAfter("`${'$'}{url}")
Expand Down Expand Up @@ -357,6 +368,7 @@ class AnimeflixLive : ConfigurableAnimeSource, AnimeHttpSource() {

companion object {
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 PREF_DOMAIN_KEY = "pref_domain_key"
Expand Down