Skip to content

Commit

Permalink
Merge pull request #38 from Dark25/OppaiStream
Browse files Browse the repository at this point in the history
chore(en/OppaiStream) fix not episode list
  • Loading branch information
Dark25 authored Aug 15, 2024
2 parents 6f6515f + 5fbf31c commit 310000c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 30 deletions.
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

0 comments on commit 310000c

Please sign in to comment.