Merge pull request #3 from edgardmessias/pt/animeshouse

feat(pt/animeshouse): New Source AnimesHouse
This commit is contained in:
almightyhak 2024-06-23 11:46:22 +07:00 committed by GitHub
commit 9b96273df0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 194 additions and 0 deletions

View file

@ -0,0 +1,9 @@
ext {
extName = 'AnimesHouse'
extClass = '.AnimesHouse'
themePkg = 'dooplay'
baseUrl = 'https://animeshouse.app/'
overrideVersionCode = 1
}
apply from: "$rootDir/common.gradle"

Binary file not shown.

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -0,0 +1,136 @@
package eu.kanade.tachiyomi.animeextension.pt.animeshouse
import android.util.Base64
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.animeextension.pt.animeshouse.extractors.AnimeBlackMarketExtractor
import eu.kanade.tachiyomi.animesource.model.SAnime
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.multisrc.dooplay.DooPlay
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import eu.kanade.tachiyomi.util.parallelCatchingFlatMapBlocking
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
class AnimesHouse : DooPlay(
"pt-BR",
"Animes House",
"https://animeshouse.app",
) {
// ============================== Popular ===============================
override fun popularAnimeRequest(page: Int) = GET("$baseUrl/assistir-anime/", headers)
// =============================== Search ===============================
override fun searchAnimeSelector() = "div.result-item article div.thumbnail > a"
override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element)
// =========================== Anime Details ============================
override val additionalInfoSelector = "div.wp-content"
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()
}
}
genre = sheader.select("div.data div.sgeneros > a")
.eachText()
.joinToString()
description = doc.getDescription()
}
}
// ============================== Episodes ==============================
override fun getSeasonEpisodes(season: Element) = super.getSeasonEpisodes(season).reversed()
// ============================ Video Links =============================
override fun videoListParse(response: Response): List<Video> {
val document = response.asJsoup()
val players = document.select("div.source-box:not(#source-player-trailer)")
return players.parallelCatchingFlatMapBlocking(::getPlayerVideos)
}
override val prefQualityValues = arrayOf("360p", "480p", "720p", "1080p")
override val prefQualityEntries = prefQualityValues
private val animeblack by lazy { AnimeBlackMarketExtractor(client, headers) }
private fun getPlayerVideos(player: Element): List<Video> {
val fullUrl = player.selectFirst("a")?.attr("href")
?: player.selectFirst("iframe")?.attr("src")
val url = fullUrl?.let {
when {
it.contains("token=") -> {
it.substringAfter("token=")
.let { String(Base64.decode(it, Base64.DEFAULT)) }
}
else -> it
}
} ?: return emptyList()
return when {
"animeblackmarketapi.com" in url -> animeblack.videosFromUrl(url)
else -> emptyList()
}
}
// ============================== Filters ===============================
override fun genresListRequest() = GET("$baseUrl/generos/", headers)
override fun genresListSelector() = "a.genre-link"
// ============================== 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(quality.lowercase()) },
{ it.quality.lowercase().contains(language.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
}
}

View file

@ -0,0 +1,49 @@
package eu.kanade.tachiyomi.animeextension.pt.animeshouse.extractors
import android.util.Base64
import eu.kanade.tachiyomi.animesource.model.Video
import eu.kanade.tachiyomi.network.GET
import okhttp3.Headers
import okhttp3.OkHttpClient
class AnimeBlackMarketExtractor(private val client: OkHttpClient, private val headers: Headers) {
fun videosFromUrl(url: String): List<Video> {
val newHeaders = headers.newBuilder().set("referer", "https://animeblackmarketapi.com/").build()
val body = client.newCall(GET(url)).execute().body.string()
return body.substringAfter("\"data\":[")
.substringBefore(']')
.split("{")
.drop(1)
.map {
val language = it
.substringAfter("\"idioma\":\"")
.substringBefore('"')
.let {
when (it) {
"DUB" -> "Dublado"
"LEG" -> "Legendado"
else -> it
}
}
val quality = it
.substringAfter("\"quality\":\"")
.substringBefore('"')
.let {
when (it) {
"FHD" -> "1080p"
"HD" -> "720p"
"SD" -> "480p"
else -> it
}
}
val videoUrl = it.substringAfter("file")
.substringAfter("\"video\":\"")
.substringBefore('"')
.let { String(Base64.decode(it, Base64.DEFAULT)) }
Video(videoUrl, "$language - $quality", videoUrl, newHeaders)
}
}
}