feat(pt/animesbr): New source pt/AnimesBr (close #514) #522
9 changed files with 263 additions and 0 deletions
15
src/pt/animesbr/build.gradle
Normal file
15
src/pt/animesbr/build.gradle
Normal file
|
@ -0,0 +1,15 @@
|
|||
ext {
|
||||
extName = 'AnimesBr'
|
||||
extClass = '.AnimesBr'
|
||||
themePkg = 'dooplay'
|
||||
baseUrl = 'https://animesbr.tv'
|
||||
overrideVersionCode = 1
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
||||
dependencies {
|
||||
implementation("dev.datlag.jsunpacker:jsunpacker:1.0.1")
|
||||
implementation(project(":lib:vidmoly-extractor"))
|
||||
}
|
BIN
src/pt/animesbr/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
src/pt/animesbr/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
BIN
src/pt/animesbr/res/mipmap-mdpi/ic_launcher.png
Normal file
BIN
src/pt/animesbr/res/mipmap-mdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
BIN
src/pt/animesbr/res/mipmap-xhdpi/ic_launcher.png
Normal file
BIN
src/pt/animesbr/res/mipmap-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.9 KiB |
BIN
src/pt/animesbr/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
src/pt/animesbr/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
BIN
src/pt/animesbr/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
BIN
src/pt/animesbr/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
|
@ -0,0 +1,174 @@
|
|||
package eu.kanade.tachiyomi.animeextension.pt.animesbr
|
||||
|
||||
import androidx.preference.ListPreference
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.animeextension.pt.animesbr.extractors.FourNimesExtractor
|
||||
import eu.kanade.tachiyomi.animeextension.pt.animesbr.extractors.RuplayExtractor
|
||||
import eu.kanade.tachiyomi.animesource.model.SAnime
|
||||
import eu.kanade.tachiyomi.animesource.model.Video
|
||||
import eu.kanade.tachiyomi.lib.vidmolyextractor.VidMolyExtractor
|
||||
import eu.kanade.tachiyomi.multisrc.dooplay.DooPlay
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import eu.kanade.tachiyomi.util.parallelCatchingFlatMapBlocking
|
||||
import okhttp3.FormBody
|
||||
import okhttp3.Response
|
||||
import org.jsoup.nodes.Document
|
||||
import org.jsoup.nodes.Element
|
||||
|
||||
class AnimesBr : DooPlay(
|
||||
"pt-BR",
|
||||
"Animes BR",
|
||||
"https://animesbr.tv",
|
||||
) {
|
||||
|
||||
// ============================== Popular ===============================
|
||||
override fun popularAnimeSelector() = "article.w_item_b > a"
|
||||
|
||||
override fun popularAnimeRequest(page: Int) = GET(baseUrl, headers)
|
||||
|
||||
// =============================== Latest ===============================
|
||||
override val latestUpdatesPath = "episodios"
|
||||
|
||||
override fun latestUpdatesNextPageSelector() = "div.pagination > a.arrow_pag > i.fa-caret-right"
|
||||
|
||||
// =============================== Search ===============================
|
||||
|
||||
// =========================== Anime Details ============================
|
||||
override val additionalInfoSelector = "div.wp-content"
|
||||
|
||||
override fun Document.getDescription(): String {
|
||||
return select("$additionalInfoSelector p")
|
||||
.first { !it.text().contains("Todos os Episódios") }
|
||||
?.let { it.text() + "\n" }
|
||||
?: ""
|
||||
}
|
||||
|
||||
override fun animeDetailsParse(document: Document): SAnime {
|
||||
val doc = getRealAnimeDoc(document)
|
||||
val sheader = doc.selectFirst("div.sheader")!!
|
||||
return SAnime.create().apply {
|
||||
setUrlWithoutDomain(doc.location())
|
||||
sheader.selectFirst("div.poster > img")!!.let {
|
||||
thumbnail_url = it.getImageUrl()
|
||||
title = it.attr("alt").ifEmpty {
|
||||
sheader.selectFirst("div.data > h1")!!.text()
|
||||
}.replace("Todos os Episódios", "").trim()
|
||||
}
|
||||
|
||||
genre = sheader.select("div.data div.sgeneros > a")
|
||||
.eachText()
|
||||
.joinToString()
|
||||
|
||||
doc.selectFirst("div#info")?.let { info ->
|
||||
description = buildString {
|
||||
append(doc.getDescription())
|
||||
additionalInfoItems.forEach {
|
||||
info.getInfo(it)?.let(::append)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============================ Video Links =============================
|
||||
override fun videoListParse(response: Response): List<Video> {
|
||||
val document = response.asJsoup()
|
||||
val players = document.select("ul#playeroptionsul li")
|
||||
return players.parallelCatchingFlatMapBlocking(::getPlayerVideos)
|
||||
}
|
||||
|
||||
override val prefQualityValues = arrayOf("360p", "720p")
|
||||
override val prefQualityEntries = prefQualityValues
|
||||
|
||||
private val fourNimesExtractor by lazy { FourNimesExtractor(client) }
|
||||
private val ruplayExtractor by lazy { RuplayExtractor(client) }
|
||||
private val vidMolyExtractor by lazy { VidMolyExtractor(client) }
|
||||
|
||||
private fun getPlayerVideos(player: Element): List<Video> {
|
||||
val name = player.selectFirst("span.title")!!.text()
|
||||
.run {
|
||||
if (this.lowercase().endsWith("dub")) {
|
||||
"Dublado"
|
||||
} else {
|
||||
"Legendado"
|
||||
}
|
||||
}
|
||||
|
||||
val url = getPlayerUrl(player) ?: return emptyList()
|
||||
|
||||
return when {
|
||||
"4nimes.com" in url -> fourNimesExtractor.videosFromUrl(url, "$name - ")
|
||||
"4youmovies" in url -> fourNimesExtractor.videosFromUrl(url, "$name - ")
|
||||
"vidmoly" in url -> vidMolyExtractor.videosFromUrl(url, "$name - ")
|
||||
"/embed/" in url -> ruplayExtractor.videosFromUrl(url, "$name - ")
|
||||
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getPlayerUrl(player: Element): String? {
|
||||
val body = FormBody.Builder()
|
||||
.add("action", "doo_player_ajax")
|
||||
.add("post", player.attr("data-post"))
|
||||
.add("nume", player.attr("data-nume"))
|
||||
.add("type", player.attr("data-type"))
|
||||
.build()
|
||||
|
||||
return client.newCall(POST("$baseUrl/wp-admin/admin-ajax.php", headers, body))
|
||||
.execute().body.string()
|
||||
.substringAfter("\"embed_url\":\"")
|
||||
.substringBefore("\",")
|
||||
.replace("\\", "")
|
||||
.takeIf(String::isNotBlank)
|
||||
}
|
||||
|
||||
// ============================== Filters ===============================
|
||||
override fun genresListRequest() = GET("$baseUrl/generos/", headers)
|
||||
override fun genresListSelector() = "div.wp-content a[href*=generos]"
|
||||
|
||||
// ============================== Settings ==============================
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
val videoLanguagePref = ListPreference(screen.context).apply {
|
||||
key = PREF_LANGUAGE_KEY
|
||||
title = PREF_LANGUAGE_TITLE
|
||||
entries = PREF_LANGUAGE_ENTRIES
|
||||
entryValues = PREF_LANGUAGE_VALUES
|
||||
setDefaultValue(PREF_LANGUAGE_DEFAULT)
|
||||
summary = "%s"
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val selected = newValue as String
|
||||
val index = findIndexOfValue(selected)
|
||||
val entry = entryValues[index] as String
|
||||
preferences.edit().putString(key, entry).commit()
|
||||
}
|
||||
}
|
||||
|
||||
screen.addPreference(videoLanguagePref)
|
||||
super.setupPreferenceScreen(screen)
|
||||
}
|
||||
|
||||
// ============================= Utilities ==============================
|
||||
override fun List<Video>.sort(): List<Video> {
|
||||
val quality = preferences.getString(videoSortPrefKey, videoSortPrefDefault)!!
|
||||
val language = preferences.getString(PREF_LANGUAGE_KEY, PREF_LANGUAGE_DEFAULT)!!
|
||||
return sortedWith(
|
||||
compareBy(
|
||||
{ it.quality.lowercase().contains(language.lowercase()) },
|
||||
{ it.quality.lowercase().contains(quality.lowercase()) },
|
||||
{ REGEX_QUALITY.find(it.quality)?.groupValues?.get(1)?.toIntOrNull() ?: 0 },
|
||||
),
|
||||
).reversed()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val REGEX_QUALITY by lazy { Regex("""(\d+)p""") }
|
||||
|
||||
private const val PREF_LANGUAGE_KEY = "preferred_language"
|
||||
private const val PREF_LANGUAGE_DEFAULT = "Legendado"
|
||||
private const val PREF_LANGUAGE_TITLE = "Língua preferida"
|
||||
private val PREF_LANGUAGE_VALUES = arrayOf("Legendado", "Dublado")
|
||||
private val PREF_LANGUAGE_ENTRIES = PREF_LANGUAGE_VALUES
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package eu.kanade.tachiyomi.animeextension.pt.animesbr.extractors
|
||||
|
||||
import dev.datlag.jsunpacker.JsUnpacker
|
||||
import eu.kanade.tachiyomi.animesource.model.Video
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import eu.kanade.tachiyomi.util.parseAs
|
||||
import kotlinx.serialization.Serializable
|
||||
import okhttp3.HttpUrl.Companion.toHttpUrl
|
||||
import okhttp3.OkHttpClient
|
||||
|
||||
class FourNimesExtractor(private val client: OkHttpClient) {
|
||||
fun videosFromUrl(url: String, prefix: String = ""): List<Video> {
|
||||
val doc = client.newCall(GET(url)).execute().asJsoup()
|
||||
|
||||
val script = doc.selectFirst("script:containsData(eval):containsData(p,a,c,k,e,d)")?.data()
|
||||
?.let(JsUnpacker::unpackAndCombine)
|
||||
?: return emptyList()
|
||||
|
||||
val kaken = script.substringAfter("kaken", "")
|
||||
.substringAfter('"')
|
||||
.substringBefore('"')
|
||||
.ifEmpty { null }
|
||||
?: return emptyList()
|
||||
|
||||
val now = System.currentTimeMillis()
|
||||
val apiUrl = "https://${url.toHttpUrl().host}/api?$kaken&_=$now"
|
||||
|
||||
return client.newCall(GET(apiUrl)).execute().parseAs<Response>().sources.map { source ->
|
||||
val videoUrl = source.file
|
||||
val quality = source.label
|
||||
|
||||
Video(videoUrl, "$prefix 4nimes - $quality ".trim(), videoUrl)
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class Source(
|
||||
val file: String,
|
||||
val label: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Response(
|
||||
val sources: List<Source>,
|
||||
)
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package eu.kanade.tachiyomi.animeextension.pt.animesbr.extractors
|
||||
|
||||
import eu.kanade.tachiyomi.animesource.model.Video
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import okhttp3.Headers
|
||||
import okhttp3.OkHttpClient
|
||||
|
||||
class RuplayExtractor(private val client: OkHttpClient) {
|
||||
fun videosFromUrl(url: String, prefix: String = ""): List<Video> {
|
||||
return client.newCall(GET(url)).execute()
|
||||
.body.string()
|
||||
.substringAfter("Playerjs({")
|
||||
.substringAfter("file:")
|
||||
.substringAfter("\"")
|
||||
.substringBefore("\"")
|
||||
.split(",")
|
||||
.map { file ->
|
||||
val videoUrl = file.substringAfter("]")
|
||||
val quality = file.substringAfter("[", "")
|
||||
.substringBefore("]")
|
||||
.ifEmpty { "Default" }
|
||||
|
||||
val headers = Headers.headersOf("Referer", videoUrl)
|
||||
Video(videoUrl, "$prefix Ruplay - $quality".trim(), videoUrl, headers = headers)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue