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

SussyToons: Fix loading pages #7015

Merged
merged 1 commit into from
Jan 6, 2025
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
6 changes: 3 additions & 3 deletions src/pt/sussyscan/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ext {
extName = 'Sussy Scan'
extClass = '.SussyScan'
extVersionCode = 43
extName = 'Sussy Toons'
extClass = '.SussyToons'
extVersionCode = 44
isNsfw = true
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.kanade.tachiyomi.extension.pt.sussyscan

import android.annotation.SuppressLint
import android.util.Base64
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.interceptor.rateLimit
import eu.kanade.tachiyomi.source.model.FilterList
Expand All @@ -11,6 +12,7 @@ import eu.kanade.tachiyomi.source.model.SManga
import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.decodeFromStream
import okhttp3.Headers
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.Interceptor
import okhttp3.Request
Expand All @@ -21,9 +23,9 @@ import uy.kohesive.injekt.injectLazy
import java.text.SimpleDateFormat
import java.util.concurrent.TimeUnit

class SussyScan : HttpSource() {
class SussyToons : HttpSource() {

override val name = "Sussy Scan"
override val name = "Sussy Toons"

override val baseUrl = "https://new.sussytoons.site"

Expand All @@ -33,6 +35,8 @@ class SussyScan : HttpSource() {

override val supportsLatest = true

override val id = 6963507464339951166

// Moved from Madara
override val versionId = 2

Expand All @@ -54,7 +58,7 @@ class SussyScan : HttpSource() {

override fun popularMangaParse(response: Response): MangasPage {
val dto = response.parseAs<WrapperDto<List<MangaDto>>>()
val mangas = dto.results.map { it.toSManga() }
val mangas = dto.results.filterNot { it.slug.isNullOrBlank() }.map { it.toSManga() }
return MangasPage(mangas, false) // There's a pagination bug
}

Expand All @@ -70,7 +74,7 @@ class SussyScan : HttpSource() {

override fun latestUpdatesParse(response: Response): MangasPage {
val dto = response.parseAs<WrapperDto<List<MangaDto>>>()
val mangas = dto.results.map { it.toSManga() }
val mangas = dto.results.filterNot { it.slug.isNullOrBlank() }.map { it.toSManga() }
return MangasPage(mangas, dto.hasNextPage())
}

Expand Down Expand Up @@ -150,11 +154,25 @@ class SussyScan : HttpSource() {
// ============================= Pages ====================================

override fun pageListRequest(chapter: SChapter): Request {
val pageHeaders = buildPageListHeaders(chapter)
return GET("$apiUrl${chapter.url}", pageHeaders)
}

private fun buildPageListHeaders(chapter: SChapter): Headers {
val timestamp = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())
val xClientHash = when {
chapter.id.toInt() % 2 != 0 -> ""
else -> (headers.get("User-Agent") ?: "").md5()
}
val pageHeaders = headers.newBuilder()
.set("Accept", "application/json, text/plain, */*")
.set("Accept-Language", "pt-br,pt;q=0.9,en-us;q=0.8,en;q=0.7")
.set("Origin", baseUrl)
.set("Referer", "$baseUrl/")
.set("x-client-hash", xClientHash)
.set("x-timestamp", timestamp.toString())
.build()
return GET("$apiUrl${chapter.url}", pageHeaders)
return pageHeaders
}

override fun pageListParse(response: Response): List<Page> {
Expand Down Expand Up @@ -186,7 +204,7 @@ class SussyScan : HttpSource() {
initialized = true
val mangaUrl = "$baseUrl/obra".toHttpUrl().newBuilder()
.addPathSegment([email protected]())
.addPathSegment([email protected])
.addPathSegment([email protected]!!)
.build()
setUrlWithoutDomain(mangaUrl.toString())
}
Expand Down Expand Up @@ -224,6 +242,11 @@ class SussyScan : HttpSource() {
private fun String.toDate() =
try { dateFormat.parse(this)!!.time } catch (_: Exception) { 0L }

private fun String.md5(): String {
// Base64.NO_WRAP avoids HTTP error in header encoding on special characters (\n,\r, etc)
return Base64.encodeToString(this.toByteArray(Charsets.UTF_8), Base64.NO_WRAP)
}

companion object {
const val CDN_URL = "https://usc1.contabostorage.com/23b45111d96c42c18a678c1d8cba7123:cdn"
const val OLDI_URL = "https://oldi.sussytoons.site"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class MangaDto(
@SerialName("obr_nome")
val name: String,
@SerialName("obr_slug")
val slug: String,
val slug: String?,
@SerialName("status")
val status: MangaStatus,
) {
Expand Down
Loading