Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(pt/animeplayer): Fix popular anime, anime details and episode list pages #3271

Merged
merged 5 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pt/animeplayer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ ext {
extClass = '.AnimePlayer'
themePkg = 'dooplay'
baseUrl = 'https://animeplayer.com.br'
overrideVersionCode = 2
overrideVersionCode = 3
isNsfw = true
}

apply from: "$rootDir/common.gradle"

dependencies {
implementation(project(":lib:blogger-extractor"))
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package eu.kanade.tachiyomi.animeextension.pt.animeplayer

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.lib.bloggerextractor.BloggerExtractor
import eu.kanade.tachiyomi.multisrc.dooplay.DooPlay
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.HttpUrl.Companion.toHttpUrlOrNull
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element

class AnimePlayer : DooPlay(
"pt-BR",
Expand All @@ -15,14 +19,73 @@ class AnimePlayer : DooPlay(
) {

// ============================== Popular ===============================
override fun popularAnimeSelector() = "div#featured-titles article div.poster"
override fun popularAnimeSelector() = "div#archive-content article div.poster"

override fun popularAnimeRequest(page: Int) = GET("$baseUrl/animes/")

override fun popularAnimeNextPageSelector() = "a > i#nextpagination"

// =============================== Latest ===============================
override val latestUpdatesPath = "episodios"

override fun latestUpdatesNextPageSelector() = "a > i#nextpagination"
override fun latestUpdatesNextPageSelector() = popularAnimeNextPageSelector()

// =========================== Anime Details ============================
override fun animeDetailsParse(document: Document) = SAnime.create().apply {
val doc = getRealAnimeDoc(document)
val content = doc.selectFirst("div#contenedor > div.data")!!
doc.selectFirst("div.sheader div.poster > img")!!.let {
thumbnail_url = it.getImageUrl()
title = it.attr("alt").ifEmpty {
content.selectFirst("div.data > h1")!!.text()
}
}

genre = content.select("div.sgeneros > a")
.eachText()
.joinToString()
}

// ============================== Episodes ==============================
override fun episodeListParse(response: Response): List<SEpisode> {
val doc = getRealAnimeDoc(response.asJsoup())
val seasonList = doc.select(seasonListSelector)
return if (seasonList.size < 1) {
SEpisode.create().apply {
setUrlWithoutDomain(doc.location())
episode_number = 1F
name = episodeMovieText
}.let(::listOf)
} else {
seasonList.flatMap(::getSeasonEpisodes)
}
}

override fun getSeasonEpisodes(season: Element): List<SEpisode> {
val seasonName = season.selectFirst("span.title")!!.text()
return season.select(episodeListSelector()).mapNotNull { element ->
try {
episodeFromElement(element, seasonName)
} catch (e: Throwable) {
e.printStackTrace()
null
}
}
}

override fun episodeFromElement(element: Element): SEpisode = throw UnsupportedOperationException()

override fun episodeFromElement(element: Element, seasonName: String) = SEpisode.create().apply {
val epNum = element.selectFirst("div.episodiotitle p")!!.text()
.trim()
.let(episodeNumberRegex::find)
?.groupValues
?.last() ?: "0"
val href = element.selectFirst("a[href]")!!
episode_number = epNum.toFloatOrNull() ?: 0F
name = "$seasonName x Episódio $epNum"
setUrlWithoutDomain(href.absUrl("href"))
}

// ============================ Video Links =============================
override val prefQualityValues = arrayOf("360p", "720p")
Expand All @@ -33,7 +96,7 @@ class AnimePlayer : DooPlay(
override fun videoListParse(response: Response): List<Video> {
val playerUrl = response.asJsoup()
.selectFirst("div.playex iframe")
?.attr("abs:src")
?.absUrl("src")
?.toHttpUrlOrNull()
?: return emptyList()

Expand All @@ -43,4 +106,7 @@ class AnimePlayer : DooPlay(

// ============================== Filters ===============================
override fun genresListSelector() = "ul.genres a"

// ============================= Utilities ==============================
override val animeMenuSelector = "div.pag_episodes div.item a[href] i.icon-bars"
}