Skip to content

Commit

Permalink
Load all chapters for Dynasty Doujins (#139)
Browse files Browse the repository at this point in the history
* Added next page to all

Copied implementation from `Chapters` to all other extensions. New pages load when scrolling now

* Update DynastyDoujins.kt

Circumvent `IndexOutOfBoundsException` when section has no chapters

* Update build.gradle

* Moved functionality to base class

* Update DynastyDoujins.kt

Lazy implementation to load all chapters for `Dynasty Doujins`

* Update build.gradle

* Update src/en/dynasty/src/eu/kanade/tachiyomi/extension/en/dynasty/DynastyDoujins.kt

Co-authored-by: stevenyomi <[email protected]>

* Fix exceeding max retry behavior

* Remove retry logic

* Update DynastyDoujins.kt

---------

Co-authored-by: stevenyomi <[email protected]>
  • Loading branch information
2 people authored and cuong-tran committed Jan 14, 2024
1 parent 50fef6b commit 0433e76
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/en/dynasty/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ext {
extName = 'Dynasty'
pkgNameSuffix = 'en.dynasty'
extClass = '.DynastyFactory'
extVersionCode = 22
extVersionCode = 23
}

apply from: "$rootDir/common.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ class DynastyDoujins : DynastyScans() {

override fun chapterListSelector() = "div#main > dl.chapter-list > dd"

private fun doujinChapterParse(document: Document): List<SChapter> {
return try {
document.select(chapterListSelector()).map { chapterFromElement(it) }
} catch (e: IndexOutOfBoundsException) {
emptyList()
}
}

override fun chapterListParse(response: Response): List<SChapter> {
val document = response.asJsoup()

val chapters = try { document.select(chapterListSelector()).map { chapterFromElement(it) }.toMutableList() } catch (e: IndexOutOfBoundsException) { mutableListOf() }
val chapters = mutableListOf<SChapter>()
var page = 1

document.select("a.thumbnail img").let { images ->
if (images.isNotEmpty()) {
Expand All @@ -64,7 +72,34 @@ class DynastyDoujins : DynastyScans() {
)
}
}
chapters.addAll(doujinChapterParse(document))

var hasNextPage = popularMangaNextPageSelector().let { selector ->
document.select(selector).first()
} != null

while (hasNextPage) {
page += 1
val doujinURL = document.location() + "?page=$page"

val newRequest = GET(doujinURL, headers)
val newResponse = client.newCall(newRequest).execute()

if (!newResponse.isSuccessful) {
/*
TODO: Toast to notify chapter parsing aborted.
Add possible retry logic.
*/
return chapters
}

val newDocument = newResponse.asJsoup()
chapters.addAll(doujinChapterParse(newDocument))

hasNextPage = popularMangaNextPageSelector().let { selector ->
newDocument.select(selector).first()
} != null
}
return chapters
}

Expand Down

0 comments on commit 0433e76

Please sign in to comment.