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

chore(en/OppaiStream) fix not episode list #38

Merged
merged 1 commit into from
Aug 15, 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/en/oppaistream/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Oppai Stream'
extClass = '.OppaiStream'
extVersionCode = 4
extVersionCode = 5
isNsfw = true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.POST
import eu.kanade.tachiyomi.util.asJsoup
import eu.kanade.tachiyomi.util.parseAs
import kotlinx.serialization.json.Json
import okhttp3.FormBody
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Request
Expand All @@ -28,7 +27,8 @@ import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import java.net.URLDecoder
import java.nio.charset.StandardCharsets

class OppaiStream : ParsedAnimeHttpSource(), ConfigurableAnimeSource {

Expand All @@ -46,8 +46,6 @@ class OppaiStream : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
Injekt.get<Application>().getSharedPreferences("source_$id", 0x0000)
}

private val json: Json by injectLazy()

// ============================== Popular ===============================
override fun popularAnimeRequest(page: Int) = GET("$baseUrl/$SEARCH_PATH?order=views&page=$page&limit=$SEARCH_LIMIT")

Expand Down Expand Up @@ -124,8 +122,10 @@ class OppaiStream : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
override fun searchAnimeFromElement(element: Element) = SAnime.create().apply {
thumbnail_url = element.selectFirst("img.cover-img-in")?.attr("abs:src")
title = element.selectFirst(".title-ep")!!.text().replace(TITLE_CLEANUP_REGEX, "")
val encodedUrl = element.attr("href").substringAfter("to=")
val decodedUrl = URLDecoder.decode(encodedUrl, StandardCharsets.UTF_8.toString())
setUrlWithoutDomain(
element.attr("href").replace(Regex("(?<=\\?e=)(.*?)(?=&f=)")) {
decodedUrl.replace(Regex("(?<=\\?e=)(.*?)(?=&f=)")) {
java.net.URLEncoder.encode(it.groupValues[1], "UTF-8")
},
)
Expand Down Expand Up @@ -157,40 +157,42 @@ class OppaiStream : ParsedAnimeHttpSource(), ConfigurableAnimeSource {
}

// ============================== Episodes ==============================
override fun episodeListParse(response: Response): List<SEpisode> {
val doc = response.asJsoup()
return buildList {
doc.select(episodeListSelector())
.map(::episodeFromElement)
.let(::addAll)

add(
SEpisode.create().apply {
setUrlWithoutDomain(
doc.location().replace(Regex("(?<=\\?e=)(.*?)(?=&f=)")) {
java.net.URLEncoder.encode(it.groupValues[1], "UTF-8")
},
)
val num = doc.selectFirst("div.episode-info > h1")!!.text().substringAfter(" Ep ")
name = "Episode $num"
episode_number = num.toFloatOrNull() ?: 1F
scanlator = doc.selectFirst("div.episode-info a.red")?.text()
},
)
}.sortedByDescending { it.episode_number }
}
// override fun episodeListParse(response: Response): List<SEpisode> {
// val doc = response.asJsoup()
// return buildList {
// doc.select(episodeListSelector())
// .map(::episodeFromElement)
// .let(::addAll)
//
// add(
// SEpisode.create().apply {
// setUrlWithoutDomain(
// doc.location().replace(Regex("(?<=\\?e=)(.*?)(?=&f=)")) {
// java.net.URLEncoder.encode(it.groupValues[1], "UTF-8")
// },
// )
// val num = doc.selectFirst("div.episode-info > h1")!!.text().substringAfter(" Ep ")
// name = "Episode $num"
// episode_number = num.toFloatOrNull() ?: 1F
// scanlator = doc.selectFirst("div.episode-info a.red")?.text()
// },
// )
// }.sortedByDescending { it.episode_number }
// }

override fun episodeListSelector() = "div.more-same-eps > div > div > a"

override fun episodeFromElement(element: Element) = SEpisode.create().apply {
val encodedUrl = element.attr("href").substringAfter("to=")
val decodedUrl = URLDecoder.decode(encodedUrl, StandardCharsets.UTF_8.toString())
setUrlWithoutDomain(
element.attr("href").replace(Regex("(?<=\\?e=)(.*?)(?=&f=)")) {
decodedUrl.replace(Regex("(?<=\\?e=)(.*?)(?=&f=)")) {
java.net.URLEncoder.encode(it.groupValues[1], "UTF-8")
},
)
val num = element.selectFirst("font.ep")?.text() ?: "1"
name = "Episode $num"
episode_number = num.toFloatOrNull() ?: 1F
episode_number = "0.$num".toFloat()
scanlator = element.selectFirst("h6 > a")?.text()
}

Expand Down