Skip to content

Commit

Permalink
allow for configuring chapter image quality
Browse files Browse the repository at this point in the history
  • Loading branch information
Kladki committed Jan 18, 2025
1 parent 622ccfe commit 759d1e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,6 @@ abstract class Webtoons(

// TODO: Motion
override fun pageListParse(response: Response): List<Page> {
// TODO: configuration for image quality
// set by 'type' query parameter, with values q40, q50, q60, q70, q80, q90
// in ascending quality. In the default returned path, it is set to q70
// The official Webtoon app only makes q40 (Low) and q70 (High) available
return if (response.isCanvas()) {
response
.get<ChallengeEpisodeInfoResponse>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.extension.all.webtoons

import android.app.Application
import android.content.SharedPreferences
import androidx.preference.ListPreference
import androidx.preference.PreferenceScreen
import androidx.preference.SwitchPreferenceCompat
import eu.kanade.tachiyomi.lib.textinterceptor.TextInterceptor
Expand All @@ -11,6 +12,7 @@ import eu.kanade.tachiyomi.multisrc.webtoons.EpisodeInfoResponse
import eu.kanade.tachiyomi.multisrc.webtoons.Webtoons
import eu.kanade.tachiyomi.source.ConfigurableSource
import eu.kanade.tachiyomi.source.model.Page
import okhttp3.HttpUrl.Companion.toHttpUrl
import okhttp3.OkHttpClient
import okhttp3.Response
import uy.kohesive.injekt.Injekt
Expand Down Expand Up @@ -45,12 +47,41 @@ open class WebtoonsSrc(
}
}
screen.addPreference(authorsNotesPref)

// Page image quality is set by 'type' query parameter, with values q40, q50, q60, q70, q80, q90
// in ascending quality. In the default returned path, it is set to q70 The official Webtoon app
// only makes q40 (Low) and q70 (High) available
val imageQualityPref = ListPreference(screen.context).apply {
key = CHAPTER_IMAGE_QUALITY_KEY
title = "Chapter image quality"
entries = arrayOf("Lowest", "Lower", "TODO: Name this? (or the former one)", "Default", "Higher", "Highest")
setDefaultValue(DEFAULT_CHAPTER_IMAGE_QUALITY)
entryValues = arrayOf("q40", "q50", "q60", "q70", "q80", "q90")
summary = "%s"

setOnPreferenceChangeListener { _, newValue ->
val selected = newValue as String
val index = findIndexOfValue(selected)
val entry = entryValues[index] as String

preferences.edit()
.putString(CHAPTER_IMAGE_QUALITY_KEY, entry)
.commit()
}
}
screen.addPreference(imageQualityPref)
}

private fun showAuthorsNotesPref() = preferences.getBoolean(SHOW_AUTHORS_NOTES_KEY, false)
private fun pageImageQualityPref() =
preferences.getString(CHAPTER_IMAGE_QUALITY_KEY, DEFAULT_CHAPTER_IMAGE_QUALITY)

override fun pageListParse(response: Response): List<Page> {
var pages = super.pageListParse(response)
var pages = super.pageListParse(response).map {
it.apply {
imageUrl = imageUrl?.toHttpUrl()?.newBuilder()?.setQueryParameter("type", pageImageQualityPref())?.build().toString()
}
}

if (showAuthorsNotesPref()) {
if (response.isCanvas()) {
Expand Down Expand Up @@ -83,5 +114,7 @@ open class WebtoonsSrc(

companion object {
private const val SHOW_AUTHORS_NOTES_KEY = "showAuthorsNotes"
private const val CHAPTER_IMAGE_QUALITY_KEY = "imageQuality"
private const val DEFAULT_CHAPTER_IMAGE_QUALITY = "q70"
}
}

0 comments on commit 759d1e1

Please sign in to comment.