New source: AnimesUp (#1007)
* Add AnimesUP base * Create AnimesUp extractor * Create LegacyFun extractor * Implement search filters
This commit is contained in:
24
src/pt/animesup/AndroidManifest.xml
Normal file
24
src/pt/animesup/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.animesup.AnimesUpUrlActivity"
|
||||||
|
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="animesup.biz"
|
||||||
|
android:pathPattern="/animes/..*"
|
||||||
|
android:scheme="https" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
16
src/pt/animesup/build.gradle
Normal file
16
src/pt/animesup/build.gradle
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
|
||||||
|
ext {
|
||||||
|
extName = 'AnimesUP'
|
||||||
|
pkgNameSuffix = 'pt.animesup'
|
||||||
|
extClass = '.AnimesUp'
|
||||||
|
extVersionCode = 1
|
||||||
|
libVersion = '13'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "dev.datlag.jsunpacker:jsunpacker:1.0.1"
|
||||||
|
}
|
||||||
|
|
||||||
|
apply from: "$rootDir/common.gradle"
|
BIN
src/pt/animesup/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
src/pt/animesup/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.4 KiB |
BIN
src/pt/animesup/res/mipmap-mdpi/ic_launcher.png
Normal file
BIN
src/pt/animesup/res/mipmap-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
BIN
src/pt/animesup/res/mipmap-xhdpi/ic_launcher.png
Normal file
BIN
src/pt/animesup/res/mipmap-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.8 KiB |
BIN
src/pt/animesup/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
src/pt/animesup/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.4 KiB |
BIN
src/pt/animesup/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
BIN
src/pt/animesup/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 14 KiB |
@ -0,0 +1,269 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.animesup
|
||||||
|
|
||||||
|
import android.net.Uri
|
||||||
|
import eu.kanade.tachiyomi.animeextension.pt.animesup.extractors.AnimesUpExtractor
|
||||||
|
import eu.kanade.tachiyomi.animeextension.pt.animesup.extractors.LegacyFunExtractor
|
||||||
|
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.OkHttpClient
|
||||||
|
import okhttp3.Request
|
||||||
|
import okhttp3.Response
|
||||||
|
import org.jsoup.nodes.Document
|
||||||
|
import org.jsoup.nodes.Element
|
||||||
|
import rx.Observable
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
|
import java.lang.Exception
|
||||||
|
|
||||||
|
class AnimesUp : ParsedAnimeHttpSource() {
|
||||||
|
|
||||||
|
override val name = "AnimesUp"
|
||||||
|
|
||||||
|
override val baseUrl = "https://animesup.biz"
|
||||||
|
|
||||||
|
override val lang = "pt-BR"
|
||||||
|
|
||||||
|
override val supportsLatest = true
|
||||||
|
|
||||||
|
override val client: OkHttpClient = network.client
|
||||||
|
|
||||||
|
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||||
|
.add("Referer", baseUrl)
|
||||||
|
|
||||||
|
// ============================== Popular ===============================
|
||||||
|
override fun popularAnimeSelector(): String = "article.w_item_b > a"
|
||||||
|
|
||||||
|
override fun popularAnimeRequest(page: Int): Request = GET("$baseUrl/animes/")
|
||||||
|
|
||||||
|
override fun popularAnimeFromElement(element: Element): SAnime {
|
||||||
|
val anime = SAnime.create()
|
||||||
|
val img = element.selectFirst("img")
|
||||||
|
val url = element.selectFirst("a")?.attr("href") ?: element.attr("href")
|
||||||
|
anime.setUrlWithoutDomain(url)
|
||||||
|
anime.title = img.attr("alt")
|
||||||
|
anime.thumbnail_url = img.attr("src")
|
||||||
|
return anime
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun popularAnimeNextPageSelector() = throw Exception("not used")
|
||||||
|
|
||||||
|
override fun popularAnimeParse(response: Response): AnimesPage {
|
||||||
|
val document = response.asJsoup()
|
||||||
|
val animes = document.select(popularAnimeSelector()).map { element ->
|
||||||
|
popularAnimeFromElement(element)
|
||||||
|
}
|
||||||
|
return AnimesPage(animes, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================== Episodes ==============================
|
||||||
|
override fun episodeListSelector(): String = "ul.episodios > li"
|
||||||
|
|
||||||
|
override fun episodeListParse(response: Response): List<SEpisode> {
|
||||||
|
val doc = getRealDoc(response.asJsoup())
|
||||||
|
val epList = doc.select(episodeListSelector())
|
||||||
|
if (epList.size < 1) {
|
||||||
|
val episode = SEpisode.create()
|
||||||
|
episode.setUrlWithoutDomain(response.request.url.toString())
|
||||||
|
episode.episode_number = 1F
|
||||||
|
episode.name = "Filme"
|
||||||
|
return listOf(episode)
|
||||||
|
}
|
||||||
|
return epList.reversed().map { episodeFromElement(it) }
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun episodeFromElement(element: Element): SEpisode {
|
||||||
|
val episode = SEpisode.create()
|
||||||
|
val origName = element.selectFirst("div.numerando").text()
|
||||||
|
|
||||||
|
episode.episode_number = origName.substringAfter("- ")
|
||||||
|
.replace("-", "")
|
||||||
|
.toFloat()
|
||||||
|
episode.name = "Temp " + origName.replace(" - ", ": Ep ")
|
||||||
|
episode.setUrlWithoutDomain(element.selectFirst("a").attr("href"))
|
||||||
|
return episode
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================ Video Links =============================
|
||||||
|
|
||||||
|
override fun videoListParse(response: Response): List<Video> {
|
||||||
|
val document = response.asJsoup()
|
||||||
|
val urls = document.select("div.source-box:not(#source-player-trailer) a,iframe")
|
||||||
|
.map { it.attr("href").ifEmpty { it.attr("src") } }
|
||||||
|
val resolutions = document.select("ul#playeroptionsul > li:not(#player-option-trailer)")
|
||||||
|
.mapIndexed { index, it ->
|
||||||
|
val quality = it.selectFirst("span:not(.loader)").text()
|
||||||
|
|
||||||
|
val videoUrl = urls.get(index)!!
|
||||||
|
when {
|
||||||
|
videoUrl.contains("/Player/Play") -> {
|
||||||
|
val newHeaders = Headers.headersOf(
|
||||||
|
"referer", response.request.url.toString()
|
||||||
|
)
|
||||||
|
AnimesUpExtractor(client)
|
||||||
|
.videoFromUrl(videoUrl, quality, newHeaders)
|
||||||
|
}
|
||||||
|
videoUrl.contains("blog.legacy") -> {
|
||||||
|
LegacyFunExtractor(client)
|
||||||
|
.videoFromUrl("https:" + videoUrl, quality)
|
||||||
|
}
|
||||||
|
else -> null
|
||||||
|
} ?: Video(videoUrl, quality, videoUrl)
|
||||||
|
}
|
||||||
|
return resolutions
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun videoListSelector() = throw Exception("not used")
|
||||||
|
override fun videoFromElement(element: Element) = throw Exception("not used")
|
||||||
|
override fun videoUrlParse(document: Document) = throw Exception("not used")
|
||||||
|
|
||||||
|
// =============================== Search ===============================
|
||||||
|
private fun searchAnimeBySlugParse(response: Response, slug: String): AnimesPage {
|
||||||
|
val details = animeDetailsParse(response)
|
||||||
|
details.url = "/animes/$slug"
|
||||||
|
return AnimesPage(listOf(details), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun searchAnimeParse(response: Response): AnimesPage {
|
||||||
|
val url = response.request.url.toString()
|
||||||
|
val document = response.asJsoup()
|
||||||
|
|
||||||
|
val animes = when {
|
||||||
|
"/genero/" in url -> {
|
||||||
|
document.select(latestUpdatesSelector()).map { element ->
|
||||||
|
popularAnimeFromElement(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
document.select(searchAnimeSelector()).map { element ->
|
||||||
|
searchAnimeFromElement(element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val hasNextPage = document.selectFirst(searchAnimeNextPageSelector()) != null
|
||||||
|
return AnimesPage(animes, hasNextPage)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
|
||||||
|
return if (query.startsWith(PREFIX_SEARCH)) {
|
||||||
|
val slug = query.removePrefix(PREFIX_SEARCH)
|
||||||
|
client.newCall(GET("$baseUrl/animes/$slug", headers))
|
||||||
|
.asObservableSuccess()
|
||||||
|
.map { response ->
|
||||||
|
searchAnimeBySlugParse(response, slug)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val params = AnimesUpFilters.getSearchParameters(filters)
|
||||||
|
client.newCall(searchAnimeRequest(page, query, params))
|
||||||
|
.asObservableSuccess()
|
||||||
|
.map { response ->
|
||||||
|
searchAnimeParse(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getFilterList(): AnimeFilterList = AnimesUpFilters.filterList
|
||||||
|
|
||||||
|
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList) = throw Exception("not used")
|
||||||
|
|
||||||
|
private fun searchAnimeRequest(page: Int, query: String, filters: AnimesUpFilters.FilterSearchParams): Request {
|
||||||
|
return when {
|
||||||
|
query.isBlank() -> {
|
||||||
|
val genre = filters.genre
|
||||||
|
var url = "$baseUrl/genero/$genre/"
|
||||||
|
if (page > 1) url += "page/$page"
|
||||||
|
GET(url, headers)
|
||||||
|
}
|
||||||
|
else -> GET("$baseUrl/page/$page/?s=$query", headers)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun searchAnimeFromElement(element: Element): SAnime {
|
||||||
|
val anime = SAnime.create()
|
||||||
|
anime.setUrlWithoutDomain(element.attr("href"))
|
||||||
|
anime.thumbnail_url = element.selectFirst("img")?.attr("src")
|
||||||
|
anime.title = element.text()
|
||||||
|
return anime
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun searchAnimeNextPageSelector(): String = latestUpdatesNextPageSelector()
|
||||||
|
|
||||||
|
override fun searchAnimeSelector(): String = "div.result-item div.details div.title a"
|
||||||
|
|
||||||
|
// =========================== Anime Details ============================
|
||||||
|
override fun animeDetailsParse(document: Document): SAnime {
|
||||||
|
val anime = SAnime.create()
|
||||||
|
val doc = getRealDoc(document)
|
||||||
|
val sheader = doc.selectFirst("div.sheader")
|
||||||
|
val img = sheader.selectFirst("div.poster img")
|
||||||
|
anime.thumbnail_url = img.attr("src")
|
||||||
|
anime.title = img.attr("alt")
|
||||||
|
val info = sheader.selectFirst("div.data")
|
||||||
|
anime.genre = info.select("div.sgeneros > a")
|
||||||
|
.joinToString(", ") { it.text() }
|
||||||
|
var description = doc.select("div.sinopse > div.texto")
|
||||||
|
.joinToString("\n") { it.text() } + "\n\n"
|
||||||
|
|
||||||
|
sheader.selectFirst("div.data > div.extra-title")?.let {
|
||||||
|
description += "${it.text()}"
|
||||||
|
}
|
||||||
|
info.getInfo("ANO")?.let { description += "$it" }
|
||||||
|
info.getInfo("TEMPORADAS")?.let { description += "$it" }
|
||||||
|
info.getInfo("DURAÇÃO")?.let { description += "$it" }
|
||||||
|
anime.description = description
|
||||||
|
return anime
|
||||||
|
}
|
||||||
|
|
||||||
|
// =============================== Latest ===============================
|
||||||
|
override fun latestUpdatesNextPageSelector(): String = "div.resppages > a > span.icon-chevron-right"
|
||||||
|
|
||||||
|
override fun latestUpdatesSelector(): String = "div.content article > div.poster"
|
||||||
|
|
||||||
|
override fun latestUpdatesFromElement(element: Element) = popularAnimeFromElement(element)
|
||||||
|
|
||||||
|
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/episodios/page/$page", headers)
|
||||||
|
|
||||||
|
// ============================= Utilities ==============================
|
||||||
|
private val animeMenuSelector = "div.pag_episodes div.item a[href] i.icon-bars"
|
||||||
|
|
||||||
|
private fun getRealDoc(document: Document): Document {
|
||||||
|
val menu = document.selectFirst(animeMenuSelector)
|
||||||
|
if (menu != null) {
|
||||||
|
val originalUrl = menu.parent().attr("href")
|
||||||
|
val req = client.newCall(GET(originalUrl, headers)).execute()
|
||||||
|
return req.asJsoup()
|
||||||
|
} else {
|
||||||
|
return document
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun parseStatus(status: String?): Int {
|
||||||
|
return when (status) {
|
||||||
|
null -> SAnime.COMPLETED
|
||||||
|
else -> SAnime.ONGOING
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Element.getInfo(substring: String): String? {
|
||||||
|
val target = this.selectFirst("div.custom_fields:contains($substring)")
|
||||||
|
?: return null
|
||||||
|
val key = target.selectFirst("b").text()
|
||||||
|
val value = target.selectFirst("span").text()
|
||||||
|
return "\n$key $value"
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun String.getParam(param: String): String? {
|
||||||
|
return Uri.parse(this).getQueryParameter(param)
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val PREFIX_SEARCH = "slug:"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.animesup
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilter
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
||||||
|
|
||||||
|
object AnimesUpFilters {
|
||||||
|
|
||||||
|
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.filterIsInstance<R>().joinToString("") {
|
||||||
|
(it as QueryPartFilter).toQueryPart()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GenreFilter : QueryPartFilter("Gênero", AnimesUpFiltersData.genres)
|
||||||
|
|
||||||
|
val filterList = AnimeFilterList(
|
||||||
|
AnimeFilter.Header(AnimesUpFiltersData.IGNORE_SEARCH_MSG),
|
||||||
|
GenreFilter()
|
||||||
|
)
|
||||||
|
|
||||||
|
data class FilterSearchParams(
|
||||||
|
val genre: String = ""
|
||||||
|
)
|
||||||
|
|
||||||
|
internal fun getSearchParameters(filters: AnimeFilterList): FilterSearchParams {
|
||||||
|
return FilterSearchParams(filters.asQueryPart<GenreFilter>())
|
||||||
|
}
|
||||||
|
|
||||||
|
private object AnimesUpFiltersData {
|
||||||
|
|
||||||
|
const val IGNORE_SEARCH_MSG = "NOTA: O filtro por gênero será IGNORADO ao usar a pesquisa por nome."
|
||||||
|
|
||||||
|
val genres = arrayOf(
|
||||||
|
Pair("Ação", "acao"),
|
||||||
|
Pair("Alienígena", "alienigena"),
|
||||||
|
Pair("Aventura", "aventura"),
|
||||||
|
Pair("Artes Marciais", "artes-marciais"),
|
||||||
|
Pair("Comédia", "comedia"),
|
||||||
|
Pair("Culinária", "culinaria"),
|
||||||
|
Pair("Drama", "drama"),
|
||||||
|
Pair("Ecchi", "ecchi"),
|
||||||
|
Pair("Escolar", "escolar"),
|
||||||
|
Pair("Esporte", "esporte"),
|
||||||
|
Pair("Fantasia", "fantasia"),
|
||||||
|
Pair("Ficção Científica", "sci-fi"),
|
||||||
|
Pair("Harém", "harem"),
|
||||||
|
Pair("Isekai", "isekai"),
|
||||||
|
Pair("Magia", "magia"),
|
||||||
|
Pair("Mecha", "mecha"),
|
||||||
|
Pair("Militar", "militar"),
|
||||||
|
Pair("Mistério", "misterio"),
|
||||||
|
Pair("Overpower", "overpower"),
|
||||||
|
Pair("Reencarnação", "reencarnacao"),
|
||||||
|
Pair("Romance", "romance"),
|
||||||
|
Pair("Seinen", "seinen"),
|
||||||
|
Pair("Shounen", "shounen"),
|
||||||
|
Pair("Shoujo", "shoujo"),
|
||||||
|
Pair("Slice Of Life", "slice-of-life"),
|
||||||
|
Pair("Sobrenatural", "sobrenatural"),
|
||||||
|
Pair("Superpoderes", "superpoderes"),
|
||||||
|
Pair("Vampiro", "vampiro"),
|
||||||
|
Pair("Yaoi", "yaoi"),
|
||||||
|
Pair("Yuri", "yuri")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.animesup
|
||||||
|
|
||||||
|
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://animesup.biz/animes/<slug> intents
|
||||||
|
* and redirects them to the main Aniyomi process.
|
||||||
|
*/
|
||||||
|
class AnimesUpUrlActivity : Activity() {
|
||||||
|
|
||||||
|
private val TAG = "AnimesUpUrlActivity"
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
val pathSegments = intent?.data?.pathSegments
|
||||||
|
if (pathSegments != null && pathSegments.size > 1) {
|
||||||
|
val slug = pathSegments[1]
|
||||||
|
val searchQuery = AnimesUp.PREFIX_SEARCH + slug
|
||||||
|
val mainIntent = Intent().apply {
|
||||||
|
action = "eu.kanade.tachiyomi.ANIMESEARCH"
|
||||||
|
putExtra("query", searchQuery)
|
||||||
|
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,19 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.animesup.extractors
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.Video
|
||||||
|
import eu.kanade.tachiyomi.network.GET
|
||||||
|
import okhttp3.Headers
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
|
||||||
|
class AnimesUpExtractor(private val client: OkHttpClient) {
|
||||||
|
|
||||||
|
fun videoFromUrl(url: String, quality: String, headers: Headers): Video {
|
||||||
|
val body = client.newCall(GET(url, headers))
|
||||||
|
.execute()
|
||||||
|
.body?.string()
|
||||||
|
.orEmpty()
|
||||||
|
val videoUrl = body.substringAfter("file: \"").substringBefore("\",")
|
||||||
|
val newHeaders = Headers.headersOf("referer", url)
|
||||||
|
return Video(url, quality, videoUrl, newHeaders)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package eu.kanade.tachiyomi.animeextension.pt.animesup.extractors
|
||||||
|
|
||||||
|
import dev.datlag.jsunpacker.JsUnpacker
|
||||||
|
import eu.kanade.tachiyomi.animesource.model.Video
|
||||||
|
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 org.jsoup.nodes.Document
|
||||||
|
|
||||||
|
class LegacyFunExtractor(private val client: OkHttpClient) {
|
||||||
|
private val USER_AGENT = "Mozilla/5.0 (Android 10; Mobile; rv:68.0) Gecko/68.0 Firefox/68.0"
|
||||||
|
|
||||||
|
fun videoFromUrl(url: String, quality: String): Video? {
|
||||||
|
var body: Document? = null
|
||||||
|
while (true) {
|
||||||
|
if (body == null) {
|
||||||
|
body = client.newCall(GET(url)).execute().asJsoup()
|
||||||
|
} else {
|
||||||
|
val form = body.selectFirst("form#link")
|
||||||
|
if (form == null) {
|
||||||
|
return getVideoFromDocument(body, quality)
|
||||||
|
} else {
|
||||||
|
val url = form.attr("action").let {
|
||||||
|
if (!it.startsWith("http"))
|
||||||
|
"https://legacyfun.site/$it"
|
||||||
|
else it
|
||||||
|
}
|
||||||
|
val token = form.selectFirst("input").attr("value")!!
|
||||||
|
val formBody = FormBody.Builder().apply {
|
||||||
|
add("token", token)
|
||||||
|
}.build()
|
||||||
|
body = client.newCall(POST(url, body = formBody))
|
||||||
|
.execute()
|
||||||
|
.asJsoup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getVideoFromDocument(doc: Document, quality: String): Video? {
|
||||||
|
val iframeUrl = doc.selectFirst("iframe#iframeidv").attr("src")
|
||||||
|
val newHeaders = Headers.headersOf(
|
||||||
|
"referer", doc.location(),
|
||||||
|
"user-agent", USER_AGENT
|
||||||
|
)
|
||||||
|
val newDoc = client.newCall(GET(iframeUrl, newHeaders)).execute().asJsoup()
|
||||||
|
val body = newDoc.selectFirst("script:containsData(eval)").data()
|
||||||
|
val unpacked = JsUnpacker.unpackAndCombine(body)
|
||||||
|
return unpacked?.let {
|
||||||
|
val url = it.substringAfter("file\":")
|
||||||
|
.substringAfter("\"")
|
||||||
|
.substringBefore("\"")
|
||||||
|
val videoHeaders = Headers.headersOf(
|
||||||
|
"referer", iframeUrl,
|
||||||
|
"user-agent", USER_AGENT
|
||||||
|
)
|
||||||
|
Video(url, quality, url, videoHeaders)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user