Skip to content

Commit

Permalink
fix(pt/goanimes): Fix video extraction (#3079)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias authored Mar 29, 2024
1 parent 8bedaa3 commit 419d9a7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/pt/goanimes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ext {
extClass = '.GoAnimes'
themePkg = 'dooplay'
baseUrl = 'https://goanimes.net'
overrideVersionCode = 11
overrideVersionCode = 12
isNsfw = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -145,7 +144,7 @@ class GoAnimes : DooPlay(
}
}
"www.blogger.com" in url -> bloggerExtractor.videosFromUrl(url, headers)
else -> emptyList<Video>()
else -> goanimesExtractor.videosFromUrl(url, name)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,28 @@ 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(\\'", "")
?.substringBefore("\\'", "")
?.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:", "")
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 419d9a7

Please sign in to comment.