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/animesgratis): Fixed episode parser for films #18

Merged
merged 1 commit into from
Jul 1, 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
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""") }
}
}