diff --git a/library/src/main/java/eu/kanade/tachiyomi/source/CatalogueSource.kt b/library/src/main/java/eu/kanade/tachiyomi/source/CatalogueSource.kt index c906f58..9168294 100644 --- a/library/src/main/java/eu/kanade/tachiyomi/source/CatalogueSource.kt +++ b/library/src/main/java/eu/kanade/tachiyomi/source/CatalogueSource.kt @@ -3,7 +3,6 @@ package eu.kanade.tachiyomi.source import eu.kanade.tachiyomi.source.model.FilterList import eu.kanade.tachiyomi.source.model.MangasPage import eu.kanade.tachiyomi.source.model.SManga -import rx.Observable @Suppress("unused") interface CatalogueSource : Source { @@ -19,27 +18,30 @@ interface CatalogueSource : Source { val supportsLatest: Boolean /** - * Returns an observable containing a page with a list of manga. + * Get a page with a list of manga. * + * @since extensions-lib 1.5 * @param page the page number to retrieve. */ - fun fetchPopularManga(page: Int): Observable + suspend fun getPopularManga(page: Int): MangasPage /** - * Returns an observable containing a page with a list of manga. + * Get a page with a list of manga. * + * @since extensions-lib 1.5 * @param page the page number to retrieve. * @param query the search query. * @param filters the list of filters to apply. */ - fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable + suspend fun getSearchManga(page: Int, query: String, filters: FilterList): MangasPage /** - * Returns an observable containing a page with a list of latest manga updates. + * Get a page with a list of latest manga updates. * + * @since extensions-lib 1.5 * @param page the page number to retrieve. */ - fun fetchLatestUpdates(page: Int): Observable + suspend fun getLatestUpdates(page: Int): MangasPage /** * Returns the list of filters for the source. @@ -106,8 +108,7 @@ interface CatalogueSource : Source { * @return the related mangas for the current manga. * @throws UnsupportedOperationException if a source doesn't support related mangas. */ - suspend fun fetchRelatedMangaList(manga: SManga): List = - throw Exception("Stub!") + suspend fun fetchRelatedMangaList(manga: SManga): List = throw UnsupportedOperationException("Unsupported!") /** * Slit & strip manga's title into separate searchable keywords. diff --git a/library/src/main/java/eu/kanade/tachiyomi/source/Source.kt b/library/src/main/java/eu/kanade/tachiyomi/source/Source.kt index 7fec00c..881a619 100644 --- a/library/src/main/java/eu/kanade/tachiyomi/source/Source.kt +++ b/library/src/main/java/eu/kanade/tachiyomi/source/Source.kt @@ -3,16 +3,14 @@ package eu.kanade.tachiyomi.source import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.SChapter import eu.kanade.tachiyomi.source.model.SManga -import rx.Observable /** * A basic interface for creating a source. It could be an online source, a local source, etc... */ -@Suppress("unused") interface Source { /** - * Id for the source. Must be unique. + * ID for the source. Must be unique. */ val id: Long @@ -28,7 +26,7 @@ interface Source { * @param manga the manga to update. * @return the updated manga. */ - suspend fun getMangaDetails(manga: SManga): SManga = throw Exception("Stub!") + suspend fun getMangaDetails(manga: SManga): SManga /** * Get all the available chapters for a manga. @@ -37,7 +35,17 @@ interface Source { * @param manga the manga to update. * @return the chapters for the manga. */ - suspend fun getChapterList(manga: SManga): List = throw Exception("Stub!") + suspend fun getChapterList(manga: SManga): List + + /** + * Get the list of pages a chapter has. Pages should be returned + * in the expected order; the index is ignored. + * + * @since komikku/extensions-lib 1.7 + * @param chapter the chapter. + * @return the pages for the chapter. + */ + suspend fun getPageList(chapter: SChapter): List // KMK --> /** @@ -51,27 +59,6 @@ interface Source { manga: SManga, exceptionHandler: (Throwable) -> Unit, pushResults: suspend (relatedManga: Pair>, completed: Boolean) -> Unit, - ): Unit = throw Exception("Stub!") - // KMK <-- - - /** - * Get the list of pages a chapter has. Pages should be returned - * in the expected order; the index is ignored. - * - * @param chapter the chapter. - * @return the pages for the chapter. - */ - fun fetchPageList(chapter: SChapter): Observable> - - @Deprecated( - "Use the non-RxJava API instead", - ReplaceWith("getMangaDetails"), ) - fun fetchMangaDetails(manga: SManga): Observable = throw Exception("Stub!") - - @Deprecated( - "Use the non-RxJava API instead", - ReplaceWith("getChapterList"), - ) - fun fetchChapterList(manga: SManga): Observable> = throw Exception("Stub!") + // KMK <-- } \ No newline at end of file diff --git a/library/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt b/library/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt index 6122909..4466f60 100644 --- a/library/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/library/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -12,7 +12,7 @@ import rx.Observable /** * A simple implementation for sources from a website. */ -@Suppress("unused", "unused_parameter") +@Suppress("unused", "UnusedReceiverParameter", "UNUSED_PARAMETER") abstract class HttpSource : CatalogueSource { /** @@ -32,10 +32,16 @@ abstract class HttpSource : CatalogueSource { open val versionId: Int = throw Exception("Stub!") /** - * Id of the source. By default it uses a generated id using the first 16 characters (64 bits) - * of the MD5 of the string: sourcename/language/versionId - * Note the generated id sets the sign bit to 0. + * ID of the source. By default it uses a generated id using the first 16 characters (64 bits) + * of the MD5 of the string `"${name.lowercase()}/$lang/$versionId"`. + * + * The ID is generated by the [generateId] function, which can be reused if needed + * to generate outdated IDs for cases where the source name or language needs to + * be changed but migrations can be avoided. + * + * Note: the generated ID sets the sign bit to `0`. */ + @Suppress("KDocUnresolvedReference") override val id: Long = throw Exception("Stub!") /** @@ -51,24 +57,34 @@ abstract class HttpSource : CatalogueSource { /** * Headers builder for requests. Implementations can override this method for custom headers. */ - open protected fun headersBuilder(): Headers.Builder { + protected open fun headersBuilder(): Headers.Builder { throw Exception("Stub!") } /** * Visible name of the source. */ - override fun toString(): String { + override fun toString() = throw Exception("Stub!") + + /** + * Get a page with a list of manga. + * Normally it's not needed to override this method. + * + * @since extensions-lib 1.5 + * @param page the page number to retrieve. + */ + override suspend fun getPopularManga(page: Int): MangasPage { throw Exception("Stub!") } /** - * Returns an observable containing a page with a list of manga. Normally it's not needed to - * override this method. + * Returns an observable containing a page with a list of manga. + * Normally it's not needed to override this method. * * @param page the page number to retrieve. */ - override fun fetchPopularManga(page: Int): Observable { + @Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getPopularManga(page)")) + open fun fetchPopularManga(page: Int): Observable { throw Exception("Stub!") } @@ -87,14 +103,32 @@ abstract class HttpSource : CatalogueSource { protected abstract fun popularMangaParse(response: Response): MangasPage /** - * Returns an observable containing a page with a list of manga. Normally it's not needed to - * override this method. + * Get a page with a list of manga. + * Normally it's not needed to override this method. * + * @since extensions-lib 1.5 * @param page the page number to retrieve. * @param query the search query. * @param filters the list of filters to apply. */ - override fun fetchSearchManga(page: Int, query: String, filters: FilterList): Observable { + override suspend fun getSearchManga(page: Int, query: String, filters: FilterList): MangasPage { + throw Exception("Stub!") + } + + /** + * Returns an observable containing a page with a list of manga. + * Normally it's not needed to override this method. + * + * @param page the page number to retrieve. + * @param query the search query. + * @param filters the list of filters to apply. + */ + @Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getSearchManga(page, query, filters)")) + open fun fetchSearchManga( + page: Int, + query: String, + filters: FilterList, + ): Observable { throw Exception("Stub!") } @@ -105,7 +139,11 @@ abstract class HttpSource : CatalogueSource { * @param query the search query. * @param filters the list of filters to apply. */ - protected abstract fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request + protected abstract fun searchMangaRequest( + page: Int, + query: String, + filters: FilterList, + ): Request /** * Parses the response from the site and returns a [MangasPage] object. @@ -114,12 +152,25 @@ abstract class HttpSource : CatalogueSource { */ protected abstract fun searchMangaParse(response: Response): MangasPage + /** + * Get a page with a list of latest manga updates. + * Normally it's not needed to override this method. + * + * @since extensions-lib 1.5 + * @param page the page number to retrieve. + */ + override suspend fun getLatestUpdates(page: Int): MangasPage { + throw Exception("Stub!") + } + /** * Returns an observable containing a page with a list of latest manga updates. + * Normally it's not needed to override this method. * * @param page the page number to retrieve. */ - override fun fetchLatestUpdates(page: Int): Observable { + @Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getLatestUpdates(page)")) + open fun fetchLatestUpdates(page: Int): Observable { throw Exception("Stub!") } @@ -138,18 +189,32 @@ abstract class HttpSource : CatalogueSource { protected abstract fun latestUpdatesParse(response: Response): MangasPage /** - * Returns an observable with the updated details for a manga. Normally it's not needed to - * override this method. + * Get the updated details for a manga. + * Normally it's not needed to override this method. + * + * @since extensions-lib 1.4 + * @param manga the manga to update. + * @return the updated manga. + */ + override suspend fun getMangaDetails(manga: SManga): SManga { + throw Exception("Stub!") + } + + /** + * Returns an observable with the updated details for a manga. + * Normally it's not needed to override this method. * * @param manga the manga to be updated. */ - override fun fetchMangaDetails(manga: SManga): Observable { + @Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getMangaDetails(manga)")) + open fun fetchMangaDetails(manga: SManga): Observable { throw Exception("Stub!") } /** * Returns the request for the details of a manga. Override only if it's needed to change the * url, send different headers or request method like POST. + * Normally it's not needed to override this method. * * @param manga the manga to be updated. */ @@ -167,6 +232,7 @@ abstract class HttpSource : CatalogueSource { // KMK --> /** * Whether parsing related mangas in manga page or extension provide custom related mangas request. + * * @default true * @since komikku/extensions-lib 1.6 */ @@ -188,7 +254,7 @@ abstract class HttpSource : CatalogueSource { /** * Returns the request for get related manga list. Override only if it's needed to override * the url, send different headers or request method like POST. - * If using this, must also: 'override val supportsRelatedMangas = true' + * Normally it's not needed to override this method. * * @since komikku/extensions-lib 1.6 * @param manga the manga to look for related mangas. @@ -199,7 +265,6 @@ abstract class HttpSource : CatalogueSource { /** * Parses the response from the site and returns a list of related mangas. - * If using this, must also: 'override val supportsRelatedMangas = true' * * @since komikku/extensions-lib 1.6 * @param response the response from the site. @@ -208,22 +273,37 @@ abstract class HttpSource : CatalogueSource { // KMK <-- /** - * Returns an observable with the updated chapter list for a manga. Normally it's not needed to - * override this method. + * Get all the available chapters for a manga. + * Normally it's not needed to override this method. + * + * @param manga the manga to update. + * @return the chapters for the manga. + * @throws LicensedMangaChaptersException if a manga is licensed and therefore no chapters are available. + */ + @Suppress("KDocUnresolvedReference") + override suspend fun getChapterList(manga: SManga): List { + throw Exception("Stub!") + } + + /** + * Returns an observable with the updated chapter list for a manga. + * Normally it's not needed to override this method. * * @param manga the manga to look for chapters. */ - override fun fetchChapterList(manga: SManga): Observable> { + @Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getChapterList(manga)")) + open fun fetchChapterList(manga: SManga): Observable> { throw Exception("Stub!") } /** * Returns the request for updating the chapter list. Override only if it's needed to override * the url, send different headers or request method like POST. + * Normally it's not needed to override this method. * * @param manga the manga to look for chapters. */ - open protected fun chapterListRequest(manga: SManga): Request { + protected open fun chapterListRequest(manga: SManga): Request { throw Exception("Stub!") } @@ -234,22 +314,44 @@ abstract class HttpSource : CatalogueSource { */ protected abstract fun chapterListParse(response: Response): List + /** + * Parses the response from the site and returns a SChapter Object. + * + * @param response the response from the site. + */ + protected open fun chapterPageParse(response: Response): SChapter = throw UnsupportedOperationException("Not used!") + + /** + * Get the list of pages a chapter has. Pages should be returned + * in the expected order; the index is ignored. + * Normally it's not needed to override this method. + * + * @param chapter the chapter. + * @return the pages for the chapter. + */ + override suspend fun getPageList(chapter: SChapter): List { + throw Exception("Stub!") + } + /** * Returns an observable with the page list for a chapter. + * Normally it's not needed to override this method. * * @param chapter the chapter whose page list has to be fetched. */ - override fun fetchPageList(chapter: SChapter): Observable> { + @Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getPageList(chapter)")) + open fun fetchPageList(chapter: SChapter): Observable> { throw Exception("Stub!") } /** * Returns the request for getting the page list. Override only if it's needed to override the * url, send different headers or request method like POST. + * Normally it's not needed to override this method. * * @param chapter the chapter whose page list has to be fetched. */ - open protected fun pageListRequest(chapter: SChapter): Request { + protected open fun pageListRequest(chapter: SChapter): Request { throw Exception("Stub!") } @@ -260,12 +362,25 @@ abstract class HttpSource : CatalogueSource { */ protected abstract fun pageListParse(response: Response): List + /** + * Returns the source url of the image. + * Normally it's not needed to override this method. + * + * @since extensions-lib 1.5 + * @param page the page whose source image has to be fetched. + */ + open suspend fun getImageUrl(page: Page): String { + throw Exception("Stub!") + } + /** * Returns an observable with the page containing the source url of the image. If there's any * error, it will return null instead of throwing an exception. + * Normally it's not needed to override this method. * * @param page the page whose source image has to be fetched. */ + @Deprecated("Use the non-RxJava API instead", replaceWith = ReplaceWith("getImageUrl(page)")) open fun fetchImageUrl(page: Page): Observable { throw Exception("Stub!") } @@ -273,10 +388,11 @@ abstract class HttpSource : CatalogueSource { /** * Returns the request for getting the url to the source image. Override only if it's needed to * override the url, send different headers or request method like POST. + * Normally it's not needed to override this method. * * @param page the chapter whose page list has to be fetched */ - open protected fun imageUrlRequest(page: Page): Request { + protected open fun imageUrlRequest(page: Page): Request { throw Exception("Stub!") } @@ -288,27 +404,31 @@ abstract class HttpSource : CatalogueSource { protected abstract fun imageUrlParse(response: Response): String /** - * Returns an observable with the response of the source image. + * Returns the response of the source image. + * Normally it's not needed to override this method. * + * @since extensions-lib 1.5 * @param page the page whose source image has to be downloaded. */ - fun fetchImage(page: Page): Observable { + protected open suspend fun getImage(page: Page): Response { throw Exception("Stub!") } /** * Returns the request for getting the source image. Override only if it's needed to override * the url, send different headers or request method like POST. + * Normally it's not needed to override this method. * * @param page the chapter whose page list has to be fetched */ - open protected fun imageRequest(page: Page): Request { + protected open fun imageRequest(page: Page): Request { throw Exception("Stub!") } /** * Assigns the url of the chapter without the scheme and domain. It saves some redundancy from * database and the urls could still work after a domain change. + * Normally it's not needed to override this method. * * @param url the full url to the chapter. */ @@ -319,6 +439,7 @@ abstract class HttpSource : CatalogueSource { /** * Assigns the url of the manga without the scheme and domain. It saves some redundancy from * database and the urls could still work after a domain change. + * Normally it's not needed to override this method. * * @param url the full url to the manga. */ @@ -328,15 +449,17 @@ abstract class HttpSource : CatalogueSource { /** * Returns the url of the given string without the scheme and domain. + * Normally it's not needed to override this method. * * @param orig the full url. */ private fun getUrlWithoutDomain(orig: String): String { throw Exception("Stub!") } - + /** - * Returns the url of the provided manga + * Returns the url of the provided manga. + * Normally it's not needed to override this method. * * @since extensions-lib 1.4 * @param manga the manga @@ -347,7 +470,8 @@ abstract class HttpSource : CatalogueSource { } /** - * Returns the url of the provided chapter + * Returns the url of the provided chapter. + * Normally it's not needed to override this method. * * @since extensions-lib 1.4 * @param chapter the chapter diff --git a/library/src/main/java/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt b/library/src/main/java/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt index 3a1867d..f758abf 100644 --- a/library/src/main/java/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt +++ b/library/src/main/java/eu/kanade/tachiyomi/source/online/ParsedHttpSource.kt @@ -16,6 +16,7 @@ abstract class ParsedHttpSource : HttpSource() { /** * Parses the response from the site and returns a [MangasPage] object. + * Normally it's not needed to override this method. * * @param response the response from the site. */ @@ -44,6 +45,7 @@ abstract class ParsedHttpSource : HttpSource() { /** * Parses the response from the site and returns a [MangasPage] object. + * Normally it's not needed to override this method. * * @param response the response from the site. */ @@ -72,6 +74,7 @@ abstract class ParsedHttpSource : HttpSource() { /** * Parses the response from the site and returns a [MangasPage] object. + * Normally it's not needed to override this method. * * @param response the response from the site. */ @@ -100,6 +103,7 @@ abstract class ParsedHttpSource : HttpSource() { /** * Parses the response from the site and returns the details of a manga. + * Normally it's not needed to override this method. * * @param response the response from the site. */ @@ -117,7 +121,7 @@ abstract class ParsedHttpSource : HttpSource() { // KMK --> /** * Parses the response from the site and returns a list of related mangas. - * If using this, must also: 'override val supportsRelatedMangas = true' + * Normally it's not needed to override this method. * * @since komikku/extensions-lib 1.6 * @param response the response from the site. @@ -128,7 +132,6 @@ abstract class ParsedHttpSource : HttpSource() { /** * Returns the Jsoup selector that returns a list of [Element] corresponding to each related mangas. - * If using this, must also: 'override val supportsRelatedMangas = true' * * @since komikku/extensions-lib 1.6 */ @@ -136,7 +139,6 @@ abstract class ParsedHttpSource : HttpSource() { /** * Returns a manga from the given element. - * If using this, must also: 'override val supportsRelatedMangas = true' * * @since komikku/extensions-lib 1.6 * @param element an element obtained from [relatedMangaListSelector]. @@ -146,6 +148,7 @@ abstract class ParsedHttpSource : HttpSource() { /** * Parses the response from the site and returns a list of chapters. + * Normally it's not needed to override this method. * * @param response the response from the site. */ @@ -167,6 +170,7 @@ abstract class ParsedHttpSource : HttpSource() { /** * Parses the response from the site and returns the page list. + * Normally it's not needed to override this method. * * @param response the response from the site. */ @@ -183,6 +187,7 @@ abstract class ParsedHttpSource : HttpSource() { /** * Parse the response from the site and returns the absolute url to the source image. + * Normally it's not needed to override this method. * * @param response the response from the site. */