Skip to content

Commit

Permalink
fix wrong season displayed and series not loading if no language avai…
Browse files Browse the repository at this point in the history
…lable
  • Loading branch information
DatL4g committed Nov 15, 2023
1 parent cbaaaed commit a4fe8b0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,41 @@ data class Series(
@SerialName("cover") val coverHref: String? = null,
@SerialName("href") val href: String,
@SerialName("seasonTitle") val seasonTitle: String,
@SerialName("selectedLanguage") val selectedLanguage: String,
@SerialName("selectedLanguage") val selectedLanguage: String?,
@SerialName("seasons") val seasons: List<Season>,
@SerialName("languages") val languages: List<Language>,
@SerialName("episodes") val episodes: List<Episode>
) {

val currentSeason: Season? by lazy(LazyThreadSafetyMode.NONE) {
seasons.find {
val currentSeason: Season? by lazy {
seasons.firstOrNull {
it.title.equals(seasonTitle, true)
|| it.title.trim().equals(seasonTitle.trim(), true)
|| it.title.equals(seasonTitle.toIntOrNull()?.toString(), true)
|| it.title.toIntOrNull()?.toString().equals(seasonTitle.toIntOrNull()?.toString(), true)
|| it.title.equals(seasonTitle.getDigitsOrNull(), true)
|| it.title.getDigitsOrNull().equals(seasonTitle, true)
|| it.title.getDigitsOrNull().equals(seasonTitle.getDigitsOrNull(), true)
} ?: seasons.firstOrNull {
it.title.trim().equals(seasonTitle.trim(), true)
} ?: seasons.firstOrNull {
it.title.equals(seasonTitle.toIntOrNull()?.toString(), true)
} ?: seasons.firstOrNull {
val titleInt = it.title.toIntOrNull()
val seasonInt = seasonTitle.toIntOrNull()

titleInt != null && seasonInt != null && titleInt == seasonInt
} ?: seasons.firstOrNull {
it.title.equals(seasonTitle.getDigitsOrNull(), true)
} ?: seasons.firstOrNull {
it.title.getDigitsOrNull().equals(seasonTitle, true)
} ?: seasons.firstOrNull {
it.title.getDigitsOrNull().equals(seasonTitle.getDigitsOrNull(), true)
}
}

val currentLanguage: Language? by lazy(LazyThreadSafetyMode.NONE) {
val currentLanguage: Language? by lazy {
languages.find {
it.value.equals(selectedLanguage, true)
|| it.value.trim().equals(selectedLanguage.trim(), true)
|| it.value.trim().equals(selectedLanguage?.trim(), true)
}
}

fun hrefBuilder(season: Int? = currentSeason?.value, language: String = currentLanguage?.value ?: selectedLanguage): String {
fun hrefBuilder(season: Int? = currentSeason?.value, language: String? = currentLanguage?.value ?: selectedLanguage): String {
val hrefData = BSUtil.hrefDataFromHref(
BSUtil.normalizeHref(href)
)
Expand All @@ -48,7 +57,7 @@ data class Series(
Triple(
first = hrefData.first,
second = season?.toString() ?: hrefData.second,
third = language
third = language ?: hrefData.third
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ data object BurningSeries {
if (selectedLanguage.isNullOrBlank()) {
selectedLanguage = selectedLanguageValue
if (selectedLanguage.isNullOrBlank()) {
selectedLanguage = languages.firstOrNull()?.value ?: return null
selectedLanguage = languages.firstOrNull()?.value
}
}

val episodesDoc = doc.querySelector(".serie")?.querySelector(".episodes")?.querySelectorAll("tr") ?: emptyList()
val episodeInfoList = episodesDoc.mapNotNull { episodesElement ->
val episodeList = episodesElement.querySelectorAll("td").mapNotNull { it.querySelector("a") }.mapNotNull { data ->
val episodeList = episodesElement.querySelectorAll("td").mapNotNull { it.querySelector("a") }.map { data ->
val text = data.querySelector("a")?.textContent() ?: String()
val episodeHref = BSUtil.normalizeHref(data.querySelector("a")?.getHref() ?: String())

Expand Down Expand Up @@ -217,7 +217,7 @@ data object BurningSeries {
href = docHref,
seasonTitle = titleSeason ?: String(),
seasons = seasons,
selectedLanguage = selectedLanguage?.trim() ?: return null,
selectedLanguage = selectedLanguage?.trim(),
languages = languages,
episodes = episodeInfoList
)
Expand Down

0 comments on commit a4fe8b0

Please sign in to comment.