latisbooks: add text pages for accompanying text (#11102)
Not all pages have accompanying text, but it's nice to be able to see the text when there is some. Examples are `No Comic (03/14/22)` and `Meidri (Interspecies Reviewers)` This is done in a nearly identical way to the xkcd source's alt-text pages, with nearly identical code. Also handle the extremely rare case where there are multiple images for the same page. The only instance I can recall is `Page 23+24`
This commit is contained in:
parent
158aceb1fd
commit
dd2bb6cd82
|
@ -5,7 +5,7 @@ ext {
|
|||
extName = 'Latis Books'
|
||||
pkgNameSuffix = 'en.latisbooks'
|
||||
extClass = '.Latisbooks'
|
||||
extVersionCode = 2
|
||||
extVersionCode = 3
|
||||
isNsfw = true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.kanade.tachiyomi.extension.en.latisbooks
|
||||
|
||||
import android.net.Uri.encode
|
||||
import eu.kanade.tachiyomi.network.GET
|
||||
import eu.kanade.tachiyomi.network.asObservableSuccess
|
||||
import eu.kanade.tachiyomi.source.model.FilterList
|
||||
|
@ -27,6 +28,10 @@ class Latisbooks : HttpSource() {
|
|||
|
||||
override val client: OkHttpClient = network.cloudflareClient
|
||||
|
||||
private val textToImageURL = "https://fakeimg.pl/1500x2126/ffffff/000000/?font=museo&font_size=42"
|
||||
|
||||
private fun String.image() = textToImageURL + "&text=" + encode(this)
|
||||
|
||||
private fun createManga(response: Response): SManga {
|
||||
return SManga.create().apply {
|
||||
initialized = true
|
||||
|
@ -97,15 +102,45 @@ class Latisbooks : HttpSource() {
|
|||
|
||||
// Pages
|
||||
|
||||
override fun fetchPageList(chapter: SChapter): Observable<List<Page>> {
|
||||
return Observable.just(listOf(Page(0, chapter.url)))
|
||||
// Adapted from the xkcd source's wordWrap function
|
||||
private fun wordWrap(text: String) = buildString {
|
||||
var charCount = 0
|
||||
text.replace("\r\n", " ").split(' ').forEach { w ->
|
||||
if (charCount > 25) {
|
||||
append("\n")
|
||||
charCount = 0
|
||||
}
|
||||
append(w).append(' ')
|
||||
charCount += w.length + 1
|
||||
}
|
||||
}
|
||||
|
||||
override fun pageListParse(response: Response): List<Page> = throw UnsupportedOperationException("Not used")
|
||||
override fun pageListRequest(chapter: SChapter): Request = GET(chapter.url, headers)
|
||||
|
||||
override fun imageUrlParse(response: Response): String {
|
||||
return response.asJsoup().select("div.content-wrapper img.thumb-image").attr("abs:data-src")
|
||||
override fun pageListParse(response: Response): List<Page> {
|
||||
val blocks = response.asJsoup().select("div.content-wrapper div.row div.col")
|
||||
|
||||
// Handle multiple images per page (e.g. Page 23+24)
|
||||
val pages = blocks.select("img.thumb-image")
|
||||
.mapIndexed { i, it -> Page(i, it.attr("abs:data-src")) }
|
||||
.toMutableList()
|
||||
|
||||
val numImages = pages.size
|
||||
|
||||
// Add text above/below the image as xkcd-esque text pages after the image itself
|
||||
pages.addAll(
|
||||
blocks.select("div.html-block")
|
||||
.map { it.select("div.sqs-block-content").first() }
|
||||
// Some pages have empty html blocks (e.g. Page 1), so ignore them
|
||||
.filter { it.childrenSize() > 0 }
|
||||
.mapIndexed { i, it -> Page(i + numImages, wordWrap(it.text()).image()) }
|
||||
.toList()
|
||||
)
|
||||
|
||||
return pages.toList()
|
||||
}
|
||||
|
||||
override fun imageUrlParse(response: Response): String = throw UnsupportedOperationException("Not used")
|
||||
|
||||
override fun getFilterList() = FilterList()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue