fix(pt/goanimes): Fix video extraction (#3079)

This commit is contained in:
Edgard Lorraine Messias 2024-03-29 13:04:03 -03:00 committed by GitHub
parent 8bedaa3063
commit 419d9a7a64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 48 additions and 10 deletions

View File

@ -3,7 +3,7 @@ ext {
extClass = '.GoAnimes'
themePkg = 'dooplay'
baseUrl = 'https://goanimes.net'
overrideVersionCode = 11
overrideVersionCode = 12
isNsfw = true
}

View File

@ -86,7 +86,6 @@ class GoAnimes : DooPlay(
.replace("SD", "480p")
val url = getPlayerUrl(player)
return when {
"player5.goanimes.net" in url -> goanimesExtractor.videosFromUrl(url, name)
"https://gojopoolt" in url -> {
val headers = headers.newBuilder()
.set("referer", url)
@ -129,7 +128,7 @@ class GoAnimes : DooPlay(
listOf("/bloggerjwplayer", "/m3u8", "/multivideo").any { it in url } -> {
val script = client.newCall(GET(url)).await()
.body.string()
.let(JsDecoder::decodeScript)
.let { JsDecoder.decodeScript(it, true).ifBlank { JsDecoder.decodeScript(it, false).ifBlank { it } } }
when {
"/bloggerjwplayer" in url ->
BloggerJWPlayerExtractor.videosFromScript(script)
@ -145,7 +144,7 @@ class GoAnimes : DooPlay(
}
}
"www.blogger.com" in url -> bloggerExtractor.videosFromUrl(url, headers)
else -> emptyList<Video>()
else -> goanimesExtractor.videosFromUrl(url, name)
}
}

View File

@ -15,9 +15,16 @@ class GoAnimesExtractor(private val client: OkHttpClient, private val headers: H
fun videosFromUrl(url: String, name: String): List<Video> {
val body = client.newCall(GET(url, headers)).execute()
.body.string()
val decodedBody = JsUnpacker.unpackAndCombine(body)
?: JsDecoder.decodeScript(body, false).takeIf(String::isNotEmpty)
?: JsDecoder.decodeScript(body, true).takeIf(String::isNotEmpty)
?: body
val partialName = name.split('-').first().trim()
val resolution = name.split('-').last().trim()
return when {
"better-go.fun/player.php" in url || "/profix/player.php" in url ->
PlaylistExtractor.videosFromScript(body, name.split('-').first().trim())
"/proxy/v.php" in url -> {
val playlistUrl = JsUnpacker.unpackAndCombine(body)
?.substringAfterLast("player(\\'", "")
@ -25,7 +32,11 @@ class GoAnimesExtractor(private val client: OkHttpClient, private val headers: H
?.takeIf(String::isNotEmpty)
?: return emptyList()
playlistUtils.extractFromHls(playlistUrl, url, videoNameGen = { "$name - $it" })
playlistUtils.extractFromHls(
playlistUrl,
url,
videoNameGen = { "$partialName - ${it.replace("Video", resolution)}" },
)
}
"/proxy/api3/" in url -> {
val playlistUrl = body.substringAfter("sources:", "")
@ -43,7 +54,24 @@ class GoAnimesExtractor(private val client: OkHttpClient, private val headers: H
}
val referer = url.toHttpUrl().queryParameter("url") ?: url
playlistUtils.extractFromHls(fixedUrl, referer, videoNameGen = { "$name - $it" })
playlistUtils.extractFromHls(
fixedUrl,
referer,
videoNameGen = { "$partialName - ${it.replace("Video", resolution)}" },
)
}
"jwplayer" in decodedBody && "sources:" in decodedBody -> {
val videos = PlaylistExtractor.videosFromScript(decodedBody, partialName)
if ("label:" !in decodedBody && videos.size === 1) {
return playlistUtils.extractFromHls(
videos[0].url,
url,
videoNameGen = { "$partialName - ${it.replace("Video", resolution)}" },
)
}
videos
}
else -> emptyList()
}

View File

@ -7,8 +7,19 @@ object PlaylistExtractor {
val sources = script.substringAfter("sources: [").substringBefore("],")
return sources.split("{").drop(1).mapNotNull { source ->
val url = source.substringAfter("file:").substringAfter('"').substringBefore('"')
.ifEmpty { return@mapNotNull null }
val url = source.substringAfter("file:")
.substringAfter('"', "")
.substringBefore('"', "")
.takeIf(String::isNotEmpty)
?: source.substringAfter("file:")
.substringAfter("'", "")
.substringBefore("'", "")
.takeIf(String::isNotEmpty)
if (url.isNullOrBlank()) {
return@mapNotNull null
}
val label = source.substringAfter("label:").substringAfter('"').substringBefore('"')
.replace("FHD", "1080p")
.replace("HD", "720p")