refactor(src/pt): Refactorate some extensions (#1713)
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
}
|
||||
|
||||
ext {
|
||||
extName = 'Anime Fire'
|
||||
@ -10,5 +12,4 @@ ext {
|
||||
libVersion = '13'
|
||||
}
|
||||
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
@ -1,9 +0,0 @@
|
||||
package eu.kanade.tachiyomi.animeextension.pt.animefire
|
||||
|
||||
object AFConstants {
|
||||
const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7"
|
||||
const val USER_AGENT = "Mozilla/5.0 (Linux; Android 10; SM-A307GT Build/QP1A.190711.020;) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/102.0.5005.125 Mobile Safari/537.36"
|
||||
const val PREFERRED_QUALITY = "preferred_quality"
|
||||
const val PREFIX_SEARCH = "id:"
|
||||
val QUALITY_LIST = arrayOf("360p", "720p")
|
||||
}
|
@ -16,7 +16,7 @@ object AFFilters {
|
||||
}
|
||||
|
||||
private inline fun <reified R> AnimeFilterList.asQueryPart(): String {
|
||||
return this.filterIsInstance<R>().joinToString("") {
|
||||
return first { it is R }.let {
|
||||
(it as QueryPartFilter).toQueryPart()
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class AFUrlActivity : Activity() {
|
||||
val pathSegments = intent?.data?.pathSegments
|
||||
if (pathSegments != null && pathSegments.size > 1) {
|
||||
val id = pathSegments[1]
|
||||
val searchQuery = AFConstants.PREFIX_SEARCH + id
|
||||
val searchQuery = AnimeFire.PREFIX_SEARCH + id
|
||||
val mainIntent = Intent().apply {
|
||||
action = "eu.kanade.tachiyomi.ANIMESEARCH"
|
||||
putExtra("query", searchQuery)
|
||||
|
@ -17,7 +17,6 @@ import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.util.asJsoup
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.Headers
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
@ -26,6 +25,7 @@ import org.jsoup.nodes.Element
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.lang.Exception
|
||||
|
||||
class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
@ -40,17 +40,15 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
override val client: OkHttpClient = network.cloudflareClient
|
||||
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
|
||||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||
override fun headersBuilder() = super.headersBuilder()
|
||||
.add("Referer", baseUrl)
|
||||
.add("Accept-Language", AFConstants.ACCEPT_LANGUAGE)
|
||||
.add("Accept-Language", ACCEPT_LANGUAGE)
|
||||
|
||||
// ============================== Popular ===============================
|
||||
override fun popularAnimeSelector() = latestUpdatesSelector()
|
||||
@ -62,25 +60,21 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
override fun episodeListSelector(): String = "div.div_video_list > a"
|
||||
override fun episodeListParse(response: Response) = super.episodeListParse(response).reversed()
|
||||
|
||||
override fun episodeFromElement(element: Element): SEpisode {
|
||||
val episode = SEpisode.create()
|
||||
override fun episodeFromElement(element: Element) = SEpisode.create().apply {
|
||||
val url = element.attr("href")
|
||||
episode.setUrlWithoutDomain(url)
|
||||
episode.name = element.text()
|
||||
episode.episode_number = try {
|
||||
url.substringAfterLast("/").toFloat()
|
||||
} catch (e: NumberFormatException) { 0F }
|
||||
return episode
|
||||
setUrlWithoutDomain(url)
|
||||
name = element.text()
|
||||
episode_number = url.substringAfterLast("/").toFloatOrNull() ?: 0F
|
||||
}
|
||||
|
||||
// ============================ Video Links =============================
|
||||
override fun videoListParse(response: Response): List<Video> {
|
||||
val document: Document = response.asJsoup()
|
||||
val document = response.asJsoup()
|
||||
val videoElement = document.selectFirst("video#my-video")
|
||||
return if (videoElement != null) {
|
||||
AnimeFireExtractor(client, json).videoListFromElement(videoElement)
|
||||
} else {
|
||||
IframeExtractor(client).videoListFromDocument(document)
|
||||
IframeExtractor(client).videoListFromDocument(document, headers)
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,36 +88,27 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
override fun searchAnimeNextPageSelector() = latestUpdatesNextPageSelector()
|
||||
|
||||
override fun fetchSearchAnime(page: Int, query: String, filters: AnimeFilterList): Observable<AnimesPage> {
|
||||
return if (query.startsWith(AFConstants.PREFIX_SEARCH)) {
|
||||
val id = query.removePrefix(AFConstants.PREFIX_SEARCH)
|
||||
return if (query.startsWith(PREFIX_SEARCH)) {
|
||||
val id = query.removePrefix(PREFIX_SEARCH)
|
||||
client.newCall(GET("$baseUrl/animes/$id"))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeByIdParse(response, id)
|
||||
}
|
||||
.map(::searchAnimeByIdParse)
|
||||
} else {
|
||||
val params = AFFilters.getSearchParameters(filters)
|
||||
client.newCall(searchAnimeRequest(page, query, params))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeParse(response)
|
||||
}
|
||||
super.fetchSearchAnime(page, query, filters)
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchAnimeByIdParse(response: Response, id: String): AnimesPage {
|
||||
private fun searchAnimeByIdParse(response: Response): AnimesPage {
|
||||
val details = animeDetailsParse(response)
|
||||
details.url = "/animes/$id"
|
||||
return AnimesPage(listOf(details), false)
|
||||
}
|
||||
|
||||
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request = throw Exception("not used")
|
||||
|
||||
private fun searchAnimeRequest(page: Int, query: String, filters: AFFilters.FilterSearchParams): Request {
|
||||
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
|
||||
val params = AFFilters.getSearchParameters(filters)
|
||||
if (query.isBlank()) {
|
||||
return when {
|
||||
filters.season.isNotBlank() -> GET("$baseUrl/temporada/${filters.season}/$page")
|
||||
else -> GET("$baseUrl/genero/${filters.genre}/$page")
|
||||
params.season.isNotBlank() -> GET("$baseUrl/temporada/${params.season}/$page")
|
||||
else -> GET("$baseUrl/genero/${params.genre}/$page")
|
||||
}
|
||||
}
|
||||
val fixedQuery = query.trim().replace(" ", "-").lowercase()
|
||||
@ -131,58 +116,58 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
}
|
||||
|
||||
// =========================== Anime Details ============================
|
||||
override fun animeDetailsParse(document: Document): SAnime {
|
||||
val anime = SAnime.create()
|
||||
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
|
||||
val content = document.selectFirst("div.divDivAnimeInfo")!!
|
||||
val names = content.selectFirst("div.div_anime_names")!!
|
||||
val infos = content.selectFirst("div.divAnimePageInfo")!!
|
||||
anime.thumbnail_url = content.selectFirst("div.sub_animepage_img > img")!!
|
||||
setUrlWithoutDomain(document.location())
|
||||
thumbnail_url = content.selectFirst("div.sub_animepage_img > img")!!
|
||||
.attr("data-src")
|
||||
anime.title = names.selectFirst("h1")!!.text()
|
||||
anime.genre = infos.select("a.spanGeneros").joinToString(", ") { it.text() }
|
||||
anime.author = infos.getInfo("Estúdios")
|
||||
anime.status = parseStatus(infos.getInfo("Status"))
|
||||
title = names.selectFirst("h1")!!.text()
|
||||
genre = infos.select("a.spanGeneros").eachText().joinToString()
|
||||
author = infos.getInfo("Estúdios")
|
||||
status = parseStatus(infos.getInfo("Status"))
|
||||
|
||||
var desc = content.selectFirst("div.divSinopse > span")!!.text() + "\n"
|
||||
names.selectFirst("h6")?.let { desc += "\nNome alternativo: ${it.text()}" }
|
||||
infos.getInfo("Dia de")?.let { desc += "\nDia de lançamento: $it" }
|
||||
infos.getInfo("Áudio")?.let { desc += "\nTipo: $it" }
|
||||
infos.getInfo("Ano")?.let { desc += "\nAno: $it" }
|
||||
infos.getInfo("Episódios")?.let { desc += "\nEpisódios: $it" }
|
||||
infos.getInfo("Temporada")?.let { desc += "\nTemporada: $it" }
|
||||
anime.description = desc
|
||||
|
||||
return anime
|
||||
description = buildString {
|
||||
append(content.selectFirst("div.divSinopse > span")!!.text() + "\n")
|
||||
names.selectFirst("h6")?.let { append("\nNome alternativo: ${it.text()}") }
|
||||
infos.getInfo("Dia de")?.let { append("\nDia de lançamento: $it") }
|
||||
infos.getInfo("Áudio")?.let { append("\nTipo: $it") }
|
||||
infos.getInfo("Ano")?.let { append("\nAno: $it") }
|
||||
infos.getInfo("Episódios")?.let { append("\nEpisódios: $it") }
|
||||
infos.getInfo("Temporada")?.let { append("\nTemporada: $it") }
|
||||
}
|
||||
}
|
||||
|
||||
// =============================== Latest ===============================
|
||||
override fun latestUpdatesNextPageSelector(): String = "ul.pagination img.seta-right"
|
||||
override fun latestUpdatesSelector(): String = "article.cardUltimosEps > a"
|
||||
|
||||
override fun latestUpdatesFromElement(element: Element): SAnime {
|
||||
val anime = SAnime.create()
|
||||
override fun latestUpdatesFromElement(element: Element) = SAnime.create().apply {
|
||||
val url = element.attr("href")
|
||||
// get anime url from episode url
|
||||
when (url.substringAfterLast("/").toIntOrNull()) {
|
||||
null -> setUrlWithoutDomain(url)
|
||||
else -> {
|
||||
val substr = url.substringBeforeLast("/")
|
||||
setUrlWithoutDomain("$substr-todos-os-episodios")
|
||||
}
|
||||
}
|
||||
|
||||
if (url.substringAfterLast("/").toIntOrNull() != null) {
|
||||
val newUrl = url.substringBeforeLast("/") + "-todos-os-episodios"
|
||||
anime.setUrlWithoutDomain(newUrl)
|
||||
} else { anime.setUrlWithoutDomain(url) }
|
||||
|
||||
anime.title = element.selectFirst("h3.animeTitle")!!.text()
|
||||
anime.thumbnail_url = element.selectFirst("img")!!.attr("data-src")
|
||||
return anime
|
||||
title = element.selectFirst("h3.animeTitle")!!.text()
|
||||
thumbnail_url = element.selectFirst("img")!!.attr("data-src")
|
||||
}
|
||||
|
||||
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/home/$page")
|
||||
override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/home/$page")
|
||||
|
||||
// ============================== Settings ==============================
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
val videoQualityPref = ListPreference(screen.context).apply {
|
||||
key = AFConstants.PREFERRED_QUALITY
|
||||
title = "Qualidade preferida"
|
||||
entries = AFConstants.QUALITY_LIST
|
||||
entryValues = AFConstants.QUALITY_LIST
|
||||
setDefaultValue(AFConstants.QUALITY_LIST.last())
|
||||
ListPreference(screen.context).apply {
|
||||
key = PREF_QUALITY_KEY
|
||||
title = PREF_QUALITY_TITLE
|
||||
entries = PREF_QUALITY_VALUES
|
||||
entryValues = PREF_QUALITY_VALUES
|
||||
setDefaultValue(PREF_QUALITY_DEFAULT)
|
||||
summary = "%s"
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val selected = newValue as String
|
||||
@ -190,9 +175,7 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
val entry = entryValues[index] as String
|
||||
preferences.edit().putString(key, entry).commit()
|
||||
}
|
||||
}
|
||||
|
||||
screen.addPreference(videoQualityPref)
|
||||
}.also(screen::addPreference)
|
||||
}
|
||||
|
||||
override fun getFilterList(): AnimeFilterList = AFFilters.FILTER_LIST
|
||||
@ -208,27 +191,23 @@ class AnimeFire : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
}
|
||||
|
||||
private fun Element.getInfo(key: String): String? {
|
||||
val div = this.selectFirst("div.animeInfo:contains($key)")
|
||||
if (div == null) return div
|
||||
val span = div.selectFirst("span")
|
||||
return span?.text()
|
||||
return selectFirst("div.animeInfo:contains($key) span")?.text()
|
||||
}
|
||||
|
||||
override fun List<Video>.sort(): List<Video> {
|
||||
val quality = preferences.getString(AFConstants.PREFERRED_QUALITY, null)
|
||||
if (quality != null) {
|
||||
val newList = mutableListOf<Video>()
|
||||
var preferred = 0
|
||||
for (video in this) {
|
||||
if (video.quality == quality) {
|
||||
newList.add(preferred, video)
|
||||
preferred++
|
||||
} else {
|
||||
newList.add(video)
|
||||
}
|
||||
}
|
||||
return newList
|
||||
}
|
||||
return this
|
||||
val quality = preferences.getString(PREF_QUALITY_KEY, PREF_QUALITY_DEFAULT)!!
|
||||
return sortedWith(
|
||||
compareBy { it.quality.contains(quality) },
|
||||
).reversed()
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val PREFIX_SEARCH = "id:"
|
||||
private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7"
|
||||
|
||||
private const val PREF_QUALITY_KEY = "preferred_quality"
|
||||
private const val PREF_QUALITY_TITLE = "Qualidade preferida"
|
||||
private const val PREF_QUALITY_DEFAULT = "720p"
|
||||
private val PREF_QUALITY_VALUES = arrayOf("360p", "720p")
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package eu.kanade.tachiyomi.animeextension.pt.animefire.extractors
|
||||
|
||||
import eu.kanade.tachiyomi.animeextension.pt.animefire.AFConstants
|
||||
import eu.kanade.tachiyomi.animesource.model.Video
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import okhttp3.Headers
|
||||
@ -8,10 +7,7 @@ import okhttp3.OkHttpClient
|
||||
import org.jsoup.nodes.Document
|
||||
|
||||
class IframeExtractor(private val client: OkHttpClient) {
|
||||
|
||||
private val headers = Headers.headersOf("User-Agent", AFConstants.USER_AGENT)
|
||||
|
||||
fun videoListFromDocument(doc: Document): List<Video> {
|
||||
fun videoListFromDocument(doc: Document, headers: Headers): List<Video> {
|
||||
val iframeElement = doc.selectFirst("div#div_video iframe")!!
|
||||
val iframeUrl = iframeElement.attr("src")
|
||||
val response = client.newCall(GET(iframeUrl, headers)).execute()
|
||||
|
@ -29,12 +29,10 @@ class AnimesAria : ParsedAnimeHttpSource() {
|
||||
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 popularAnimeFromElement(element: Element) = SAnime.create().apply {
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
title = element.attr("title")
|
||||
thumbnail_url = element.selectFirst("img")!!.attr("src")
|
||||
}
|
||||
|
||||
override fun popularAnimeNextPageSelector() = latestUpdatesNextPageSelector()
|
||||
@ -46,46 +44,43 @@ class AnimesAria : ParsedAnimeHttpSource() {
|
||||
// ============================== 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 episodeFromElement(element: Element) = SEpisode.create().apply {
|
||||
element.parent()!!.selectFirst("a > b")!!.ownText().let {
|
||||
name = it
|
||||
episode_number = it.substringAfter(" ").toFloatOrNull() ?: 0F
|
||||
}
|
||||
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()
|
||||
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
|
||||
setUrlWithoutDomain(document.location())
|
||||
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)
|
||||
description = buildString {
|
||||
document.selectFirst("li.active > small")!!
|
||||
.ownText()
|
||||
.substringAfter(": ")
|
||||
.let(::append)
|
||||
|
||||
append("\n\n")
|
||||
append("\n\n")
|
||||
|
||||
row.selectFirst("h1 > small")?.text()?.let {
|
||||
append("Títulos Alternativos: $it\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")
|
||||
}
|
||||
// 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")
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -154,28 +149,23 @@ class AnimesAria : ParsedAnimeHttpSource() {
|
||||
val id = query.removePrefix(PREFIX_SEARCH)
|
||||
client.newCall(GET("$baseUrl/anime/$id"))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeByIdParse(response, id)
|
||||
}
|
||||
.map(::searchAnimeByIdParse)
|
||||
} else {
|
||||
super.fetchSearchAnime(page, query, filters)
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchAnimeByIdParse(response: Response, id: String): AnimesPage {
|
||||
private fun searchAnimeByIdParse(response: Response): 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 latestUpdatesFromElement(element: Element) = 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)"
|
||||
|
@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
}
|
||||
|
||||
ext {
|
||||
extName = 'AnimesTC'
|
||||
|
@ -21,11 +21,11 @@ object ATCFilters {
|
||||
private class TriStateVal(name: String) : AnimeFilter.TriState(name)
|
||||
|
||||
private inline fun <reified R> AnimeFilterList.getFirst(): R {
|
||||
return this.filterIsInstance<R>().first()
|
||||
return first { it is R } as R
|
||||
}
|
||||
|
||||
private inline fun <reified R> AnimeFilterList.asQueryPart(): String {
|
||||
return this.getFirst<R>().let {
|
||||
return getFirst<R>().let {
|
||||
(it as QueryPartFilter).toQueryPart()
|
||||
}
|
||||
}
|
||||
@ -41,7 +41,7 @@ object ATCFilters {
|
||||
|
||||
class GenresFilter : TriStateFilterList(
|
||||
"Gêneros",
|
||||
ATCFiltersData.GENRES.map { TriStateVal(it) },
|
||||
ATCFiltersData.GENRES.map(::TriStateVal),
|
||||
)
|
||||
|
||||
val FILTER_LIST get() = AnimeFilterList(
|
||||
@ -88,38 +88,33 @@ object ATCFilters {
|
||||
return searchParams
|
||||
}
|
||||
|
||||
private fun compareLower(first: String, second: String): Boolean {
|
||||
return first.lowercase() in second.lowercase()
|
||||
}
|
||||
|
||||
private fun mustRemove(anime: AnimeDto, params: FilterSearchParams): Boolean {
|
||||
return when {
|
||||
params.animeName != "" && !compareLower(params.animeName, anime.title) -> true
|
||||
params.animeName != "" && !anime.title.contains(params.animeName, true) -> true
|
||||
params.initialLetter != "" && !anime.title.lowercase().startsWith(params.initialLetter) -> true
|
||||
params.blackListedGenres.size > 0 && params.blackListedGenres.any {
|
||||
compareLower(it, anime.genres)
|
||||
anime.genres.contains(it, true)
|
||||
} -> true
|
||||
params.includedGenres.size > 0 && params.includedGenres.any {
|
||||
!compareLower(it, anime.genres)
|
||||
!anime.genres.contains(it, true)
|
||||
} -> true
|
||||
params.status != "" && anime.status != SAnime.UNKNOWN && anime.status != params.status.toInt() -> true
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <T, R : Comparable<R>> List<out T>.sortedByIf(
|
||||
condition: Boolean,
|
||||
crossinline selector: (T) -> R?,
|
||||
private inline fun <T, R : Comparable<R>> List<T>.sortedByIf(
|
||||
isAscending: Boolean,
|
||||
crossinline selector: (T) -> R,
|
||||
): List<T> {
|
||||
return if (condition) {
|
||||
sortedBy(selector)
|
||||
} else {
|
||||
sortedByDescending(selector)
|
||||
return when {
|
||||
isAscending -> sortedBy(selector)
|
||||
else -> sortedByDescending(selector)
|
||||
}
|
||||
}
|
||||
|
||||
fun List<AnimeDto>.applyFilterParams(params: FilterSearchParams): List<AnimeDto> {
|
||||
return this.filterNot { mustRemove(it, params) }.let { results ->
|
||||
return filterNot { mustRemove(it, params) }.let { results ->
|
||||
when (params.sortBy) {
|
||||
"A-Z" -> results.sortedByIf(params.orderAscending) { it.title.lowercase() }
|
||||
"year" -> results.sortedByIf(params.orderAscending) { it.year ?: 0 }
|
||||
|
@ -27,12 +27,12 @@ import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.serialization.json.Json
|
||||
import okhttp3.CacheControl
|
||||
import okhttp3.Headers
|
||||
import okhttp3.Request
|
||||
import okhttp3.Response
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.TimeUnit.DAYS
|
||||
@ -47,16 +47,14 @@ class AnimesTC : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
|
||||
override val supportsLatest = true
|
||||
|
||||
override fun headersBuilder() = Headers.Builder()
|
||||
override fun headersBuilder() = super.headersBuilder()
|
||||
.add("Referer", "https://www.animestc.net/")
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
// ============================== Popular ===============================
|
||||
// This source doesnt have a popular animes page,
|
||||
@ -77,14 +75,7 @@ class AnimesTC : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
private fun getEpisodeList(animeId: Int, page: Int = 1): List<SEpisode> {
|
||||
val response = client.newCall(episodeListRequest(animeId, page)).execute()
|
||||
val parsed = response.parseAs<ResponseDto<EpisodeDto>>()
|
||||
val episodes = parsed.items.map {
|
||||
SEpisode.create().apply {
|
||||
name = it.title
|
||||
setUrlWithoutDomain("/episodes?slug=${it.slug}")
|
||||
episode_number = it.number.toFloat()
|
||||
date_upload = it.created_at.toDate()
|
||||
}
|
||||
}
|
||||
val episodes = parsed.items.map(::episodeFromObject)
|
||||
|
||||
if (parsed.page < parsed.lastPage) {
|
||||
return episodes + getEpisodeList(animeId, page + 1)
|
||||
@ -93,6 +84,13 @@ class AnimesTC : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun episodeFromObject(episode: EpisodeDto) = SEpisode.create().apply {
|
||||
name = episode.title
|
||||
setUrlWithoutDomain("/episodes?slug=${episode.slug}")
|
||||
episode_number = episode.number.toFloat()
|
||||
date_upload = episode.created_at.toDate()
|
||||
}
|
||||
|
||||
// ============================ Video Links =============================
|
||||
|
||||
override fun videoListParse(response: Response): List<Video> {
|
||||
@ -125,15 +123,13 @@ class AnimesTC : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
}
|
||||
|
||||
// =========================== Anime Details ============================
|
||||
override fun animeDetailsParse(response: Response): SAnime {
|
||||
override fun animeDetailsParse(response: Response) = SAnime.create().apply {
|
||||
val anime = response.getAnimeDto()
|
||||
return SAnime.create().apply {
|
||||
setUrlWithoutDomain("/series/${anime.id}")
|
||||
title = anime.title
|
||||
status = anime.status
|
||||
genre = anime.genres
|
||||
description = anime.synopsis
|
||||
}
|
||||
setUrlWithoutDomain("/series/${anime.id}")
|
||||
title = anime.title
|
||||
status = anime.status
|
||||
genre = anime.genres
|
||||
description = anime.synopsis
|
||||
}
|
||||
|
||||
// =============================== Search ===============================
|
||||
@ -150,12 +146,9 @@ class AnimesTC : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
val slug = query.removePrefix(PREFIX_SEARCH)
|
||||
client.newCall(GET("$baseUrl/series?slug=$slug"))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeBySlugParse(response)
|
||||
}
|
||||
.map(::searchAnimeBySlugParse)
|
||||
} else {
|
||||
val params = ATCFilters.getSearchParameters(filters)
|
||||
return Observable.just(searchAnime(page, query, params))
|
||||
return Observable.just(searchAnime(page, query, filters))
|
||||
}
|
||||
}
|
||||
|
||||
@ -170,9 +163,11 @@ class AnimesTC : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
|
||||
override fun getFilterList(): AnimeFilterList = ATCFilters.FILTER_LIST
|
||||
|
||||
private fun searchAnime(page: Int, query: String, filterParams: ATCFilters.FilterSearchParams): AnimesPage {
|
||||
filterParams.animeName = query
|
||||
val filtered = allAnimesList.applyFilterParams(filterParams)
|
||||
private fun searchAnime(page: Int, query: String, filters: AnimeFilterList): AnimesPage {
|
||||
val params = ATCFilters.getSearchParameters(filters).apply {
|
||||
animeName = query
|
||||
}
|
||||
val filtered = allAnimesList.applyFilterParams(params)
|
||||
val results = filtered.chunked(30)
|
||||
val hasNextPage = results.size > page
|
||||
val currentPage = if (results.size == 0) {
|
||||
@ -267,12 +262,12 @@ class AnimesTC : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
|
||||
private fun String.toDate(): Long {
|
||||
return runCatching {
|
||||
DATE_FORMATTER.parse(this)?.time ?: 0L
|
||||
DATE_FORMATTER.parse(this)?.time
|
||||
}.getOrNull() ?: 0L
|
||||
}
|
||||
|
||||
private inline fun <reified T> Response.parseAs(preloaded: String? = null): T {
|
||||
val responseBody = preloaded ?: body.string()
|
||||
val responseBody = preloaded ?: use { it.body.string() }
|
||||
return json.decodeFromString(responseBody)
|
||||
}
|
||||
|
||||
|
@ -46,16 +46,14 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
.add("Accept-Language", ACCEPT_LANGUAGE)
|
||||
|
||||
// ============================== Popular ===============================
|
||||
override fun popularAnimeSelector(): String = "div.lista_de_animes div.ani_loop_item_img > a"
|
||||
override fun popularAnimeRequest(page: Int): Request = GET("$baseUrl/anime/page/$page")
|
||||
override fun popularAnimeSelector() = "div.lista_de_animes div.ani_loop_item_img > a"
|
||||
override fun popularAnimeRequest(page: Int) = GET("$baseUrl/anime/page/$page")
|
||||
|
||||
override fun popularAnimeFromElement(element: Element): SAnime {
|
||||
return SAnime.create().apply {
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
val img = element.selectFirst("img")!!
|
||||
title = img.attr("title")
|
||||
thumbnail_url = img.attr("src")
|
||||
}
|
||||
override fun popularAnimeFromElement(element: Element) = SAnime.create().apply {
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
val img = element.selectFirst("img")!!
|
||||
title = img.attr("title")
|
||||
thumbnail_url = img.attr("src")
|
||||
}
|
||||
|
||||
override fun popularAnimeNextPageSelector(): String = "a.page-numbers:contains(Próximo)"
|
||||
@ -70,45 +68,36 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
}
|
||||
|
||||
// ============================== Episodes ==============================
|
||||
override fun episodeListSelector(): String = "div.animepag_episodios_container > div.animepag_episodios_item > a"
|
||||
|
||||
private fun getAllEps(response: Response): List<SEpisode> {
|
||||
val doc = response.asJsoup().let {
|
||||
if (response.request.url.toString().contains("/video/")) {
|
||||
getRealDoc(it)
|
||||
} else { it }
|
||||
}
|
||||
|
||||
val epElementList = doc.select(episodeListSelector())
|
||||
val epList = mutableListOf<SEpisode>()
|
||||
epList.addAll(epElementList.map(::episodeFromElement))
|
||||
if (hasNextPage(doc)) {
|
||||
val next = doc.selectFirst(popularAnimeNextPageSelector())!!.attr("href")
|
||||
val request = GET(baseUrl + next)
|
||||
val newResponse = client.newCall(request).execute()
|
||||
epList.addAll(getAllEps(newResponse))
|
||||
}
|
||||
return epList
|
||||
}
|
||||
override fun episodeListSelector() = "div.animepag_episodios_container > div.animepag_episodios_item > a"
|
||||
|
||||
override fun episodeListParse(response: Response): List<SEpisode> {
|
||||
return getAllEps(response).reversed()
|
||||
var doc = getRealDoc(response.asJsoup())
|
||||
var first = true
|
||||
val epList = buildList {
|
||||
do {
|
||||
if (!first) {
|
||||
val path = doc.selectFirst(popularAnimeNextPageSelector())!!.attr("href")
|
||||
doc = client.newCall(GET(baseUrl + path)).execute().asJsoup()
|
||||
}
|
||||
first = false
|
||||
doc.select(episodeListSelector())
|
||||
.map(::episodeFromElement)
|
||||
.let(::addAll)
|
||||
} while (hasNextPage(doc))
|
||||
}
|
||||
return epList.reversed()
|
||||
}
|
||||
|
||||
override fun episodeFromElement(element: Element): SEpisode {
|
||||
return SEpisode.create().apply {
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
episode_number = runCatching {
|
||||
element.selectFirst("div.animepag_episodios_item_views")!!
|
||||
.text()
|
||||
.substringAfter(" ")
|
||||
.toFloat()
|
||||
}.getOrDefault(0F)
|
||||
name = element.selectFirst("div.animepag_episodios_item_nome")!!.text()
|
||||
date_upload = element.selectFirst("div.animepag_episodios_item_date")!!
|
||||
.text()
|
||||
.toDate()
|
||||
}
|
||||
override fun episodeFromElement(element: Element) = SEpisode.create().apply {
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
episode_number = element.selectFirst("div.animepag_episodios_item_views")!!
|
||||
.text()
|
||||
.substringAfter(" ")
|
||||
.toFloatOrNull() ?: 0F
|
||||
name = element.selectFirst("div.animepag_episodios_item_nome")!!.text()
|
||||
date_upload = element.selectFirst("div.animepag_episodios_item_date")!!
|
||||
.text()
|
||||
.toDate()
|
||||
}
|
||||
|
||||
// ============================ Video Links =============================
|
||||
@ -120,10 +109,8 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
// =============================== Search ===============================
|
||||
override fun searchAnimeFromElement(element: Element) = throw Exception("not used")
|
||||
override fun searchAnimeNextPageSelector() = throw Exception("not used")
|
||||
|
||||
override fun searchAnimeSelector() = throw Exception("not used")
|
||||
|
||||
override fun searchAnimeParse(response: Response): AnimesPage = popularAnimeParse(response)
|
||||
override fun searchAnimeParse(response: Response) = popularAnimeParse(response)
|
||||
|
||||
override fun getFilterList(): AnimeFilterList = AnitubeFilters.FILTER_LIST
|
||||
|
||||
@ -145,46 +132,42 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
}
|
||||
|
||||
// =========================== Anime Details ============================
|
||||
override fun animeDetailsParse(document: Document): SAnime {
|
||||
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
|
||||
val doc = getRealDoc(document)
|
||||
return SAnime.create().apply {
|
||||
setUrlWithoutDomain(doc.location())
|
||||
val content = doc.selectFirst("div.anime_container_content")!!
|
||||
val infos = content.selectFirst("div.anime_infos")!!
|
||||
setUrlWithoutDomain(doc.location())
|
||||
val content = doc.selectFirst("div.anime_container_content")!!
|
||||
val infos = content.selectFirst("div.anime_infos")!!
|
||||
|
||||
title = doc.selectFirst("div.anime_container_titulo")!!.text()
|
||||
thumbnail_url = content.selectFirst("img")!!.attr("src")
|
||||
genre = infos.getInfo("Gêneros")
|
||||
author = infos.getInfo("Autor")
|
||||
artist = infos.getInfo("Estúdio")
|
||||
status = parseStatus(infos.getInfo("Status"))
|
||||
title = doc.selectFirst("div.anime_container_titulo")!!.text()
|
||||
thumbnail_url = content.selectFirst("img")!!.attr("src")
|
||||
genre = infos.getInfo("Gêneros")
|
||||
author = infos.getInfo("Autor")
|
||||
artist = infos.getInfo("Estúdio")
|
||||
status = parseStatus(infos.getInfo("Status"))
|
||||
|
||||
val infoItems = listOf("Ano", "Direção", "Episódios", "Temporada", "Título Alternativo")
|
||||
val infoItems = listOf("Ano", "Direção", "Episódios", "Temporada", "Título Alternativo")
|
||||
|
||||
description = buildString {
|
||||
append(doc.selectFirst("div.sinopse_container_content")!!.text() + "\n")
|
||||
infoItems.forEach { item ->
|
||||
infos.getInfo(item)?.let { append("\n$item: $it") }
|
||||
}
|
||||
description = buildString {
|
||||
append(doc.selectFirst("div.sinopse_container_content")!!.text() + "\n")
|
||||
infoItems.forEach { item ->
|
||||
infos.getInfo(item)?.let { append("\n$item: $it") }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =============================== Latest ===============================
|
||||
override fun latestUpdatesNextPageSelector(): String = popularAnimeNextPageSelector()
|
||||
override fun latestUpdatesNextPageSelector() = popularAnimeNextPageSelector()
|
||||
|
||||
override fun latestUpdatesSelector(): String = "div.mContainer_content.threeItensPerContent > div.epi_loop_item"
|
||||
override fun latestUpdatesSelector() = "div.mContainer_content.threeItensPerContent > div.epi_loop_item"
|
||||
|
||||
override fun latestUpdatesFromElement(element: Element): SAnime {
|
||||
return SAnime.create().apply {
|
||||
val img = element.selectFirst("img")!!
|
||||
setUrlWithoutDomain(element.selectFirst("a")!!.attr("href"))
|
||||
title = img.attr("title")
|
||||
thumbnail_url = img.attr("src")
|
||||
}
|
||||
override fun latestUpdatesFromElement(element: Element) = SAnime.create().apply {
|
||||
val img = element.selectFirst("img")!!
|
||||
setUrlWithoutDomain(element.selectFirst("a")!!.attr("href"))
|
||||
title = img.attr("title")
|
||||
thumbnail_url = img.attr("src")
|
||||
}
|
||||
|
||||
override fun latestUpdatesRequest(page: Int): Request = GET("$baseUrl/?page=$page")
|
||||
override fun latestUpdatesRequest(page: Int) = GET("$baseUrl/?page=$page")
|
||||
|
||||
override fun latestUpdatesParse(response: Response): AnimesPage {
|
||||
val document = response.asJsoup()
|
||||
@ -216,15 +199,11 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
// ============================= Utilities ==============================
|
||||
private fun getRealDoc(document: Document): Document {
|
||||
val menu = document.selectFirst("div.controles_ep > a[href] > i.spr.listaEP")
|
||||
if (menu != null) {
|
||||
val parent = menu.parent()!!
|
||||
val parentPath = parent.attr("href")
|
||||
val req = client.newCall(GET(baseUrl + parentPath)).execute()
|
||||
return req.asJsoup()
|
||||
} else {
|
||||
return document
|
||||
}
|
||||
return document.selectFirst("div.controles_ep > a[href]:has(i.spr.listaEP)")
|
||||
?.let {
|
||||
val path = it.attr("href")
|
||||
client.newCall(GET(baseUrl + path)).execute().asJsoup()
|
||||
} ?: document
|
||||
}
|
||||
|
||||
private fun parseStatus(statusString: String?): Int {
|
||||
@ -248,12 +227,12 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
return currentPage != lastPage
|
||||
}
|
||||
|
||||
private fun String.toPageNum(): Int = try {
|
||||
this.substringAfter("page/")
|
||||
private fun String.toPageNum(): Int =
|
||||
substringAfter("page/")
|
||||
.substringAfter("page=")
|
||||
.substringBefore("/")
|
||||
.substringBefore("&").toInt()
|
||||
} catch (e: NumberFormatException) { 1 }
|
||||
.substringBefore("&")
|
||||
.toIntOrNull() ?: 1
|
||||
|
||||
private fun Element.getInfo(key: String): String? {
|
||||
val parent = selectFirst("b:contains($key)")?.parent()
|
||||
@ -261,10 +240,9 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
val text = if (genres?.size == 0) {
|
||||
parent.ownText()
|
||||
} else {
|
||||
genres?.joinToString(", ") { it.text() }
|
||||
genres?.eachText()?.joinToString()
|
||||
}
|
||||
if (text == "") return null
|
||||
return text
|
||||
return text?.ifEmpty { null }
|
||||
}
|
||||
|
||||
override fun List<Video>.sort(): List<Video> {
|
||||
@ -276,7 +254,7 @@ class Anitube : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
private fun String.toDate(): Long {
|
||||
return runCatching {
|
||||
DATE_FORMATTER.parse(this)?.time ?: 0L
|
||||
DATE_FORMATTER.parse(this)?.time
|
||||
}.getOrNull() ?: 0L
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
}
|
||||
|
||||
ext {
|
||||
extName = 'Better Anime'
|
||||
|
@ -18,7 +18,7 @@ class BAUrlActivity : Activity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val pathSegments = intent?.data?.pathSegments
|
||||
if (pathSegments != null && pathSegments.size > 1) {
|
||||
if (pathSegments != null && pathSegments.size > 2) {
|
||||
val type = pathSegments[0]
|
||||
val lang = pathSegments[1]
|
||||
val item = pathSegments[2]
|
||||
|
@ -34,6 +34,7 @@ import org.jsoup.nodes.Element
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
|
||||
@ -51,9 +52,7 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
.addInterceptor(::loginInterceptor)
|
||||
.build()
|
||||
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
@ -66,14 +65,14 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
// ============================== Popular ===============================
|
||||
// The site doesn't have a true popular anime tab,
|
||||
// so we use the latest added anime page instead.
|
||||
override fun popularAnimeSelector() = latestUpdatesSelector()
|
||||
|
||||
override fun popularAnimeFromElement(element: Element) = latestUpdatesFromElement(element)
|
||||
override fun popularAnimeParse(response: Response) = latestUpdatesParse(response)
|
||||
|
||||
override fun popularAnimeRequest(page: Int): Request =
|
||||
GET("$baseUrl/ultimosAdicionados?page=$page")
|
||||
|
||||
override fun popularAnimeNextPageSelector() = latestUpdatesNextPageSelector()
|
||||
override fun popularAnimeSelector() = TODO()
|
||||
override fun popularAnimeFromElement(element: Element) = TODO()
|
||||
override fun popularAnimeNextPageSelector() = TODO()
|
||||
|
||||
// ============================== Episodes ==============================
|
||||
override fun episodeListSelector(): String = "ul#episodesList > li.list-group-item-action > a"
|
||||
@ -81,13 +80,11 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
override fun episodeListParse(response: Response) =
|
||||
super.episodeListParse(response).reversed()
|
||||
|
||||
override fun episodeFromElement(element: Element): SEpisode {
|
||||
return SEpisode.create().apply {
|
||||
val episodeName = element.text()
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
name = episodeName
|
||||
episode_number = episodeName.substringAfterLast(" ").toFloatOrNull() ?: 0F
|
||||
}
|
||||
override fun episodeFromElement(element: Element) = SEpisode.create().apply {
|
||||
val episodeName = element.text()
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
name = episodeName
|
||||
episode_number = episodeName.substringAfterLast(" ").toFloatOrNull() ?: 0F
|
||||
}
|
||||
|
||||
// ============================ Video Links =============================
|
||||
@ -123,17 +120,14 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
val path = query.removePrefix(PREFIX_SEARCH_PATH)
|
||||
client.newCall(GET("$baseUrl/$path"))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeByPathParse(response, path)
|
||||
}
|
||||
.map(::searchAnimeByPathParse)
|
||||
} else {
|
||||
super.fetchSearchAnime(page, query, filters)
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchAnimeByPathParse(response: Response, path: String): AnimesPage {
|
||||
private fun searchAnimeByPathParse(response: Response): AnimesPage {
|
||||
val details = animeDetailsParse(response)
|
||||
details.url = "/$path"
|
||||
return AnimesPage(listOf(details), false)
|
||||
}
|
||||
|
||||
@ -171,23 +165,23 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
}
|
||||
|
||||
// =========================== Anime Details ============================
|
||||
override fun animeDetailsParse(document: Document): SAnime {
|
||||
return SAnime.create().apply {
|
||||
val doc = getRealDoc(document)
|
||||
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
|
||||
val doc = getRealDoc(document)
|
||||
setUrlWithoutDomain(doc.location())
|
||||
|
||||
val infos = doc.selectFirst("div.infos_left > div.anime-info")!!
|
||||
val img = doc.selectFirst("div.infos-img > img")!!
|
||||
thumbnail_url = "https:" + img.attr("src")
|
||||
title = img.attr("alt")
|
||||
genre = infos.select("div.anime-genres > a")
|
||||
.eachText()
|
||||
.joinToString()
|
||||
author = infos.getInfo("Produtor")
|
||||
artist = infos.getInfo("Estúdio")
|
||||
status = parseStatus(infos.getInfo("Estado"))
|
||||
var desc = infos.selectFirst("div.anime-description")!!.text() + "\n\n"
|
||||
desc += infos.select(">p").eachText().joinToString("\n")
|
||||
description = desc
|
||||
val infos = doc.selectFirst("div.infos_left > div.anime-info")!!
|
||||
val img = doc.selectFirst("div.infos-img > img")!!
|
||||
thumbnail_url = "https:" + img.attr("src")
|
||||
title = img.attr("alt")
|
||||
genre = infos.select("div.anime-genres > a")
|
||||
.eachText()
|
||||
.joinToString()
|
||||
author = infos.getInfo("Produtor")
|
||||
artist = infos.getInfo("Estúdio")
|
||||
status = parseStatus(infos.getInfo("Estado"))
|
||||
description = buildString {
|
||||
append(infos.selectFirst("div.anime-description")!!.text() + "\n\n")
|
||||
infos.select(">p").eachText().forEach { append("$it\n") }
|
||||
}
|
||||
}
|
||||
|
||||
@ -198,14 +192,12 @@ class BetterAnime : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
override fun latestUpdatesRequest(page: Int): Request =
|
||||
GET("$baseUrl/ultimosLancamentos?page=$page")
|
||||
|
||||
override fun latestUpdatesFromElement(element: Element): SAnime {
|
||||
return SAnime.create().apply {
|
||||
val img = element.selectFirst("img")!!
|
||||
val url = element.selectFirst("a")?.attr("href")!!
|
||||
setUrlWithoutDomain(url)
|
||||
title = element.selectFirst("h3")?.text()!!
|
||||
thumbnail_url = "https:" + img.attr("src")
|
||||
}
|
||||
override fun latestUpdatesFromElement(element: Element) = SAnime.create().apply {
|
||||
val img = element.selectFirst("img")!!
|
||||
val url = element.selectFirst("a")?.attr("href")!!
|
||||
setUrlWithoutDomain(url)
|
||||
title = element.selectFirst("h3")?.text()!!
|
||||
thumbnail_url = "https:" + img.attr("src")
|
||||
}
|
||||
|
||||
// ============================== Settings ==============================
|
||||
|
@ -1,5 +1,7 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
}
|
||||
|
||||
ext {
|
||||
extName = 'Hinata Soul'
|
||||
|
@ -15,8 +15,6 @@ 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
|
||||
@ -37,14 +35,13 @@ class HinataSoul : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
override val supportsLatest = true
|
||||
|
||||
override val client: OkHttpClient = network.cloudflareClient
|
||||
override val client = network.cloudflareClient
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
|
||||
override fun headersBuilder(): Headers.Builder = Headers.Builder()
|
||||
.add("Referer", baseUrl)
|
||||
override fun headersBuilder() = super.headersBuilder().add("Referer", baseUrl)
|
||||
|
||||
// ============================== Popular ===============================
|
||||
override fun popularAnimeSelector() = "div.FsssItem:contains(Mais Vistos) > a"
|
||||
@ -58,21 +55,22 @@ class HinataSoul : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
// ============================== Episodes ==============================
|
||||
override fun episodeListSelector() = "div.aniContainer a"
|
||||
override fun episodeListParse(response: Response): List<SEpisode> {
|
||||
val totalEpisodes = mutableListOf<SEpisode>()
|
||||
var doc = getRealDoc(response.asJsoup())
|
||||
val originalUrl = doc.location()
|
||||
var pageNum = 1
|
||||
do {
|
||||
if (pageNum > 1) {
|
||||
doc = client.newCall(GET(originalUrl + "/page/$pageNum"))
|
||||
.execute()
|
||||
.asJsoup()
|
||||
}
|
||||
doc.select(episodeListSelector()).forEach {
|
||||
totalEpisodes.add(episodeFromElement(it))
|
||||
}
|
||||
pageNum++
|
||||
} while (hasNextPage(doc))
|
||||
val totalEpisodes = buildList {
|
||||
do {
|
||||
if (pageNum > 1) {
|
||||
doc = client.newCall(GET(originalUrl + "/page/$pageNum"))
|
||||
.execute()
|
||||
.asJsoup()
|
||||
}
|
||||
doc.select(episodeListSelector()).forEach {
|
||||
add(episodeFromElement(it))
|
||||
}
|
||||
pageNum++
|
||||
} while (hasNextPage(doc))
|
||||
}
|
||||
return totalEpisodes.reversed()
|
||||
}
|
||||
|
||||
@ -80,8 +78,7 @@ class HinataSoul : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
val title = element.attr("title")
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
name = title
|
||||
episode_number = runCatching { title.substringAfterLast(" ").toFloat() }
|
||||
.getOrNull() ?: 0F
|
||||
episode_number = title.substringAfterLast(" ").toFloatOrNull() ?: 0F
|
||||
date_upload = element.selectFirst("div.lancaster_episodio_info_data")!!
|
||||
.text()
|
||||
.toDate()
|
||||
@ -120,21 +117,14 @@ class HinataSoul : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
val slug = query.removePrefix(PREFIX_SEARCH)
|
||||
client.newCall(GET("$baseUrl/animes/$slug"))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeBySlugParse(response, slug)
|
||||
}
|
||||
.map(::searchAnimeBySlugParse)
|
||||
} else {
|
||||
client.newCall(searchAnimeRequest(page, query, filters))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeParse(response)
|
||||
}
|
||||
super.fetchSearchAnime(page, query, filters)
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchAnimeBySlugParse(response: Response, slug: String): AnimesPage {
|
||||
private fun searchAnimeBySlugParse(response: Response): AnimesPage {
|
||||
val details = animeDetailsParse(response)
|
||||
details.url = "/animes/$slug"
|
||||
return AnimesPage(listOf(details), false)
|
||||
}
|
||||
|
||||
@ -142,51 +132,53 @@ class HinataSoul : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
GET("$baseUrl/busca?busca=$query&page=$page")
|
||||
|
||||
// =========================== Anime Details ============================
|
||||
override fun animeDetailsParse(document: Document): SAnime {
|
||||
val anime = SAnime.create()
|
||||
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
|
||||
val doc = getRealDoc(document)
|
||||
setUrlWithoutDomain(doc.location())
|
||||
val infos = doc.selectFirst("div.aniInfosSingle")!!
|
||||
val img = infos.selectFirst("img")!!
|
||||
anime.thumbnail_url = img.attr("src")
|
||||
anime.title = img.attr("alt")
|
||||
anime.genre = infos.select("div.aniInfosSingleGeneros > span")
|
||||
.joinToString(", ") { it.text() }
|
||||
thumbnail_url = img.attr("src")
|
||||
title = img.attr("alt")
|
||||
genre = infos.select("div.aniInfosSingleGeneros > span")
|
||||
.eachText()
|
||||
.joinToString()
|
||||
|
||||
anime.author = infos.getInfo("AUTOR")
|
||||
anime.artist = infos.getInfo("ESTÚDIO")
|
||||
anime.status = parseStatus(infos.selectFirst("div.anime_status")!!)
|
||||
author = infos.getInfo("AUTOR")
|
||||
artist = infos.getInfo("ESTÚDIO")
|
||||
status = parseStatus(infos.selectFirst("div.anime_status")!!)
|
||||
|
||||
var desc = infos.selectFirst("div.aniInfosSingleSinopse > p")!!.text() + "\n"
|
||||
infos.getInfo("Título")?.let { desc += "\nTítulos Alternativos: $it" }
|
||||
infos.selectFirst("div.aniInfosSingleNumsItem:contains(Ano)")?.let {
|
||||
desc += "\nAno: ${it.ownText()}"
|
||||
description = buildString {
|
||||
append(infos.selectFirst("div.aniInfosSingleSinopse > p")!!.text() + "\n")
|
||||
infos.getInfo("Título")?.also { append("\nTítulos Alternativos: $it") }
|
||||
infos.selectFirst("div.aniInfosSingleNumsItem:contains(Ano)")?.also {
|
||||
append("\nAno: ${it.ownText()}")
|
||||
}
|
||||
infos.getInfo("Temporada")?.also { append("\nTemporada: $it") }
|
||||
}
|
||||
infos.getInfo("Temporada")?.let { desc += "\nTemporada: $it" }
|
||||
anime.description = desc
|
||||
|
||||
return anime
|
||||
}
|
||||
|
||||
// =============================== Latest ===============================
|
||||
override fun latestUpdatesNextPageSelector(): String? = null
|
||||
override fun latestUpdatesSelector(): String =
|
||||
"div.tituloContainer:contains(lançamento) + div.epiContainer a"
|
||||
|
||||
override fun latestUpdatesFromElement(element: Element) = SAnime.create().apply {
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
val img = element.selectFirst("img")!!
|
||||
thumbnail_url = img.attr("src")
|
||||
title = img.attr("alt")
|
||||
}
|
||||
|
||||
override fun latestUpdatesRequest(page: Int): Request = GET(baseUrl)
|
||||
|
||||
// ============================== Settings ==============================
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
val videoQualityPref = ListPreference(screen.context).apply {
|
||||
key = PREFERRED_QUALITY
|
||||
title = "Qualidade preferida"
|
||||
entries = QUALITY_LIST
|
||||
entryValues = QUALITY_LIST
|
||||
setDefaultValue(QUALITY_LIST.last())
|
||||
ListPreference(screen.context).apply {
|
||||
key = PREF_QUALITY_KEY
|
||||
title = PREF_QUALITY_TITLE
|
||||
entries = PREF_QUALITY_VALUES
|
||||
entryValues = PREF_QUALITY_VALUES
|
||||
setDefaultValue(PREF_QUALITY_DEFAULT)
|
||||
summary = "%s"
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val selected = newValue as String
|
||||
@ -194,13 +186,10 @@ class HinataSoul : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
val entry = entryValues[index] as String
|
||||
preferences.edit().putString(key, entry).commit()
|
||||
}
|
||||
}
|
||||
|
||||
screen.addPreference(videoQualityPref)
|
||||
}.also(screen::addPreference)
|
||||
}
|
||||
|
||||
// ============================= Utilities ==============================
|
||||
|
||||
private fun parseStatus(element: Element): Int {
|
||||
return when {
|
||||
element.hasClass("completed") -> SAnime.COMPLETED
|
||||
@ -213,26 +202,20 @@ class HinataSoul : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
val currentUrl = doc.location()
|
||||
val nextUrl = doc.selectFirst("a:contains(»)")!!.attr("href")
|
||||
val endings = listOf("/1", "page=1")
|
||||
return !endings.any { nextUrl.endsWith(it) } && currentUrl != nextUrl
|
||||
return !endings.any(nextUrl::endsWith) && currentUrl != nextUrl
|
||||
}
|
||||
|
||||
private val animeMenuSelector = "div.controlesBoxItem > a > i.iconLista"
|
||||
private val animeMenuSelector = "div.controlesBoxItem > a:has(i.iconLista)"
|
||||
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
|
||||
}
|
||||
return document.selectFirst(animeMenuSelector)?.let {
|
||||
client.newCall(GET(it.attr("href"), headers)).execute().asJsoup()
|
||||
} ?: document
|
||||
}
|
||||
|
||||
private fun Element.getInfo(key: String): String? {
|
||||
val div = this.selectFirst("div.aniInfosSingleInfoItem:contains($key)")
|
||||
if (div == null) return div
|
||||
val span = div.selectFirst("span")
|
||||
return span?.text()
|
||||
return selectFirst("div.aniInfosSingleInfoItem:contains($key) span")
|
||||
?.text()
|
||||
?.trim()
|
||||
}
|
||||
|
||||
private fun String.toDate(): Long {
|
||||
@ -241,18 +224,10 @@ class HinataSoul : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
}
|
||||
|
||||
override fun List<Video>.sort(): List<Video> {
|
||||
val quality = preferences.getString(PREFERRED_QUALITY, "FULLHD")!!
|
||||
val newList = mutableListOf<Video>()
|
||||
var preferred = 0
|
||||
for (video in this) {
|
||||
if (video.quality.trim() == quality) {
|
||||
newList.add(preferred, video)
|
||||
preferred++
|
||||
} else {
|
||||
newList.add(video)
|
||||
}
|
||||
}
|
||||
return newList
|
||||
val quality = preferences.getString(PREF_QUALITY_KEY, PREF_QUALITY_DEFAULT)!!
|
||||
return sortedWith(
|
||||
compareBy { it.quality.contains(quality) },
|
||||
).reversed()
|
||||
}
|
||||
|
||||
companion object {
|
||||
@ -260,9 +235,11 @@ class HinataSoul : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
SimpleDateFormat("dd/MM/yyyy à's' HH:mm", Locale.ENGLISH)
|
||||
}
|
||||
|
||||
private const val PREFERRED_QUALITY = "preferred_quality"
|
||||
private val QUALITY_LIST = arrayOf("SD", "HD", "FULLHD")
|
||||
|
||||
const val PREFIX_SEARCH = "slug:"
|
||||
|
||||
private const val PREF_QUALITY_KEY = "preferred_quality"
|
||||
private const val PREF_QUALITY_TITLE = "Qualidade preferida"
|
||||
private const val PREF_QUALITY_DEFAULT = "FULLHD"
|
||||
private val PREF_QUALITY_VALUES = arrayOf("SD", "HD", "FULLHD")
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
}
|
||||
|
||||
ext {
|
||||
extName = 'Meus Animes'
|
||||
|
@ -16,7 +16,7 @@ object MAFilters {
|
||||
}
|
||||
|
||||
private inline fun <reified R> AnimeFilterList.asQueryPart(): String {
|
||||
return this.filterIsInstance<R>().joinToString("") {
|
||||
return first { it is R }.let {
|
||||
(it as QueryPartFilter).toQueryPart()
|
||||
}
|
||||
}
|
||||
|
@ -45,16 +45,12 @@ class MeusAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
override fun popularAnimeSelector(): String = "div.ultAnisContainerItem > a"
|
||||
|
||||
// ============================== Episodes ==============================
|
||||
override fun episodeFromElement(element: Element): SEpisode {
|
||||
return SEpisode.create().apply {
|
||||
element.attr("href")!!.also {
|
||||
setUrlWithoutDomain(it)
|
||||
episode_number = try {
|
||||
it.substringAfterLast("/").toFloat()
|
||||
} catch (e: NumberFormatException) { 0F }
|
||||
}
|
||||
name = element.text()
|
||||
override fun episodeFromElement(element: Element) = SEpisode.create().apply {
|
||||
element.attr("href")!!.also {
|
||||
setUrlWithoutDomain(it)
|
||||
episode_number = it.substringAfterLast("/").toFloatOrNull() ?: 0F
|
||||
}
|
||||
name = element.text()
|
||||
}
|
||||
|
||||
override fun episodeListSelector(): String = "div#aba_epi > a"
|
||||
@ -62,23 +58,21 @@ class MeusAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
override fun episodeListParse(response: Response) = super.episodeListParse(response).reversed()
|
||||
|
||||
// =========================== Anime Details ============================
|
||||
override fun animeDetailsParse(document: Document): SAnime {
|
||||
return SAnime.create().apply {
|
||||
val infos = document.selectFirst("div.animeInfos")!!
|
||||
val right = document.selectFirst("div.right")!!
|
||||
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
|
||||
val infos = document.selectFirst("div.animeInfos")!!
|
||||
val right = document.selectFirst("div.right")!!
|
||||
|
||||
setUrlWithoutDomain(document.location())
|
||||
title = right.selectFirst("h1")!!.text()
|
||||
genre = right.select("ul.animeGen a").joinToString(", ") { it.text() }
|
||||
setUrlWithoutDomain(document.location())
|
||||
title = right.selectFirst("h1")!!.text()
|
||||
genre = right.select("ul.animeGen a").eachText().joinToString()
|
||||
|
||||
thumbnail_url = infos.selectFirst("img")!!.attr("data-lazy-src")
|
||||
description = right.selectFirst("div.animeSecondContainer > p:gt(0)")!!.text()
|
||||
}
|
||||
thumbnail_url = infos.selectFirst("img")!!.attr("data-lazy-src")
|
||||
description = right.selectFirst("div.animeSecondContainer > p:gt(0)")!!.text()
|
||||
}
|
||||
|
||||
// ============================ Video Links =============================
|
||||
override fun videoListParse(response: Response): List<Video> {
|
||||
val document: Document = response.asJsoup()
|
||||
val document = response.asJsoup()
|
||||
val videoElement = document.selectFirst("div.playerBox > *")!!
|
||||
return if (videoElement.tagName() == "video") {
|
||||
MeusAnimesExtractor(client).videoListFromElement(videoElement)
|
||||
@ -92,19 +86,19 @@ class MeusAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
override fun videoUrlParse(document: Document) = throw Exception("not used")
|
||||
|
||||
// =============================== Search ===============================
|
||||
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request = throw Exception("not used")
|
||||
override fun searchAnimeFromElement(element: Element) = latestUpdatesFromElement(element)
|
||||
override fun searchAnimeSelector() = popularAnimeSelector()
|
||||
override fun searchAnimeNextPageSelector() = "div.paginacao > a.next"
|
||||
override fun getFilterList(): AnimeFilterList = MAFilters.FILTER_LIST
|
||||
|
||||
private fun searchAnimeRequest(page: Int, query: String, filters: MAFilters.FilterSearchParams): Request {
|
||||
override fun searchAnimeRequest(page: Int, query: String, filters: AnimeFilterList): Request {
|
||||
val defaultUrl = "$baseUrl/lista-de-animes/$page"
|
||||
val params = MAFilters.getSearchParameters(filters)
|
||||
return when {
|
||||
filters.letter.isNotBlank() -> GET("$defaultUrl?letra=${filters.letter}")
|
||||
filters.year.isNotBlank() -> GET("$defaultUrl?ano=${filters.year}")
|
||||
filters.audio.isNotBlank() -> GET("$defaultUrl?audio=${filters.audio}")
|
||||
filters.genre.isNotBlank() -> GET("$defaultUrl?genero=${filters.genre}")
|
||||
params.letter.isNotBlank() -> GET("$defaultUrl?letra=${params.letter}")
|
||||
params.year.isNotBlank() -> GET("$defaultUrl?ano=${params.year}")
|
||||
params.audio.isNotBlank() -> GET("$defaultUrl?audio=${params.audio}")
|
||||
params.genre.isNotBlank() -> GET("$defaultUrl?genero=${params.genre}")
|
||||
query.isNotBlank() -> GET("$defaultUrl?s=$query")
|
||||
else -> GET(defaultUrl)
|
||||
}
|
||||
@ -115,36 +109,26 @@ class MeusAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
val id = query.removePrefix(PREFIX_SEARCH)
|
||||
client.newCall(GET("$baseUrl/animes/$id"))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeByIdParse(response, id)
|
||||
}
|
||||
.map(::searchAnimeByIdParse)
|
||||
} else {
|
||||
val params = MAFilters.getSearchParameters(filters)
|
||||
client.newCall(searchAnimeRequest(page, query, params))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeParse(response)
|
||||
}
|
||||
super.fetchSearchAnime(page, query, filters)
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchAnimeByIdParse(response: Response, id: String): AnimesPage {
|
||||
private fun searchAnimeByIdParse(response: Response): AnimesPage {
|
||||
val details = animeDetailsParse(response.asJsoup())
|
||||
details.url = "/animes/$id"
|
||||
return AnimesPage(listOf(details), false)
|
||||
}
|
||||
|
||||
// =============================== Latest ===============================
|
||||
override fun latestUpdatesFromElement(element: Element): SAnime {
|
||||
return SAnime.create().apply {
|
||||
title = element.attr("title")
|
||||
thumbnail_url = element.selectFirst("img")?.attr("data-lazy-src")
|
||||
val epUrl = element.attr("href")
|
||||
override fun latestUpdatesFromElement(element: Element) = SAnime.create().apply {
|
||||
title = element.attr("title")
|
||||
thumbnail_url = element.selectFirst("img")?.attr("data-lazy-src")
|
||||
val epUrl = element.attr("href")
|
||||
|
||||
if (epUrl.substringAfterLast("/").toIntOrNull() != null) {
|
||||
setUrlWithoutDomain(epUrl.substringBeforeLast("/") + "-todos-os-episodios")
|
||||
} else { setUrlWithoutDomain(epUrl) }
|
||||
}
|
||||
if (epUrl.substringAfterLast("/").toIntOrNull() != null) {
|
||||
setUrlWithoutDomain(epUrl.substringBeforeLast("/") + "-todos-os-episodios")
|
||||
} else { setUrlWithoutDomain(epUrl) }
|
||||
}
|
||||
|
||||
override fun latestUpdatesNextPageSelector(): String? = null
|
||||
@ -158,7 +142,7 @@ class MeusAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
title = PREF_QUALITY_TITLE
|
||||
entries = PREF_QUALITY_ENTRIES
|
||||
entryValues = PREF_QUALITY_ENTRIES
|
||||
setDefaultValue(PREF_QUALITY_ENTRIES.last())
|
||||
setDefaultValue(PREF_QUALITY_DEFAULT)
|
||||
summary = "%s"
|
||||
setOnPreferenceChangeListener { _, newValue ->
|
||||
val selected = newValue as String
|
||||
@ -172,7 +156,7 @@ class MeusAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
// ============================= Utilities ==============================
|
||||
override fun List<Video>.sort(): List<Video> {
|
||||
val quality = preferences.getString(PREF_QUALITY_KEY, "HD")!!
|
||||
val quality = preferences.getString(PREF_QUALITY_KEY, PREF_QUALITY_DEFAULT)!!
|
||||
return sortedWith(
|
||||
compareBy { it.quality.contains(quality) },
|
||||
).reversed()
|
||||
@ -183,6 +167,7 @@ class MeusAnimes : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
|
||||
|
||||
private const val PREF_QUALITY_KEY = "pref_quality"
|
||||
private const val PREF_QUALITY_TITLE = "Qualidade preferida"
|
||||
private const val PREF_QUALITY_DEFAULT = "HD"
|
||||
private val PREF_QUALITY_ENTRIES = arrayOf("SD", "HD")
|
||||
}
|
||||
}
|
||||
|
@ -19,10 +19,6 @@ class MeusAnimesUrlActivity : Activity() {
|
||||
super.onCreate(savedInstanceState)
|
||||
val pathSegments = intent?.data?.pathSegments
|
||||
if (pathSegments != null && pathSegments.size > 1) {
|
||||
// https://<host>/<segment 0>/<segment 1>...
|
||||
// ex: pattern "/animes/..*" -> pathSegments[1]
|
||||
// ex: pattern "/animes/info/..*" -> pathSegments[2]
|
||||
// etc..
|
||||
val item = pathSegments[1]
|
||||
val mainIntent = Intent().apply {
|
||||
action = "eu.kanade.tachiyomi.ANIMESEARCH"
|
||||
|
@ -5,7 +5,6 @@ import eu.kanade.tachiyomi.network.GET
|
||||
import okhttp3.Headers
|
||||
import okhttp3.OkHttpClient
|
||||
import org.jsoup.nodes.Element
|
||||
import java.net.ProtocolException
|
||||
|
||||
class MeusAnimesExtractor(private val client: OkHttpClient) {
|
||||
|
||||
@ -13,14 +12,15 @@ class MeusAnimesExtractor(private val client: OkHttpClient) {
|
||||
|
||||
fun videoListFromElement(element: Element): List<Video> {
|
||||
val headers = Headers.headersOf("Range", "bytes=0-1")
|
||||
val urls = mutableMapOf<String, String>().apply {
|
||||
val urls = buildMap {
|
||||
val sdUrl = element.attr("src")
|
||||
put("SD", sdUrl)
|
||||
val hdUrl = sdUrl.replace("/sd/", "/hd/")
|
||||
try {
|
||||
val testIt = client.newCall(head(hdUrl, headers)).execute()
|
||||
runCatching {
|
||||
// Check if the url is playing
|
||||
client.newCall(head(hdUrl, headers)).execute()
|
||||
put("HD", hdUrl)
|
||||
} catch (e: ProtocolException) {}
|
||||
}
|
||||
}
|
||||
return urls.map { (quality, url) -> Video(url, quality, url) }
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlinx-serialization'
|
||||
plugins {
|
||||
alias(libs.plugins.android.application)
|
||||
alias(libs.plugins.kotlin.android)
|
||||
alias(libs.plugins.kotlin.serialization)
|
||||
}
|
||||
|
||||
ext {
|
||||
extName = 'Vizer.tv'
|
||||
@ -12,8 +14,8 @@ ext {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(':lib-mixdrop-extractor'))
|
||||
implementation(project(':lib-streamtape-extractor'))
|
||||
implementation "dev.datlag.jsunpacker:jsunpacker:1.0.1"
|
||||
}
|
||||
|
||||
apply from: "$rootDir/common.gradle"
|
||||
|
@ -11,7 +11,6 @@ import eu.kanade.tachiyomi.animeextension.pt.vizer.dto.SearchItemDto
|
||||
import eu.kanade.tachiyomi.animeextension.pt.vizer.dto.SearchResultDto
|
||||
import eu.kanade.tachiyomi.animeextension.pt.vizer.dto.VideoDto
|
||||
import eu.kanade.tachiyomi.animeextension.pt.vizer.dto.VideoLanguagesDto
|
||||
import eu.kanade.tachiyomi.animeextension.pt.vizer.extractors.MixDropExtractor
|
||||
import eu.kanade.tachiyomi.animesource.ConfigurableAnimeSource
|
||||
import eu.kanade.tachiyomi.animesource.model.AnimeFilterList
|
||||
import eu.kanade.tachiyomi.animesource.model.AnimesPage
|
||||
@ -19,6 +18,7 @@ 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.AnimeHttpSource
|
||||
import eu.kanade.tachiyomi.lib.mixdropextractor.MixDropExtractor
|
||||
import eu.kanade.tachiyomi.lib.streamtapeextractor.StreamTapeExtractor
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.POST
|
||||
@ -35,6 +35,7 @@ import org.jsoup.nodes.Element
|
||||
import rx.Observable
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
|
||||
@ -49,16 +50,13 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
|
||||
override val client: OkHttpClient = network.cloudflareClient
|
||||
|
||||
private val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
}
|
||||
private val json: Json by injectLazy()
|
||||
|
||||
private val preferences: SharedPreferences by lazy {
|
||||
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
|
||||
}
|
||||
|
||||
// ============================== Popular ===============================
|
||||
|
||||
override fun popularAnimeRequest(page: Int): Request {
|
||||
val pageType = preferences.getString(PREF_POPULAR_PAGE_KEY, PREF_POPULAR_PAGE_DEFAULT)!!
|
||||
val params = FilterSearchParams(
|
||||
@ -71,41 +69,39 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
|
||||
override fun popularAnimeParse(response: Response): AnimesPage {
|
||||
val result = response.parseAs<SearchResultDto>()
|
||||
val animes = result.list.map(::animeFromObject).toList()
|
||||
val animes = result.list.map(::animeFromObject)
|
||||
val hasNext = result.quantity == 35
|
||||
return AnimesPage(animes, hasNext)
|
||||
}
|
||||
|
||||
private fun animeFromObject(item: SearchItemDto): SAnime =
|
||||
SAnime.create().apply {
|
||||
var slug = if (item.status.isBlank()) "filme" else "serie"
|
||||
url = "/$slug/online/${item.url}"
|
||||
slug = if (slug == "filme") "movies" else "series"
|
||||
title = item.title
|
||||
status = when (item.status) {
|
||||
"Retornando" -> SAnime.ONGOING
|
||||
else -> SAnime.COMPLETED
|
||||
}
|
||||
thumbnail_url = "$baseUrl/content/$slug/posterPt/342/${item.id}.webp"
|
||||
private fun animeFromObject(item: SearchItemDto) = SAnime.create().apply {
|
||||
val (urlslug, imgslug) = when {
|
||||
item.status.isBlank() -> Pair("filme", "movies")
|
||||
else -> Pair("serie", "series")
|
||||
}
|
||||
url = "/$urlslug/online/${item.url}"
|
||||
title = item.title
|
||||
status = when (item.status) {
|
||||
"Retornando" -> SAnime.ONGOING
|
||||
else -> SAnime.COMPLETED
|
||||
}
|
||||
thumbnail_url = "$baseUrl/content/$imgslug/posterPt/342/${item.id}.webp"
|
||||
}
|
||||
|
||||
// ============================== Episodes ==============================
|
||||
|
||||
private fun getSeasonEps(seasonElement: Element): List<SEpisode> {
|
||||
val id = seasonElement.attr("data-season-id")
|
||||
val sname = seasonElement.text()
|
||||
val response = client.newCall(apiRequest("getEpisodes=$id")).execute()
|
||||
val episodes = response.parseAs<EpisodeListDto>().episodes.mapNotNull {
|
||||
if (it.released) {
|
||||
val episodes = response.parseAs<EpisodeListDto>().episodes
|
||||
.filter { it.released }
|
||||
.map {
|
||||
SEpisode.create().apply {
|
||||
name = "Temp $sname: Ep ${it.name} - ${it.title}"
|
||||
episode_number = it.name.toFloatOrNull() ?: 0F
|
||||
url = it.id
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
return episodes
|
||||
}
|
||||
|
||||
@ -126,7 +122,6 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
}
|
||||
|
||||
// ============================ Video Links =============================
|
||||
|
||||
override fun videoListRequest(episode: SEpisode): Request {
|
||||
val url = episode.url
|
||||
return if (url.startsWith("https")) {
|
||||
@ -161,9 +156,7 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
val url = getPlayerUrl(videoObj.id, name)
|
||||
when (name) {
|
||||
"mixdrop" ->
|
||||
MixDropExtractor(client)
|
||||
.videoFromUrl(url, langPrefix)
|
||||
?.let(::listOf)
|
||||
MixDropExtractor(client).videoFromUrl(url, langPrefix)
|
||||
"streamtape" ->
|
||||
StreamTapeExtractor(client)
|
||||
.videoFromUrl(url, "StreamTape($langPrefix)")
|
||||
@ -175,7 +168,6 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
}
|
||||
|
||||
// =============================== Search ===============================
|
||||
|
||||
override fun getFilterList(): AnimeFilterList = VizerFilters.FILTER_LIST
|
||||
|
||||
override fun searchAnimeParse(response: Response) = popularAnimeParse(response)
|
||||
@ -185,17 +177,14 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
val path = query.removePrefix(PREFIX_SEARCH).replace("/", "/online/")
|
||||
client.newCall(GET("$baseUrl/$path"))
|
||||
.asObservableSuccess()
|
||||
.map { response ->
|
||||
searchAnimeByPathParse(response, path)
|
||||
}
|
||||
.map(::searchAnimeByPathParse)
|
||||
} else {
|
||||
super.fetchSearchAnime(page, query, filters)
|
||||
}
|
||||
}
|
||||
|
||||
private fun searchAnimeByPathParse(response: Response, path: String): AnimesPage {
|
||||
private fun searchAnimeByPathParse(response: Response): AnimesPage {
|
||||
val details = animeDetailsParse(response)
|
||||
details.url = "/" + path
|
||||
return AnimesPage(listOf(details), false)
|
||||
}
|
||||
|
||||
@ -230,23 +219,22 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
}
|
||||
|
||||
// =========================== Anime Details ============================
|
||||
|
||||
override fun animeDetailsParse(response: Response): SAnime {
|
||||
override fun animeDetailsParse(response: Response) = SAnime.create().apply {
|
||||
val doc = response.asJsoup()
|
||||
return SAnime.create().apply {
|
||||
title = doc.selectFirst("section.ai > h2")!!.text()
|
||||
thumbnail_url = doc.selectFirst("meta[property=og:image]")!!.attr("content")
|
||||
var desc = doc.selectFirst("span.desc")!!.text() + "\n"
|
||||
doc.selectFirst("div.year")?.let { desc += "\nAno: ${it.text()}" }
|
||||
doc.selectFirst("div.tm")?.let { desc += "\nDuração: ${it.text()}" }
|
||||
doc.selectFirst("a.rating")?.let { desc += "\nNota: ${it.text()}" }
|
||||
description = desc
|
||||
setUrlWithoutDomain(doc.location())
|
||||
title = doc.selectFirst("section.ai > h2")!!.text()
|
||||
thumbnail_url = doc.selectFirst("meta[property=og:image]")!!.attr("content")
|
||||
|
||||
description = buildString {
|
||||
append(doc.selectFirst("span.desc")!!.text() + "\n")
|
||||
doc.selectFirst("div.year")?.let { append("\nAno: ${it.text()}") }
|
||||
doc.selectFirst("div.tm")?.let { append("\nDuração: ${it.text()}") }
|
||||
doc.selectFirst("a.rating")?.let { append("\nNota: ${it.text()}") }
|
||||
}
|
||||
}
|
||||
|
||||
// =============================== Latest ===============================
|
||||
|
||||
override fun latestUpdatesRequest(page: Int): Request = apiRequest("getHomeSliderSeries=1")
|
||||
override fun latestUpdatesRequest(page: Int) = apiRequest("getHomeSliderSeries=1")
|
||||
|
||||
override fun latestUpdatesParse(response: Response): AnimesPage {
|
||||
val parsedData = response.parseAs<SearchResultDto>()
|
||||
@ -255,7 +243,6 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
}
|
||||
|
||||
// ============================== Settings ==============================
|
||||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) {
|
||||
val popularPage = ListPreference(screen.context).apply {
|
||||
key = PREF_POPULAR_PAGE_KEY
|
||||
@ -308,7 +295,6 @@ class Vizer : ConfigurableAnimeSource, AnimeHttpSource() {
|
||||
}
|
||||
|
||||
// ============================= Utilities ==============================
|
||||
|
||||
private fun getPlayerUrl(id: String, name: String): String {
|
||||
val req = GET("$baseUrl/embed/getPlay.php?id=$id&sv=$name")
|
||||
val body = client.newCall(req).execute().body.string()
|
||||
|
@ -17,11 +17,11 @@ object VizerFilters {
|
||||
}
|
||||
|
||||
private inline fun <reified R> AnimeFilterList.getFirst(): R {
|
||||
return this.filterIsInstance<R>().first()
|
||||
return first { it is R } as R
|
||||
}
|
||||
|
||||
private inline fun <reified R> AnimeFilterList.asQueryPart(): String {
|
||||
return this.getFirst<R>().let {
|
||||
return getFirst<R>().let {
|
||||
(it as QueryPartFilter).toQueryPart()
|
||||
}
|
||||
}
|
||||
|
@ -1,27 +0,0 @@
|
||||
package eu.kanade.tachiyomi.animeextension.pt.vizer.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 okhttp3.OkHttpClient
|
||||
|
||||
class MixDropExtractor(private val client: OkHttpClient) {
|
||||
fun videoFromUrl(url: String, lang: String = ""): Video? {
|
||||
val doc = client.newCall(GET(url)).execute().asJsoup()
|
||||
val unpacked = doc.selectFirst("script:containsData(eval):containsData(MDCore)")
|
||||
?.data()
|
||||
?.let { JsUnpacker.unpackAndCombine(it) }
|
||||
?: return null
|
||||
val videoUrl = "https:" + unpacked.substringAfter("Core.wurl=\"")
|
||||
.substringBefore("\"")
|
||||
val quality = ("MixDrop").let {
|
||||
if (lang.isNotBlank()) {
|
||||
"$it($lang)"
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
return Video(url, quality, videoUrl)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user