Skip to content

Commit

Permalink
fix(pt/animesgratis): Fixed episode parser for films
Browse files Browse the repository at this point in the history
  • Loading branch information
WebDitto committed Jun 30, 2024
1 parent cdbfbdc commit 0f2003a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/pt/animesgratis/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ext {
extClass = '.Bakashi'
themePkg = 'dooplay'
baseUrl = 'https://bakashi.tv'
overrideVersionCode = 10
overrideVersionCode = 11
}

apply from: "$rootDir/common.gradle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import java.text.SimpleDateFormat
import java.util.Locale

class Bakashi : DooPlay(
"pt-BR",
Expand All @@ -26,6 +28,10 @@ class Bakashi : DooPlay(

override val id: Long = 2969482460524685571L

override val dateFormatter by lazy {
SimpleDateFormat("dd/MM/yy", Locale("pt", "BR"))
}

// ============================== Popular ===============================
override fun popularAnimeSelector() = "div.items.featured article div.poster"
override fun popularAnimeRequest(page: Int) = GET("$baseUrl/animes/", headers)
Expand All @@ -35,11 +41,18 @@ class Bakashi : DooPlay(
override fun searchAnimeFromElement(element: Element) = popularAnimeFromElement(element)

// ============================== Episodes ==============================
override fun episodeListParse(response: Response) =
getRealAnimeDoc(response.asJsoup())
.select(episodeListSelector())
.map(::episodeFromElement)
.reversed()
override fun getSeasonEpisodes(season: Element): List<SEpisode> {
val seasonName = season.selectFirst("span.se-t")?.text()
return season.select(episodeListSelector()).mapNotNull { element ->
runCatching {
if (seasonName.isNullOrBlank()) {
episodeFromElement(element)
} else {
episodeFromElement(element, seasonName)
}
}.onFailure { it.printStackTrace() }.getOrNull()
}
}

override fun episodeListSelector() = "ul.episodios > li > div.episodiotitle > a"

Expand All @@ -49,6 +62,9 @@ class Bakashi : DooPlay(
name = it
episode_number = it.substringAfter(" ").toFloatOrNull() ?: 0F
}
date_upload = element.parent()?.selectFirst(episodeDateSelector)
?.text()
?.toDate() ?: 0L
}

// ============================ Video Links =============================
Expand Down Expand Up @@ -93,6 +109,7 @@ class Bakashi : DooPlay(
when {
it.contains("/aviso/") ->
it.toHttpUrl().queryParameter("url")

else -> it
}
}
Expand Down Expand Up @@ -125,4 +142,18 @@ class Bakashi : DooPlay(
.asJsoup()
} ?: document
}

override fun List<Video>.sort(): List<Video> {
val quality = preferences.getString(videoSortPrefKey, videoSortPrefDefault)!!
return sortedWith(
compareBy(
{ it.quality.contains(quality) },
{ REGEX_QUALITY.find(it.quality)?.groupValues?.get(1)?.toIntOrNull() ?: 0 },
),
).reversed()
}

companion object {
private val REGEX_QUALITY by lazy { Regex("""(\d+)p""") }
}
}

0 comments on commit 0f2003a

Please sign in to comment.