make timeout longer (#216)

added pagination support for getting chapters
added icon
This commit is contained in:
Carlos 2018-02-26 08:54:03 -05:00 committed by GitHub
parent aada50123e
commit 3f14d851e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 50 additions and 3 deletions

View File

@ -5,8 +5,8 @@ ext {
appName = 'Tachiyomi: MangaDex'
pkgNameSuffix = "all.mangadex"
extClass = '.MangadexFactory'
extVersionCode = 7
extVersionSuffix = 7
extVersionCode = 8
extVersionSuffix = 8
libVersion = '1.2'
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

View File

@ -4,14 +4,17 @@ import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.network.asObservableSuccess
import eu.kanade.tachiyomi.source.model.*
import eu.kanade.tachiyomi.source.online.ParsedHttpSource
import eu.kanade.tachiyomi.util.asJsoup
import okhttp3.HttpUrl
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
import org.jsoup.nodes.Element
import rx.Observable
import java.net.URLEncoder
import java.text.SimpleDateFormat
import java.util.concurrent.TimeUnit
open class Mangadex(override val lang: String, private val internalLang: String, val pageStart: Int) : ParsedHttpSource() {
@ -24,6 +27,8 @@ open class Mangadex(override val lang: String, private val internalLang: String,
override val client = clientBuilder(ALL)
private fun clientBuilder(r18Toggle: Int): OkHttpClient = network.cloudflareClient.newBuilder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.addNetworkInterceptor { chain ->
val newReq = chain
.request()
@ -86,6 +91,9 @@ open class Mangadex(override val lang: String, private val internalLang: String,
override fun searchMangaNextPageSelector() = ".pagination li:not(.disabled) span[title*=last page]:not(disabled)"
private fun mangaNextPageSelector() = ".pagination li:not(.disabled) span[title*=last page]:not(disabled)"
override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable<MangasPage> {
return getSearchClient(filters).newCall(searchMangaRequest(page, query, filters))
.asObservableSuccess()
@ -155,7 +163,8 @@ open class Mangadex(override val lang: String, private val internalLang: String,
val manga = SManga.create()
val infoElement = document.select(".row.edit").first()
val genreElement = infoElement.select("tr:eq(3) td .genre")
// val mangaUrl = document.select(".pagination a").first()
//manga.url = mangaUrl.attr("href")
manga.author = infoElement.select("tr:eq(1) td").first()?.text()
manga.artist = infoElement.select("tr:eq(2) td").first()?.text()
manga.status = parseStatus(infoElement.select("tr:eq(5) td").first()?.text())
@ -173,6 +182,44 @@ open class Mangadex(override val lang: String, private val internalLang: String,
override fun chapterListSelector() = ".table.table-striped.table-hover.table-condensed tbody tr:has(img[src*=$internalLang])"
private fun pagedChapterListRequest(url: String, page: Int): Request {
var pageUrl = url + "/" + ((page * 100))
return GET(pageUrl, headers)
}
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
return client.newCall(chapterListRequest(manga))
.asObservableSuccess()
.map { response ->
chapterListParse(response)
}
}
override fun chapterListParse(response: Response): List<SChapter> {
var document = response.asJsoup()
val baseUri = baseUrl + document.select("li.paging a").first()?.attr("href")?.substringBeforeLast("/")
var page = 1
val chapters = mutableListOf<SChapter>()
do {
document.select(chapterListSelector()).forEach {
chapters.add(chapterFromElement(it))
}
val nextPage = hasNextPage(document)
if (nextPage) {
var resp = client.newCall(pagedChapterListRequest(baseUri, page)).execute()
document = resp.asJsoup()
page++
}
} while (nextPage)
return chapters
}
private fun hasNextPage(document: Document) = document.select(mangaNextPageSelector()).isNotEmpty()
override fun chapterFromElement(element: Element): SChapter {
val urlElement = element.select("td:eq(0)").first()
val dateElement = element.select("td:eq(5)").first()