MangaCards update (#1911)

MangaCards update
This commit is contained in:
Mike 2019-12-25 16:57:57 -05:00 committed by arkon
parent 288c35f951
commit 6a703ead9b
2 changed files with 23 additions and 34 deletions

View File

@ -5,7 +5,7 @@ ext {
appName = 'Tachiyomi: MangaCards (Valhalla, NANI?)' appName = 'Tachiyomi: MangaCards (Valhalla, NANI?)'
pkgNameSuffix = 'all.mangacards' pkgNameSuffix = 'all.mangacards'
extClass = '.MangaCardsFactory' extClass = '.MangaCardsFactory'
extVersionCode = 5 extVersionCode = 6
libVersion = '1.2' libVersion = '1.2'
} }

View File

@ -15,6 +15,7 @@ import okhttp3.Request
import okhttp3.Response import okhttp3.Response
import org.jsoup.nodes.Document import org.jsoup.nodes.Document
import org.jsoup.nodes.Element import org.jsoup.nodes.Element
import java.lang.Exception
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Locale import java.util.Locale
@ -31,7 +32,7 @@ abstract class MangaCards(
// Popular // Popular
override fun popularMangaRequest(page: Int): Request { override fun popularMangaRequest(page: Int): Request {
return GET("$baseUrl/projects") return GET("$baseUrl/projects", headers)
} }
override fun popularMangaSelector() = "div.col-sm-4" override fun popularMangaSelector() = "div.col-sm-4"
@ -46,32 +47,20 @@ abstract class MangaCards(
return manga return manga
} }
override fun popularMangaNextPageSelector() = "No next page" override fun popularMangaNextPageSelector(): String? = null
// Latest // Latest
// Track which manga titles have been added to latestUpdates's MangasPage
private val latestUpdatesTitles = mutableSetOf<String>()
override fun latestUpdatesRequest(page: Int): Request { override fun latestUpdatesRequest(page: Int): Request {
if (page == 1) latestUpdatesTitles.clear() return GET(baseUrl, headers)
return GET(baseUrl)
} }
// Only add manga to MangasPage if its title is not one we've added already
override fun latestUpdatesParse(response: Response): MangasPage { override fun latestUpdatesParse(response: Response): MangasPage {
val latestManga = mutableListOf<SManga>() val mangas = response.asJsoup().select(latestUpdatesSelector())
val document = response.asJsoup() .distinctBy { it.select("div.pt-0 a").text() }
.map { latestUpdatesFromElement(it) }
document.select(latestUpdatesSelector()).forEach { element -> return MangasPage(mangas, false)
latestUpdatesFromElement(element).let { manga ->
if (manga.title !in latestUpdatesTitles) {
latestManga.add(manga)
latestUpdatesTitles.add(manga.title)
}
}
}
return MangasPage(latestManga, document.select(latestUpdatesNextPageSelector()).hasText())
} }
override fun latestUpdatesSelector() = "div.col-sm-6" override fun latestUpdatesSelector() = "div.col-sm-6"
@ -86,25 +75,24 @@ abstract class MangaCards(
return manga return manga
} }
override fun latestUpdatesNextPageSelector() = "No next page" override fun latestUpdatesNextPageSelector(): String? = null
// Search // Search
/* Source websites aren't able to search their whole catalog at once, instead we'd have to /* Source websites aren't able to search their whole catalog at once, instead we'd have to
do separate searches for ongoing, hiatus, dropped, and completed and then combine those results. do separate searches for ongoing, hiatus, dropped, and completed and then combine those results.
Since their catalogs are small, it seems easier to do the search client-side */ Since their catalogs are small, it seems easier to do the search client-side */
private var searchQuery = "" private lateinit var searchQuery: String
override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request {
searchQuery = query.toLowerCase() searchQuery = query
return popularMangaRequest(1) return popularMangaRequest(1)
} }
override fun searchMangaParse(response: Response): MangasPage { override fun searchMangaParse(response: Response): MangasPage {
val searchMatches = mutableListOf<SManga>() val searchMatches = response.asJsoup().select(searchMangaSelector())
response.asJsoup().select(searchMangaSelector()) .filter { it.text().contains(searchQuery, ignoreCase = true) }
.filter { it.text().toLowerCase().contains(searchQuery) } .map { searchMangaFromElement(it) }
.map { searchMatches.add(searchMangaFromElement(it)) }
return MangasPage(searchMatches, false) return MangasPage(searchMatches, false)
} }
@ -113,7 +101,7 @@ abstract class MangaCards(
override fun searchMangaFromElement(element: Element) = popularMangaFromElement(element) override fun searchMangaFromElement(element: Element) = popularMangaFromElement(element)
override fun searchMangaNextPageSelector() = popularMangaNextPageSelector() override fun searchMangaNextPageSelector(): String? = null
// Manga details // Manga details
@ -151,7 +139,11 @@ abstract class MangaCards(
} }
private fun parseDate(date: String): Long { private fun parseDate(date: String): Long {
return SimpleDateFormat("dd/MM/yyyy", Locale.US).parse(date).time return try {
SimpleDateFormat("dd/MM/yyyy", Locale.US).parse(date).time
} catch (e: Exception) {
0L
}
} }
override fun pageListRequest(chapter: SChapter): Request { override fun pageListRequest(chapter: SChapter): Request {
@ -162,12 +154,9 @@ abstract class MangaCards(
} }
override fun pageListParse(document: Document): List<Page> { override fun pageListParse(document: Document): List<Page> {
val pages = mutableListOf<Page>() return document.select("div#pages img").mapIndexed { i, element ->
Page(i, "", element.attr("abs:src"))
document.select("div#pages img").forEachIndexed { i, element ->
pages.add(Page(i, "", element.attr("abs:src")))
} }
return pages
} }
override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used") override fun imageUrlParse(document: Document): String = throw UnsupportedOperationException("Not used")