Keep compatibility with YAML sources. Reorder methods
This commit is contained in:
parent
0b3dda18d3
commit
6d0689fe6c
6 changed files with 103 additions and 107 deletions
|
@ -54,7 +54,7 @@ abstract class OnlineSource(context: Context) : Source {
|
|||
abstract val lang: Language
|
||||
|
||||
/**
|
||||
* If the Source has Support for Latest Updates
|
||||
* Whether the source has support for latest updates.
|
||||
*/
|
||||
abstract val supportsLatest : Boolean
|
||||
|
||||
|
@ -101,17 +101,6 @@ abstract class OnlineSource(context: Context) : Source {
|
|||
page
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an observable containing a page with a list of latest manga.
|
||||
*/
|
||||
open fun fetchLatestUpdates(page: MangasPage): Observable<MangasPage> = client
|
||||
.newCall(latestUpdatesRequest(page))
|
||||
.asObservable()
|
||||
.map { response ->
|
||||
latestUpdatesParse(response, page)
|
||||
page
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request for the popular manga given the page. Override only if it's needed to
|
||||
* send different headers or request method like POST.
|
||||
|
@ -125,26 +114,11 @@ abstract class OnlineSource(context: Context) : Source {
|
|||
return GET(page.url, headers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request for latest manga given the page.
|
||||
*/
|
||||
open protected fun latestUpdatesRequest(page: MangasPage): Request {
|
||||
if (page.page == 1) {
|
||||
page.url = latestUpdatesInitialUrl()
|
||||
}
|
||||
return GET(page.url, headers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute url of the first page to popular manga.
|
||||
*/
|
||||
abstract protected fun popularMangaInitialUrl(): String
|
||||
|
||||
/**
|
||||
* Returns the absolute url of the first page to latest manga.
|
||||
*/
|
||||
abstract protected fun latestUpdatesInitialUrl(): String
|
||||
|
||||
/**
|
||||
* Parse the response from the site. It should add a list of manga and the absolute url to the
|
||||
* next page (if it has a next one) to [page].
|
||||
|
@ -154,11 +128,6 @@ abstract class OnlineSource(context: Context) : Source {
|
|||
*/
|
||||
abstract protected fun popularMangaParse(response: Response, page: MangasPage)
|
||||
|
||||
/**
|
||||
* Same as [popularMangaParse], but for latest manga.
|
||||
*/
|
||||
abstract protected fun latestUpdatesParse(response: Response, page: MangasPage)
|
||||
|
||||
/**
|
||||
* Returns an observable containing a page with a list of manga. Normally it's not needed to
|
||||
* override this method.
|
||||
|
@ -206,6 +175,37 @@ abstract class OnlineSource(context: Context) : Source {
|
|||
*/
|
||||
abstract protected fun searchMangaParse(response: Response, page: MangasPage, query: String, filters: List<Filter>)
|
||||
|
||||
/**
|
||||
* Returns an observable containing a page with a list of latest manga.
|
||||
*/
|
||||
open fun fetchLatestUpdates(page: MangasPage): Observable<MangasPage> = client
|
||||
.newCall(latestUpdatesRequest(page))
|
||||
.asObservable()
|
||||
.map { response ->
|
||||
latestUpdatesParse(response, page)
|
||||
page
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the request for latest manga given the page.
|
||||
*/
|
||||
open protected fun latestUpdatesRequest(page: MangasPage): Request {
|
||||
if (page.page == 1) {
|
||||
page.url = latestUpdatesInitialUrl()
|
||||
}
|
||||
return GET(page.url, headers)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the absolute url of the first page to latest manga.
|
||||
*/
|
||||
abstract protected fun latestUpdatesInitialUrl(): String
|
||||
|
||||
/**
|
||||
* Same as [popularMangaParse], but for latest manga.
|
||||
*/
|
||||
abstract protected fun latestUpdatesParse(response: Response, page: MangasPage)
|
||||
|
||||
/**
|
||||
* Returns an observable with the updated details for a manga. Normally it's not needed to
|
||||
* override this method.
|
||||
|
|
|
@ -37,33 +37,11 @@ abstract class ParsedOnlineSource(context: Context) : OnlineSource(context) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the response from the site for latest updates and fills [page].
|
||||
*/
|
||||
override fun latestUpdatesParse(response: Response, page: MangasPage) {
|
||||
val document = response.asJsoup()
|
||||
for (element in document.select(latestUpdatesSelector())) {
|
||||
Manga.create(id).apply {
|
||||
latestUpdatesFromElement(element, this)
|
||||
page.mangas.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
latestUpdatesNextPageSelector()?.let { selector ->
|
||||
page.nextPageUrl = document.select(selector).first()?.absUrl("href")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Jsoup selector that returns a list of [Element] corresponding to each manga.
|
||||
*/
|
||||
abstract protected fun popularMangaSelector(): String
|
||||
|
||||
/**
|
||||
* Returns the Jsoup selector similar to [popularMangaSelector], but for latest updates.
|
||||
*/
|
||||
abstract protected fun latestUpdatesSelector(): String
|
||||
|
||||
/**
|
||||
* Fills [manga] with the given [element]. Most sites only show the title and the url, it's
|
||||
* totally safe to fill only those two values.
|
||||
|
@ -73,22 +51,12 @@ abstract class ParsedOnlineSource(context: Context) : OnlineSource(context) {
|
|||
*/
|
||||
abstract protected fun popularMangaFromElement(element: Element, manga: Manga)
|
||||
|
||||
/**
|
||||
* Fills [manga] with the given [element]. For latest updates.
|
||||
*/
|
||||
abstract protected fun latestUpdatesFromElement(element: Element, manga: Manga)
|
||||
|
||||
/**
|
||||
* Returns the Jsoup selector that returns the <a> tag linking to the next page, or null if
|
||||
* there's no next page.
|
||||
*/
|
||||
abstract protected fun popularMangaNextPageSelector(): String?
|
||||
|
||||
/**
|
||||
* Returns the Jsoup selector that returns the <a> tag, like [popularMangaNextPageSelector].
|
||||
*/
|
||||
abstract protected fun latestUpdatesNextPageSelector(): String?
|
||||
|
||||
/**
|
||||
* Parse the response from the site and fills [page].
|
||||
*
|
||||
|
@ -130,6 +98,38 @@ abstract class ParsedOnlineSource(context: Context) : OnlineSource(context) {
|
|||
*/
|
||||
abstract protected fun searchMangaNextPageSelector(): String?
|
||||
|
||||
/**
|
||||
* Parse the response from the site for latest updates and fills [page].
|
||||
*/
|
||||
override fun latestUpdatesParse(response: Response, page: MangasPage) {
|
||||
val document = response.asJsoup()
|
||||
for (element in document.select(latestUpdatesSelector())) {
|
||||
Manga.create(id).apply {
|
||||
latestUpdatesFromElement(element, this)
|
||||
page.mangas.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
latestUpdatesNextPageSelector()?.let { selector ->
|
||||
page.nextPageUrl = document.select(selector).first()?.absUrl("href")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Jsoup selector similar to [popularMangaSelector], but for latest updates.
|
||||
*/
|
||||
abstract protected fun latestUpdatesSelector(): String
|
||||
|
||||
/**
|
||||
* Fills [manga] with the given [element]. For latest updates.
|
||||
*/
|
||||
abstract protected fun latestUpdatesFromElement(element: Element, manga: Manga)
|
||||
|
||||
/**
|
||||
* Returns the Jsoup selector that returns the <a> tag, like [popularMangaNextPageSelector].
|
||||
*/
|
||||
abstract protected fun latestUpdatesNextPageSelector(): String?
|
||||
|
||||
/**
|
||||
* Parse the response from the site and fills the details of [manga].
|
||||
*
|
||||
|
|
|
@ -5,7 +5,6 @@ import eu.kanade.tachiyomi.data.database.models.Chapter
|
|||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.network.GET
|
||||
import eu.kanade.tachiyomi.data.network.POST
|
||||
import eu.kanade.tachiyomi.data.source.Source
|
||||
import eu.kanade.tachiyomi.data.source.getLanguages
|
||||
import eu.kanade.tachiyomi.data.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.data.source.model.Page
|
||||
|
@ -15,7 +14,6 @@ import okhttp3.Request
|
|||
import okhttp3.Response
|
||||
import org.jsoup.Jsoup
|
||||
import org.jsoup.nodes.Element
|
||||
import rx.Observable
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
|
||||
|
@ -34,7 +32,7 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
|
|||
getLanguages().find { code == it.code }!!
|
||||
}
|
||||
|
||||
override val supportsLatest = map.supportsLatest.toBoolean()
|
||||
override val supportsLatest = map.latestupdates != null
|
||||
|
||||
override val client = when(map.client) {
|
||||
"cloudflare" -> network.cloudflareClient
|
||||
|
@ -55,20 +53,8 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
|
|||
}
|
||||
}
|
||||
|
||||
override fun latestUpdatesRequest(page: MangasPage): Request {
|
||||
if (page.page == 1) {
|
||||
page.url = latestUpdatesInitialUrl()
|
||||
}
|
||||
return when (map.latestupdates.method?.toLowerCase()) {
|
||||
"post" -> POST(page.url, headers, map.latestupdates.createForm())
|
||||
else -> GET(page.url, headers)
|
||||
}
|
||||
}
|
||||
|
||||
override fun popularMangaInitialUrl() = map.popular.url
|
||||
|
||||
override fun latestUpdatesInitialUrl() = map.latestupdates.url
|
||||
|
||||
override fun popularMangaParse(response: Response, page: MangasPage) {
|
||||
val document = response.asJsoup()
|
||||
for (element in document.select(map.popular.manga_css)) {
|
||||
|
@ -84,21 +70,6 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
|
|||
}
|
||||
}
|
||||
|
||||
override fun latestUpdatesParse(response: Response, page: MangasPage) {
|
||||
val document = response.asJsoup()
|
||||
for (element in document.select(map.latestupdates.manga_css)) {
|
||||
Manga.create(id).apply {
|
||||
title = element.text()
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
page.mangas.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
map.popular.next_url_css?.let { selector ->
|
||||
page.nextPageUrl = document.select(selector).first()?.absUrl("href")
|
||||
}
|
||||
}
|
||||
|
||||
override fun searchMangaRequest(page: MangasPage, query: String, filters: List<Filter>): Request {
|
||||
if (page.page == 1) {
|
||||
page.url = searchMangaInitialUrl(query, filters)
|
||||
|
@ -126,6 +97,33 @@ class YamlOnlineSource(context: Context, mappings: Map<*, *>) : OnlineSource(con
|
|||
}
|
||||
}
|
||||
|
||||
override fun latestUpdatesRequest(page: MangasPage): Request {
|
||||
if (page.page == 1) {
|
||||
page.url = latestUpdatesInitialUrl()
|
||||
}
|
||||
return when (map.latestupdates!!.method?.toLowerCase()) {
|
||||
"post" -> POST(page.url, headers, map.latestupdates.createForm())
|
||||
else -> GET(page.url, headers)
|
||||
}
|
||||
}
|
||||
|
||||
override fun latestUpdatesInitialUrl() = map.latestupdates!!.url
|
||||
|
||||
override fun latestUpdatesParse(response: Response, page: MangasPage) {
|
||||
val document = response.asJsoup()
|
||||
for (element in document.select(map.latestupdates!!.manga_css)) {
|
||||
Manga.create(id).apply {
|
||||
title = element.text()
|
||||
setUrlWithoutDomain(element.attr("href"))
|
||||
page.mangas.add(this)
|
||||
}
|
||||
}
|
||||
|
||||
map.latestupdates.next_url_css?.let { selector ->
|
||||
page.nextPageUrl = document.select(selector).first()?.absUrl("href")
|
||||
}
|
||||
}
|
||||
|
||||
override fun mangaDetailsParse(response: Response, manga: Manga) {
|
||||
val document = response.asJsoup()
|
||||
with(map.manga) {
|
||||
|
|
|
@ -25,14 +25,12 @@ class YamlSourceNode(uncheckedMap: Map<*, *>) {
|
|||
|
||||
val lang: String by map
|
||||
|
||||
val supportsLatest: String by map
|
||||
|
||||
val client: String?
|
||||
get() = map["client"] as? String
|
||||
|
||||
val popular = PopularNode(toMap(map["popular"])!!)
|
||||
|
||||
val latestupdates = LatestUpdatesNode(toMap(map["latest_updates"])!!)
|
||||
val latestupdates = toMap(map["latest_updates"])?.let { LatestUpdatesNode(it) }
|
||||
|
||||
val search = SearchNode(toMap(map["search"])!!)
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,2C6.5,2 2,6.5 2,12s4.5,10 10,10 10,-4.5 10,-10S17.5,2 12,2zM16.2,16.2L11,13L11,7h1.5v5.2l4.5,2.7 -0.8,1.3z"/>
|
||||
</vector>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,2C6.5,2 2,6.5 2,12s4.5,10 10,10 10,-4.5 10,-10S17.5,2 12,2zM16.2,16.2L11,13L11,7h1.5v5.2l4.5,2.7 -0.8,1.3z"/>
|
||||
</vector>
|
|
@ -21,7 +21,7 @@
|
|||
android:title="@string/label_catalogues" />
|
||||
<item
|
||||
android:id="@+id/nav_drawer_latest_updates"
|
||||
android:icon="@drawable/ic_watch_later"
|
||||
android:icon="@drawable/ic_watch_later_black_24dp"
|
||||
android:title="@string/label_latest_updates" />
|
||||
<item
|
||||
android:id="@+id/nav_drawer_downloads"
|
||||
|
|
Reference in a new issue