From 5ae0589547489193826b6205f05711a07ceaa16b Mon Sep 17 00:00:00 2001 From: Carlos Date: Mon, 28 Aug 2017 03:10:19 -0400 Subject: [PATCH] License manga update and Manga Fox Title Update (#937) * update mangafox parsing to read chapter title also if it exists. * updated chapterImpl to force update chapters if chapter name changes. This allows for chapter name changes from the source to update in app * switched from : to - since other sites that already have title use - so it provides consistency across sources. * fixed spacing for - * fixes license status for manga fox if manga is licensed no chapters will be shown. * 1. changed equality in chapterImp back to just the url (removed scanlator, and name comparison) 2. Removed extra line of code assigning mangaFox title twice 3. Modified ChapterSourceSync for scanlator/title/url comparison. * cleaned spaces, added comment, incorporated toChange code from other pull request * throw exception instead of returning empty list when licensed * space fix --- .../tachiyomi/source/online/HttpSource.kt | 19 ++++++++++++------- .../source/online/english/Mangafox.kt | 8 +++++--- .../tachiyomi/util/ChapterSourceSync.kt | 3 ++- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt index 5698a3dfd0..7b57d10c1c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/HttpSource.kt @@ -13,6 +13,7 @@ import okhttp3.Request import okhttp3.Response import rx.Observable import uy.kohesive.injekt.injectLazy +import java.lang.Exception import java.net.URI import java.net.URISyntaxException import java.security.MessageDigest @@ -51,7 +52,7 @@ abstract class HttpSource : CatalogueSource { override val id by lazy { val key = "${name.toLowerCase()}/$lang/$versionId" val bytes = MessageDigest.getInstance("MD5").digest(key.toByteArray()) - (0..7).map { bytes[it].toLong() and 0xff shl 8*(7-it) }.reduce(Long::or) and Long.MAX_VALUE + (0..7).map { bytes[it].toLong() and 0xff shl 8 * (7 - it) }.reduce(Long::or) and Long.MAX_VALUE } /** @@ -197,16 +198,20 @@ abstract class HttpSource : CatalogueSource { /** * Returns an observable with the updated chapter list for a manga. Normally it's not needed to - * override this method. + * override this method. If a manga is licensed an empty chapter list observable is returned * * @param manga the manga to look for chapters. */ override fun fetchChapterList(manga: SManga): Observable> { - return client.newCall(chapterListRequest(manga)) - .asObservableSuccess() - .map { response -> - chapterListParse(response) - } + if (manga.status != SManga.LICENSED) { + return client.newCall(chapterListRequest(manga)) + .asObservableSuccess() + .map { response -> + chapterListParse(response) + } + } else { + return Observable.error(Exception("Licensed - No chapters to show")) + } } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/online/english/Mangafox.kt b/app/src/main/java/eu/kanade/tachiyomi/source/online/english/Mangafox.kt index 4444d9105f..269ab067a1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/online/english/Mangafox.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/online/english/Mangafox.kt @@ -61,7 +61,7 @@ class Mangafox : ParsedHttpSource() { is Status -> url.addQueryParameter(filter.id, filter.state.toString()) is GenreList -> filter.state.forEach { genre -> url.addQueryParameter(genre.id, genre.state.toString()) } is TextField -> url.addQueryParameter(filter.key, filter.state) - is Type -> url.addQueryParameter("type", if(filter.state == 0) "" else filter.state.toString()) + is Type -> url.addQueryParameter("type", if (filter.state == 0) "" else filter.state.toString()) is OrderBy -> { url.addQueryParameter("sort", arrayOf("name", "rating", "views", "total_chapters", "last_chapter_time")[filter.state!!.index]) url.addQueryParameter("order", if (filter.state?.ascending == true) "az" else "za") @@ -89,13 +89,14 @@ class Mangafox : ParsedHttpSource() { val infoElement = document.select("div#title").first() val rowElement = infoElement.select("table > tbody > tr:eq(1)").first() val sideInfoElement = document.select("#series_info").first() + val licensedElement = document.select("div.warning").first() val manga = SManga.create() manga.author = rowElement.select("td:eq(1)").first()?.text() manga.artist = rowElement.select("td:eq(2)").first()?.text() manga.genre = rowElement.select("td:eq(3)").first()?.text() manga.description = infoElement.select("p.summary").first()?.text() - manga.status = sideInfoElement.select(".data").first()?.text().orEmpty().let { parseStatus(it) } + manga.status = licensedElement?.let { SManga.LICENSED } ?: sideInfoElement.select(".data").first()?.text().orEmpty().let { parseStatus(it) } manga.thumbnail_url = sideInfoElement.select("div.cover > img").first()?.attr("src") return manga } @@ -113,7 +114,7 @@ class Mangafox : ParsedHttpSource() { val chapter = SChapter.create() chapter.setUrlWithoutDomain(urlElement.attr("href")) - chapter.name = urlElement.text() + chapter.name = element.select("span.title.nowrap").first()?.text()?.let { urlElement.text() + " - " + it } ?: urlElement.text() chapter.date_upload = element.select("span.date").first()?.text()?.let { parseChapterDate(it) } ?: 0 return chapter } @@ -169,6 +170,7 @@ class Mangafox : ParsedHttpSource() { private class OrderBy : Filter.Sort("Order by", arrayOf("Series name", "Rating", "Views", "Total chapters", "Last chapter"), Filter.Sort.Selection(2, false)) + private class GenreList(genres: List) : Filter.Group("Genres", genres) override fun getFilterList() = FilterList( diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt index 077e83d18b..36252f610c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterSourceSync.kt @@ -20,7 +20,7 @@ import java.util.* fun syncChaptersWithSource(db: DatabaseHelper, rawSourceChapters: List, manga: Manga, - source: Source) : Pair, List> { + source: Source): Pair, List> { if (rawSourceChapters.isEmpty()) { throw Exception("No chapters found") @@ -121,4 +121,5 @@ fun syncChaptersWithSource(db: DatabaseHelper, db.fixChaptersSourceOrder(sourceChapters).executeAsBlocking() } return Pair(toAdd.subtract(readded).toList(), toDelete.subtract(readded).toList()) + }