handle interactive xkcd comics (#6474)

* handle interactive xkcd comics

Some xkcd comics tend to be interactive and can only be played in a regular browser
These cannot be loaded in the app and the reader loads indefinitely
Instead, we throw a text image with a message to open in browser

the div#comic img attribute will be null/empty in case of parsing interactive
comics and is then replaced with an image warning

uses fakeimagepl to generate image from text

closes https://github.com/tachiyomiorg/tachiyomi-extensions/issues/6370

* update build.gradle version code for xkcd
This commit is contained in:
curche 2021-04-08 18:24:05 +05:30 committed by GitHub
parent 0741c20a9f
commit e2a7cf1013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -5,7 +5,7 @@ ext {
extName = 'xkcd'
pkgNameSuffix = 'en.xkcd'
extClass = '.Xkcd'
extVersionCode = 8
extVersionCode = 9
libVersion = '1.2'
}

View File

@ -59,12 +59,22 @@ class Xkcd : ParsedHttpSource() {
override fun pageListParse(document: Document): List<Page> {
val titleWords: Sequence<String>
val altTextWords: Sequence<String>
val interactiveText = listOf(
"To experience the", "interactive version of this comic,",
"open it in WebView/browser."
)
.joinToString(separator = "%0A")
.replace(" ", "%20")
// transforming filename from info.0.json isn't guaranteed to work, stick to html
// if an HD image is available it'll be the srcset attribute
// if img tag is empty then it is an interactive comic viewable only in browser
val image = document.select("div#comic img").let {
if (it.hasAttr("srcset")) it.attr("abs:srcset").substringBefore(" ")
else it.attr("abs:src")
when {
it == null || it.isEmpty() -> baseAltTextUrl + interactiveText + baseAltTextPostUrl
it.hasAttr("srcset") -> it.attr("abs:srcset").substringBefore(" ")
else -> it.attr("abs:src")
}
}
// create a text image for the alt text