Initial commit

This commit is contained in:
almightyhak 2024-06-20 11:54:12 +07:00
commit 98ed7e8839
2263 changed files with 108711 additions and 0 deletions

View file

@ -0,0 +1,16 @@
ext {
extName = 'GoAnimes'
extClass = '.GoAnimes'
themePkg = 'dooplay'
baseUrl = 'https://goanimes.net'
overrideVersionCode = 13
isNsfw = true
}
apply from: "$rootDir/common.gradle"
dependencies {
implementation(project(":lib:playlist-utils"))
implementation(project(":lib:blogger-extractor"))
implementation("dev.datlag.jsunpacker:jsunpacker:1.0.1")
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

View file

@ -0,0 +1,185 @@
package eu.kanade.tachiyomi.animeextension.pt.goanimes
import eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors.BloggerJWPlayerExtractor
import eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors.GoAnimesExtractor
import eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors.JsDecoder
import eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors.LinkfunBypasser
import eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors.PlaylistExtractor
import eu.kanade.tachiyomi.animesource.model.SEpisode
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.lib.bloggerextractor.BloggerExtractor
import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils
import eu.kanade.tachiyomi.multisrc.dooplay.DooPlay
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.await
import eu.kanade.tachiyomi.util.asJsoup
import eu.kanade.tachiyomi.util.parallelCatchingFlatMapBlocking
import okhttp3.Response
import org.jsoup.nodes.Element
class GoAnimes : DooPlay(
"pt-BR",
"GoAnimes",
"https://goanimes.net",
) {
// ============================== Popular ===============================
override fun popularAnimeSelector() = "div#featured-titles article.item.tvshows > div.poster"
// =============================== Latest ===============================
override val latestUpdatesPath = "lancamentos"
// ============================== Episodes ==============================
override val seasonListSelector = "div#seasons > *"
override fun getSeasonEpisodes(season: Element): List<SEpisode> {
// All episodes are listed under a single page
season.selectFirst(episodeListSelector())?.let {
return getSeasonEpisodesRecursive(season)
}
// Episodes are listed at another page
val url = season.attr("href")
return client.newCall(GET(url, headers))
.execute()
.asJsoup()
.let(::getSeasonEpisodes)
}
private val episodeListNextPageSelector = "div.pagination span.current + a:not(.arrow_pag)"
private fun getSeasonEpisodesRecursive(season: Element): List<SEpisode> {
var doc = season.root()
return buildList {
do {
if (isNotEmpty()) {
doc.selectFirst(episodeListNextPageSelector)?.let {
val url = it.attr("abs:href")
doc = client.newCall(GET(url, headers)).execute()
.asJsoup()
}
}
addAll(super.getSeasonEpisodes(doc))
} while (doc.selectFirst(episodeListNextPageSelector) != null)
reversed()
}
}
// ============================ Video Links =============================
override val prefQualityValues = arrayOf("240p", "360p", "480p", "720p", "1080p")
override val prefQualityEntries = prefQualityValues
private val goanimesExtractor by lazy { GoAnimesExtractor(client, headers) }
private val bloggerExtractor by lazy { BloggerExtractor(client) }
private val linkfunBypasser by lazy { LinkfunBypasser(client) }
private val playlistUtils by lazy { PlaylistUtils(client, headers) }
override fun videoListParse(response: Response): List<Video> {
val document = response.asJsoup()
val players = document.select("ul#playeroptionsul li")
return players.parallelCatchingFlatMapBlocking(::getPlayerVideos)
}
private suspend fun getPlayerVideos(player: Element): List<Video> {
val name = player.selectFirst("span.title")!!.text()
.replace("FULLHD", "1080p")
.replace("HD", "720p")
.replace("SD", "480p")
val url = getPlayerUrl(player)
return when {
"https://gojopoolt" in url -> {
val headers = headers.newBuilder()
.set("referer", url)
.build()
val script = client.newCall(GET(url, headers)).await()
.body.string()
.let { JsDecoder.decodeScript(it, false).ifBlank { it } }
script.substringAfter("sources: [")
.substringBefore(']')
.split('{')
.drop(1)
.mapNotNull {
val videoUrl = it.substringAfter("file: ")
.substringBefore(", ")
.trim('"', '\'', ' ')
.ifBlank { return@mapNotNull null }
val resolution = it.substringAfter("label: ", "")
.substringAfter('"')
.substringBefore('"')
.ifBlank { name.split('-').last().trim() }
val partialName = name.split('-').first().trim()
return when {
videoUrl.contains(".m3u8") -> {
playlistUtils.extractFromHls(
videoUrl,
url,
videoNameGen = {
"$partialName - ${it.replace("Video", resolution)}"
},
)
}
else -> listOf(Video(videoUrl, "$partialName - $resolution", videoUrl, headers))
}
}
}
listOf("/bloggerjwplayer", "/m3u8", "/multivideo").any { it in url } -> {
val script = client.newCall(GET(url)).await()
.body.string()
.let { JsDecoder.decodeScript(it, true).ifBlank { JsDecoder.decodeScript(it, false).ifBlank { it } } }
when {
"/bloggerjwplayer" in url ->
BloggerJWPlayerExtractor.videosFromScript(script)
"/m3u8" in url ->
PlaylistExtractor.videosFromScript(script)
"/multivideo" in url ->
script.substringAfter("attr")
.substringAfter(" \"")
.substringBefore('"')
.let { goanimesExtractor.videosFromUrl(it, name) }
else -> emptyList<Video>()
}
}
"www.blogger.com" in url -> bloggerExtractor.videosFromUrl(url, headers)
else -> goanimesExtractor.videosFromUrl(url, name)
}
}
private suspend fun getPlayerUrl(player: Element): String {
val type = player.attr("data-type")
val id = player.attr("data-post")
val num = player.attr("data-nume")
val url = client.newCall(GET("$baseUrl/wp-json/dooplayer/v2/$id/$type/$num"))
.await()
.body.string()
.substringAfter("\"embed_url\":\"")
.substringBefore("\",")
.replace("\\", "")
return when {
"/protetorlinks/" in url -> {
val link = client.newCall(GET(url)).await()
.asJsoup()
.selectFirst("a[href]")!!.attr("href")
client.newCall(GET(link)).await()
.use(linkfunBypasser::getIframeUrl)
}
else -> url
}
}
// ============================= Utilities ==============================
override fun List<Video>.sort(): List<Video> {
val quality = preferences.getString(videoSortPrefKey, videoSortPrefDefault)!!
return sortedWith(
compareBy(
{ it.quality.contains(quality) },
{ Regex("""(\d+)p""").find(it.quality)?.groupValues?.get(1)?.toIntOrNull() ?: 0 },
),
).reversed()
}
}

View file

@ -0,0 +1,18 @@
package eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors
import eu.kanade.tachiyomi.animesource.model.Video
object BloggerJWPlayerExtractor {
fun videosFromScript(script: String): List<Video> {
val sources = script.substringAfter("sources: [").substringBefore("],")
return sources.split("{").drop(1).map {
val label = it.substringAfter("label").substringAfter(":\"").substringBefore('"')
val videoUrl = it.substringAfter("file")
.substringAfter(":\"")
.substringBefore('"')
.replace("\\", "")
Video(videoUrl, "BloggerJWPlayer - $label", videoUrl)
}
}
}

View file

@ -0,0 +1,81 @@
package eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors
import android.util.Base64
import dev.datlag.jsunpacker.JsUnpacker
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.lib.playlistutils.PlaylistUtils
import eu.kanade.tachiyomi.network.GET
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
class GoAnimesExtractor(private val client: OkHttpClient, private val headers: Headers) {
private val playlistUtils by lazy { PlaylistUtils(client, headers) }
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 {
"/proxy/v.php" in url -> {
val playlistUrl = JsUnpacker.unpackAndCombine(body)
?.substringAfterLast("player(\\'", "")
?.substringBefore("\\'", "")
?.takeIf(String::isNotEmpty)
?: return emptyList()
playlistUtils.extractFromHls(
playlistUrl,
url,
videoNameGen = { "$partialName - ${it.replace("Video", resolution)}" },
)
}
"/proxy/api3/" in url -> {
val playlistUrl = body.substringAfter("sources:", "")
.substringAfter("file:", "")
.substringAfter("'", "")
.substringBefore("'", "")
.takeIf(String::isNotEmpty)
?: return emptyList()
val fixedUrl = if (playlistUrl.contains("/aHR0")) {
val encoded = playlistUrl.substringAfterLast("/").substringBefore(".")
String(Base64.decode(encoded, Base64.DEFAULT))
} else {
playlistUrl
}
val referer = url.toHttpUrl().queryParameter("url") ?: url
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()
}
}
}
private const val PLAYER_NAME = "GoAnimes"

View file

@ -0,0 +1,48 @@
package eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors
import android.util.Base64
import kotlin.math.pow
object JsDecoder {
private fun convertToNum(thing: String, limit: Float): Int {
return thing.split("")
.reversed()
.map { it.toIntOrNull() ?: 0 }
.reduceIndexed { index: Int, acc, num ->
acc + (num * limit.pow(index - 1)).toInt()
}
}
fun decodeScript(encodedString: String, magicStr: String, offset: Int, limit: Int): String {
val regex = "\\w".toRegex()
return encodedString
.split(magicStr[limit])
.dropLast(1)
.map { str ->
val replaced = regex.replace(str) { magicStr.indexOf(it.value).toString() }
val charInt = convertToNum(replaced, limit.toFloat()) - offset
Char(charInt)
}.joinToString("")
}
fun decodeScript(html: String, isB64: Boolean = true): String {
val script = if (isB64) {
html.substringAfter(";base64,")
.substringBefore('"')
.let { String(Base64.decode(it, Base64.DEFAULT)) }
} else {
html
}
val regex = """\}\("(\w+)",.*?"(\w+)",(\d+),(\d+),.*?\)""".toRegex()
return regex.find(script)
?.run {
decodeScript(
groupValues[1], // encoded data
groupValues[2], // magic string
groupValues[3].toIntOrNull() ?: 0, // offset
groupValues[4].toIntOrNull() ?: 0, // limit
)
} ?: ""
}
}

View file

@ -0,0 +1,54 @@
package eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors
import android.util.Base64
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.FormBody
import okhttp3.Headers
import okhttp3.OkHttpClient
import okhttp3.Response
class LinkfunBypasser(private val client: OkHttpClient) {
fun getIframeUrl(page: Response): String {
val docString = page.body.string()
val document = if (docString.startsWith("<script")) {
page.asJsoup(decodeAtob(docString))
} else { page.asJsoup(docString) }
val newHeaders = Headers.headersOf("Referer", document.location())
val iframe = document.selectFirst("iframe[src]")
return if (iframe != null) {
iframe.attr("src")
} else {
val formBody = FormBody.Builder().apply {
document.select("input[name]").forEach {
add(it.attr("name"), it.attr("value"))
}
}.build()
val formUrl = document.selectFirst("form")!!.attr("action")
client.newCall(POST(formUrl, newHeaders, formBody))
.execute()
.let(::getIframeUrl)
}
}
companion object {
fun decodeAtob(html: String): String {
val atobContent = html.substringAfter("atob(\"").substringBefore("\"));")
val hexAtob = atobContent.replace("\\x", "").decodeHex()
val decoded = Base64.decode(hexAtob, Base64.DEFAULT)
return String(decoded)
}
// Stolen from AnimixPlay(EN) / GogoCdnExtractor
private fun String.decodeHex(): ByteArray {
check(length % 2 == 0) { "Must have an even length" }
return chunked(2)
.map { it.toInt(16).toByte() }
.toByteArray()
}
}
}

View file

@ -0,0 +1,30 @@
package eu.kanade.tachiyomi.animeextension.pt.goanimes.extractors
import eu.kanade.tachiyomi.animesource.model.Video
object PlaylistExtractor {
fun videosFromScript(script: String, prefix: String = "Playlist"): List<Video> {
val sources = script.substringAfter("sources: [").substringBefore("],")
return sources.split("{").drop(1).mapNotNull { source ->
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")
.replace("SD", "480p")
Video(url, "$prefix - $label", url)
}
}
}