New source: Animes Aria (#1448)
* feat: Add AnimesAria base * feat: Implement latest animes page * feat: Implement popular animes page * feat: Implement anime details page * feat: Implement episode list * feat: Implement episode video list * feat: Implement search engine * feat: Implement search filters * fix: Fix URL intent handler * chore: Add source icon
This commit is contained in:
24
src/pt/animesaria/AndroidManifest.xml
Normal file
24
src/pt/animesaria/AndroidManifest.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="eu.kanade.tachiyomi.animeextension">
|
||||||
|
|
||||||
|
<application>
|
||||||
|
<activity
|
||||||
|
android:name=".pt.animesaria.AnimesAriaUrlActivity"
|
||||||
|
android:excludeFromRecents="true"
|
||||||
|
android:exported="true"
|
||||||
|
android:theme="@android:style/Theme.NoDisplay">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
|
||||||
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
<category android:name="android.intent.category.BROWSABLE" />
|
||||||
|
|
||||||
|
<data
|
||||||
|
android:host="animesaria.com"
|
||||||
|
android:pathPattern="/anime/..*/..*"
|
||||||
|
android:scheme="https" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
13
src/pt/animesaria/build.gradle
Normal file
13
src/pt/animesaria/build.gradle
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
plugins {
|
||||||
|
alias(libs.plugins.android.application)
|
||||||
|
alias(libs.plugins.kotlin.android)
|
||||||
|
}
|
||||||
|
|
||||||
|
ext {
|
||||||
|
extName = 'Animes Aria'
|
||||||
|
pkgNameSuffix = 'pt.animesaria'
|
||||||
|
extClass = '.AnimesAria'
|
||||||
|
extVersionCode = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$rootDir/common.gradle"
|
BIN
src/pt/animesaria/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
src/pt/animesaria/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
BIN
src/pt/animesaria/res/mipmap-mdpi/ic_launcher.png
Normal file
BIN
src/pt/animesaria/res/mipmap-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.5 KiB |
BIN
src/pt/animesaria/res/mipmap-xhdpi/ic_launcher.png
Normal file
BIN
src/pt/animesaria/res/mipmap-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.2 KiB |
BIN
src/pt/animesaria/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
src/pt/animesaria/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
BIN
src/pt/animesaria/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
BIN
src/pt/animesaria/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
@ -0,0 +1,197 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.animesaria
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.animeextension.pt.animesaria.extractors.LinkfunBypasser
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.AnimesPage
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.SAnime
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.SEpisode
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.Video
|
||||||
|
import eu.kanade.tachiyomi.animesource.online.ParsedAnimeHttpSource
|
||||||
|
import eu.kanade.tachiyomi.network.GET
|
||||||
|
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||||
|
import eu.kanade.tachiyomi.util.asJsoup
|
||||||
|
import okhttp3.Headers
|
||||||
|
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
|
import org.jsoup.nodes.Document
|
||||||
|
import org.jsoup.nodes.Element
|
||||||
|
import rx.Observable
|
||||||
|
|
||||||
|
class AnimesAria : ParsedAnimeHttpSource() {
|
||||||
|
|
||||||
|
override val name = "Animes Aria"
|
||||||
|
|
||||||
|
override val baseUrl = "https://animesaria.com"
|
||||||
|
|
||||||
|
override val lang = "pt-BR"
|
||||||
|
|
||||||
|
override val supportsLatest = true
|
||||||
|
|
||||||
|
// ============================== Popular ===============================
|
||||||
|
override fun popularAnimeFromElement(element: Element): SAnime {
|
||||||
|
return SAnime.create().apply {
|
||||||
|
setUrlWithoutDomain(element.attr("href"))
|
||||||
|
title = element.attr("title")
|
||||||
|
thumbnail_url = element.selectFirst("img")!!.attr("src")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun popularAnimeNextPageSelector() = latestUpdatesNextPageSelector()
|
||||||
|
|
||||||
|
override fun popularAnimeRequest(page: Int) = GET("$baseUrl/novos/animes?page=$page")
|
||||||
|
|
||||||
|
override fun popularAnimeSelector() = "div.item > a"
|
||||||
|
|
||||||
|
// ============================== Episodes ==============================
|
||||||
|
override fun episodeListParse(response: Response) = super.episodeListParse(response).reversed()
|
||||||
|
|
||||||
|
override fun episodeFromElement(element: Element): SEpisode {
|
||||||
|
return SEpisode.create().apply {
|
||||||
|
element.parent()!!.selectFirst("a > b")!!.ownText().let {
|
||||||
|
name = it
|
||||||
|
episode_number = it.substringAfter(" ").toFloat()
|
||||||
|
}
|
||||||
|
setUrlWithoutDomain(element.attr("href"))
|
||||||
|
scanlator = element.text().substringAfter(" ") // sub/dub
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun episodeListSelector() = "td div.clear > a.btn-xs"
|
||||||
|
|
||||||
|
// =========================== Anime Details ============================
|
||||||
|
override fun animeDetailsParse(document: Document): SAnime {
|
||||||
|
return SAnime.create().apply {
|
||||||
|
val row = document.selectFirst("div.anime_background_w div.row")!!
|
||||||
|
title = row.selectFirst("h1 > span")!!.text()
|
||||||
|
status = row.selectFirst("div.clear span.btn")?.text().toStatus()
|
||||||
|
thumbnail_url = document.selectFirst("link[as=image]")!!.attr("href")
|
||||||
|
genre = row.select("div.clear a.btn").eachText().joinToString()
|
||||||
|
|
||||||
|
description = buildString {
|
||||||
|
document.selectFirst("li.active > small")!!
|
||||||
|
.ownText()
|
||||||
|
.substringAfter(": ")
|
||||||
|
.let(::append)
|
||||||
|
|
||||||
|
append("\n\n")
|
||||||
|
|
||||||
|
row.selectFirst("h1 > small")?.text()?.let {
|
||||||
|
append("Títulos Alternativos: $it\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Additional info
|
||||||
|
row.select("div.pull-right > a").forEach {
|
||||||
|
val title = it.selectFirst("small")!!.text()
|
||||||
|
val value = it.selectFirst("span")!!.text()
|
||||||
|
append("$title: $value\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================ Video Links =============================
|
||||||
|
override fun videoListParse(response: Response): List<Video> {
|
||||||
|
val document = response.asJsoup()
|
||||||
|
val formUrl = document.selectFirst("center > a.btn")!!.attr("href")
|
||||||
|
val bypasser = LinkfunBypasser(client)
|
||||||
|
return client.newCall(GET(formUrl, headers))
|
||||||
|
.execute()
|
||||||
|
.use(bypasser::getIframeResponse)
|
||||||
|
.use(::extractVideoFromResponse)
|
||||||
|
.let(::listOf)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun extractVideoFromResponse(response: Response): Video {
|
||||||
|
val decodedBody = LinkfunBypasser.decodeAtob(response.body.string())
|
||||||
|
val url = decodedBody
|
||||||
|
.substringAfter("sources")
|
||||||
|
.substringAfter("file: \"")
|
||||||
|
.substringBefore('"')
|
||||||
|
val videoHeaders = Headers.headersOf("Referer", response.request.url.toString())
|
||||||
|
return Video(url, "default", url, videoHeaders)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun videoFromElement(element: Element): Video {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun videoListSelector(): String {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun videoUrlParse(document: Document): String {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
// =============================== Search ===============================
|
||||||
|
override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element)
|
||||||
|
|
||||||
|
override fun searchAnimeNextPageSelector() = latestUpdatesNextPageSelector()
|
||||||
|
|
||||||
|
override fun getFilterList(): AnimeFilterList = AnimesAriaFilters.filterList
|
||||||
|
|
||||||
|
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
|
||||||
|
val params = AnimesAriaFilters.getSearchParameters(filters)
|
||||||
|
val url = "$baseUrl/anime/buscar".toHttpUrl().newBuilder()
|
||||||
|
.addQueryParameter("q", query)
|
||||||
|
.addQueryParameter("page", page.toString())
|
||||||
|
.addQueryParameter("tipo", params.type)
|
||||||
|
.addQueryParameter("genero", params.genre)
|
||||||
|
.addQueryParameter("status", params.status)
|
||||||
|
.addQueryParameter("letra", params.letter)
|
||||||
|
.addQueryParameter("audio", params.audio)
|
||||||
|
.addQueryParameter("ano", params.year)
|
||||||
|
.addQueryParameter("temporada", params.season)
|
||||||
|
.build()
|
||||||
|
return GET(url.toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun searchAnimeSelector() = popularAnimeSelector()
|
||||||
|
|
||||||
|
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
|
||||||
|
return if (query.startsWith(PREFIX_SEARCH)) { // URL intent handler
|
||||||
|
val id = query.removePrefix(PREFIX_SEARCH)
|
||||||
|
client.newCall(GET("$baseUrl/anime/$id"))
|
||||||
|
.asObservableSuccess()
|
||||||
|
.map { response ->
|
||||||
|
searchAnimeByIdParse(response, id)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
super.fetchSearchAnime(page, query, filters)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun searchAnimeByIdParse(response: Response, id: String): AnimesPage {
|
||||||
|
val details = animeDetailsParse(response.asJsoup())
|
||||||
|
details.url = "/anime/$id"
|
||||||
|
return AnimesPage(listOf(details), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// =============================== Latest ===============================
|
||||||
|
override fun latestUpdatesFromElement(element: Element): SAnime {
|
||||||
|
return SAnime.create().apply {
|
||||||
|
thumbnail_url = element.selectFirst("img")!!.attr("src")
|
||||||
|
val ahref = element.selectFirst("a")!!
|
||||||
|
title = ahref.attr("title")
|
||||||
|
setUrlWithoutDomain(ahref.attr("href").substringBefore("/episodio/"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun latestUpdatesNextPageSelector() = "a:containsOwn(Próximo):not(.disabled)"
|
||||||
|
|
||||||
|
override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/novos/episodios?page=$page")
|
||||||
|
|
||||||
|
override fun latestUpdatesSelector() = "div.item > div.pos-rlt"
|
||||||
|
|
||||||
|
// ============================= Utilities ==============================
|
||||||
|
private fun String?.toStatus() = when (this) {
|
||||||
|
"Finalizado" -> SAnime.COMPLETED
|
||||||
|
"Lançamento" -> SAnime.ONGOING
|
||||||
|
else -> SAnime.UNKNOWN
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val PREFIX_SEARCH = "id:"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,154 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.animesaria
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
||||||
|
|
||||||
|
object AnimesAriaFilters {
|
||||||
|
|
||||||
|
open class QueryPartFilter(
|
||||||
|
displayName: String,
|
||||||
|
val vals: Array<Pair<String, String>>,
|
||||||
|
) : AnimeFilter.Select<String>(
|
||||||
|
displayName,
|
||||||
|
vals.map { it.first }.toTypedArray(),
|
||||||
|
) {
|
||||||
|
fun toQueryPart() = vals[state].second
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun <reified R> AnimeFilterList.asQueryPart(): String {
|
||||||
|
return this.first { it is R }.let {
|
||||||
|
(it as QueryPartFilter).toQueryPart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TypeFilter : QueryPartFilter("Tipo", AnimesAriaFiltersData.types)
|
||||||
|
class GenreFilter : QueryPartFilter("Gênero", AnimesAriaFiltersData.genres)
|
||||||
|
class StatusFilter : QueryPartFilter("Status", AnimesAriaFiltersData.status)
|
||||||
|
class LetterFilter : QueryPartFilter("Letra inicial", AnimesAriaFiltersData.letters)
|
||||||
|
class AudioFilter : QueryPartFilter("Áudio", AnimesAriaFiltersData.audio)
|
||||||
|
class YearFilter : QueryPartFilter("Ano", AnimesAriaFiltersData.years)
|
||||||
|
class SeasonFilter : QueryPartFilter("Temporada", AnimesAriaFiltersData.seasons)
|
||||||
|
|
||||||
|
val filterList = AnimeFilterList(
|
||||||
|
TypeFilter(),
|
||||||
|
GenreFilter(),
|
||||||
|
StatusFilter(),
|
||||||
|
LetterFilter(),
|
||||||
|
AudioFilter(),
|
||||||
|
YearFilter(),
|
||||||
|
SeasonFilter(),
|
||||||
|
)
|
||||||
|
|
||||||
|
data class FilterSearchParams(
|
||||||
|
val type: String,
|
||||||
|
val genre: String,
|
||||||
|
val status: String,
|
||||||
|
val letter: String,
|
||||||
|
val audio: String,
|
||||||
|
val year: String,
|
||||||
|
val season: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
internal fun getSearchParameters(filters: AnimeFilterList): FilterSearchParams {
|
||||||
|
return FilterSearchParams(
|
||||||
|
filters.asQueryPart<TypeFilter>(),
|
||||||
|
filters.asQueryPart<GenreFilter>(),
|
||||||
|
filters.asQueryPart<StatusFilter>(),
|
||||||
|
filters.asQueryPart<LetterFilter>(),
|
||||||
|
filters.asQueryPart<AudioFilter>(),
|
||||||
|
filters.asQueryPart<YearFilter>(),
|
||||||
|
filters.asQueryPart<SeasonFilter>(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private object AnimesAriaFiltersData {
|
||||||
|
val every = Pair("Todos", "todos")
|
||||||
|
val every_f = Pair("Todas", "todas")
|
||||||
|
|
||||||
|
val types = arrayOf(
|
||||||
|
every,
|
||||||
|
Pair("Série de TV", "serie"),
|
||||||
|
Pair("OVA", "ova"),
|
||||||
|
Pair("Filme", "filme"),
|
||||||
|
Pair("Especial", "especial"),
|
||||||
|
Pair("ONA", "ona"),
|
||||||
|
)
|
||||||
|
|
||||||
|
val genres = arrayOf(
|
||||||
|
every,
|
||||||
|
Pair("Ação", "acao"),
|
||||||
|
Pair("Artes Maciais", "artes_maciais"),
|
||||||
|
Pair("Aventura", "aventura"),
|
||||||
|
Pair("Carros", "carros"),
|
||||||
|
Pair("Comédia", "comedia"),
|
||||||
|
Pair("Demência", "demencia"),
|
||||||
|
Pair("Demônios", "demonios"),
|
||||||
|
Pair("Drama", "drama"),
|
||||||
|
Pair("Ecchi", "ecchi"),
|
||||||
|
Pair("Erótico", "erotico"),
|
||||||
|
Pair("Escolar", "escolar"),
|
||||||
|
Pair("Espaço", "espaco"),
|
||||||
|
Pair("Esporte", "esporte"),
|
||||||
|
Pair("Fantasia", "fantasia"),
|
||||||
|
Pair("Ficção Científica", "ficcao_cientifica"),
|
||||||
|
Pair("Gourmet", "gourmet"),
|
||||||
|
Pair("Harem", "harem"),
|
||||||
|
Pair("Hentai", "hentai"),
|
||||||
|
Pair("Histórico", "historico"),
|
||||||
|
Pair("Infantil", "infantil"),
|
||||||
|
Pair("Jogos", "jogos"),
|
||||||
|
Pair("Josei", "josei"),
|
||||||
|
Pair("Magia", "magia"),
|
||||||
|
Pair("Mecha", "mecha"),
|
||||||
|
Pair("Militar", "militar"),
|
||||||
|
Pair("Mistério", "misterio"),
|
||||||
|
Pair("Música", "musica"),
|
||||||
|
Pair("Paródia", "parodia"),
|
||||||
|
Pair("Polícia", "policia"),
|
||||||
|
Pair("Psicológico", "psicologico"),
|
||||||
|
Pair("Romance", "romance"),
|
||||||
|
Pair("Samurai", "samurai"),
|
||||||
|
Pair("Seinen", "seinen"),
|
||||||
|
Pair("Shoujo", "shoujo"),
|
||||||
|
Pair("Shoujo Ai", "shoujo_ai"),
|
||||||
|
Pair("Shounen", "shounen"),
|
||||||
|
Pair("Shounen Ai", "shounen_ai"),
|
||||||
|
Pair("Sobrenatural", "sobrenatural"),
|
||||||
|
Pair("Super Poder", "super_poder"),
|
||||||
|
Pair("Terror", "terror"),
|
||||||
|
Pair("Thriller", "thriller"),
|
||||||
|
Pair("Vampiro", "vampiro"),
|
||||||
|
Pair("Vida Diária", "vida_diaria"),
|
||||||
|
Pair("Yaoi", "yaoi"),
|
||||||
|
Pair("Yuri", "yuri"),
|
||||||
|
)
|
||||||
|
|
||||||
|
val status = arrayOf(
|
||||||
|
every,
|
||||||
|
Pair("Em lançamento", "lancamento"),
|
||||||
|
Pair("Finalizado", "finalizado"),
|
||||||
|
)
|
||||||
|
|
||||||
|
val letters = arrayOf(every_f) + ('A'..'Z').map {
|
||||||
|
Pair(it.toString(), it.toString().lowercase())
|
||||||
|
}.toTypedArray()
|
||||||
|
|
||||||
|
val audio = arrayOf(
|
||||||
|
every,
|
||||||
|
Pair("Dublado", "dublado"),
|
||||||
|
Pair("Legendado", "legendado"),
|
||||||
|
)
|
||||||
|
|
||||||
|
val years = arrayOf(every) + (2023 downTo 1962).map {
|
||||||
|
Pair(it.toString(), it.toString())
|
||||||
|
}.toTypedArray()
|
||||||
|
|
||||||
|
val seasons = arrayOf(
|
||||||
|
every_f,
|
||||||
|
Pair("Primavera", "primavera"),
|
||||||
|
Pair("Verão", "verao"),
|
||||||
|
Pair("Outono", "outono"),
|
||||||
|
Pair("Inverno", "inverno"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.animesaria
|
||||||
|
|
||||||
|
import android.app.Activity
|
||||||
|
import android.content.ActivityNotFoundException
|
||||||
|
import android.content.Intent
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Springboard that accepts https://animesaria.com/anime/<id>/<slug> intents
|
||||||
|
* and redirects them to the main Aniyomi process.
|
||||||
|
*/
|
||||||
|
class AnimesAriaUrlActivity : Activity() {
|
||||||
|
|
||||||
|
private val TAG = javaClass.simpleName
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
val pathSegments = intent?.data?.pathSegments
|
||||||
|
if (pathSegments != null && pathSegments.size > 1) {
|
||||||
|
val id = pathSegments[1]
|
||||||
|
val slug = pathSegments[2]
|
||||||
|
val mainIntent = Intent().apply {
|
||||||
|
action = "eu.kanade.tachiyomi.ANIMESEARCH"
|
||||||
|
putExtra("query", "${AnimesAria.PREFIX_SEARCH}$id/$slug")
|
||||||
|
putExtra("filter", packageName)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
startActivity(mainIntent)
|
||||||
|
} catch (e: ActivityNotFoundException) {
|
||||||
|
Log.e(TAG, e.toString())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "could not parse uri from intent $intent")
|
||||||
|
}
|
||||||
|
|
||||||
|
finish()
|
||||||
|
exitProcess(0)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.animesaria.extractors
|
||||||
|
|
||||||
|
import android.util.Base64
|
||||||
|
import eu.kanade.tachiyomi.network.GET
|
||||||
|
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 getIframeResponse(response: Response): Response {
|
||||||
|
return response.use { page ->
|
||||||
|
val document = page.asJsoup(decodeAtob(page.body.string()))
|
||||||
|
val newHeaders = Headers.headersOf("Referer", response.request.url.toString())
|
||||||
|
|
||||||
|
val iframe = document.selectFirst("iframe")
|
||||||
|
|
||||||
|
if (iframe != null) {
|
||||||
|
client.newCall(GET(iframe.attr("src"), newHeaders))
|
||||||
|
.execute()
|
||||||
|
} 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()
|
||||||
|
.use(::getIframeResponse)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user