mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-05 00:28:56 +01:00
Consume and extend 1.x Source API
TODO: make the rest of the app actually call the 1.x functions
This commit is contained in:
@@ -9,7 +9,7 @@ interface CatalogueSource : Source {
|
||||
/**
|
||||
* An ISO 639-1 compliant language code (two letters in lower case).
|
||||
*/
|
||||
val lang: String
|
||||
override val lang: String
|
||||
|
||||
/**
|
||||
* Whether the source has support for latest updates.
|
||||
|
||||
@@ -5,30 +5,42 @@ import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import eu.kanade.tachiyomi.source.model.toChapterInfo
|
||||
import eu.kanade.tachiyomi.source.model.toMangaInfo
|
||||
import eu.kanade.tachiyomi.source.model.toPageInfo
|
||||
import eu.kanade.tachiyomi.source.model.toSChapter
|
||||
import eu.kanade.tachiyomi.source.model.toSManga
|
||||
import eu.kanade.tachiyomi.util.lang.awaitSingle
|
||||
import rx.Observable
|
||||
import tachiyomi.source.model.ChapterInfo
|
||||
import tachiyomi.source.model.MangaInfo
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
/**
|
||||
* A basic interface for creating a source. It could be an online source, a local source, etc...
|
||||
*/
|
||||
interface Source {
|
||||
interface Source : tachiyomi.source.Source {
|
||||
|
||||
/**
|
||||
* Id for the source. Must be unique.
|
||||
*/
|
||||
val id: Long
|
||||
override val id: Long
|
||||
|
||||
/**
|
||||
* Name of the source.
|
||||
*/
|
||||
val name: String
|
||||
override val name: String
|
||||
|
||||
override val lang: String
|
||||
get() = ""
|
||||
|
||||
/**
|
||||
* Returns an observable with the updated details for a manga.
|
||||
*
|
||||
* @param manga the manga to update.
|
||||
*/
|
||||
@Deprecated("Use getMangaDetails instead")
|
||||
fun fetchMangaDetails(manga: SManga): Observable<SManga>
|
||||
|
||||
/**
|
||||
@@ -36,6 +48,7 @@ interface Source {
|
||||
*
|
||||
* @param manga the manga to update.
|
||||
*/
|
||||
@Deprecated("Use getChapterList instead")
|
||||
fun fetchChapterList(manga: SManga): Observable<List<SChapter>>
|
||||
|
||||
/**
|
||||
@@ -43,7 +56,32 @@ interface Source {
|
||||
*
|
||||
* @param chapter the chapter.
|
||||
*/
|
||||
@Deprecated("Use getPageList instead")
|
||||
fun fetchPageList(chapter: SChapter): Observable<List<Page>>
|
||||
|
||||
/**
|
||||
* [1.x API] Get the updated details for a manga.
|
||||
*/
|
||||
override suspend fun getMangaDetails(manga: MangaInfo): MangaInfo {
|
||||
return fetchMangaDetails(manga.toSManga()).awaitSingle()
|
||||
.toMangaInfo()
|
||||
}
|
||||
|
||||
/**
|
||||
* [1.x API] Get all the available chapters for a manga.
|
||||
*/
|
||||
override suspend fun getChapterList(manga: MangaInfo): List<ChapterInfo> {
|
||||
return fetchChapterList(manga.toSManga()).awaitSingle()
|
||||
.map { it.toChapterInfo() }
|
||||
}
|
||||
|
||||
/**
|
||||
* [1.x API] Get the list of pages a chapter has.
|
||||
*/
|
||||
override suspend fun getPageList(chapter: ChapterInfo): List<tachiyomi.source.model.Page> {
|
||||
return fetchPageList(chapter.toSChapter()).awaitSingle()
|
||||
.map { it.toPageInfo() }
|
||||
}
|
||||
}
|
||||
|
||||
fun Source.icon(): Drawable? = Injekt.get<ExtensionManager>().getAppIconForSource(this)
|
||||
|
||||
@@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.source.model
|
||||
import android.net.Uri
|
||||
import eu.kanade.tachiyomi.network.ProgressListener
|
||||
import rx.subjects.Subject
|
||||
import tachiyomi.source.model.PageUrl
|
||||
|
||||
open class Page(
|
||||
val index: Int,
|
||||
@@ -61,3 +62,9 @@ open class Page(
|
||||
const val ERROR = 4
|
||||
}
|
||||
}
|
||||
|
||||
fun Page.toPageInfo(): PageUrl {
|
||||
return PageUrl(
|
||||
url = this.imageUrl ?: this.url
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.source.model
|
||||
|
||||
import tachiyomi.source.model.ChapterInfo
|
||||
import java.io.Serializable
|
||||
|
||||
interface SChapter : Serializable {
|
||||
@@ -28,3 +29,24 @@ interface SChapter : Serializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun SChapter.toChapterInfo(): ChapterInfo {
|
||||
return ChapterInfo(
|
||||
dateUpload = this.date_upload,
|
||||
key = this.url,
|
||||
name = this.name,
|
||||
number = this.chapter_number,
|
||||
scanlator = this.scanlator ?: ""
|
||||
)
|
||||
}
|
||||
|
||||
fun ChapterInfo.toSChapter(): SChapter {
|
||||
val chapter = this
|
||||
return SChapter.create().apply {
|
||||
url = chapter.key
|
||||
name = chapter.name
|
||||
date_upload = chapter.dateUpload
|
||||
chapter_number = chapter.number
|
||||
scanlator = chapter.scanlator
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package eu.kanade.tachiyomi.source.model
|
||||
|
||||
import tachiyomi.source.model.MangaInfo
|
||||
import java.io.Serializable
|
||||
|
||||
interface SManga : Serializable {
|
||||
@@ -61,3 +62,30 @@ interface SManga : Serializable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun SManga.toMangaInfo(): MangaInfo {
|
||||
return MangaInfo(
|
||||
key = this.url,
|
||||
title = this.title,
|
||||
artist = this.artist ?: "",
|
||||
author = this.author ?: "",
|
||||
description = this.description ?: "",
|
||||
genres = this.genre?.split(", ") ?: emptyList(),
|
||||
status = this.status,
|
||||
cover = this.thumbnail_url ?: ""
|
||||
)
|
||||
}
|
||||
|
||||
fun MangaInfo.toSManga(): SManga {
|
||||
val mangaInfo = this
|
||||
return SManga.create().apply {
|
||||
url = mangaInfo.key
|
||||
title = mangaInfo.title
|
||||
artist = mangaInfo.artist
|
||||
author = mangaInfo.author
|
||||
description = mangaInfo.description
|
||||
genre = mangaInfo.genres.joinToString(", ")
|
||||
status = mangaInfo.status
|
||||
thumbnail_url = mangaInfo.cover
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user