diff --git a/src/pt/goldenmangas/build.gradle b/src/pt/goldenmangas/build.gradle index efe9ead20..0d40aad50 100644 --- a/src/pt/goldenmangas/build.gradle +++ b/src/pt/goldenmangas/build.gradle @@ -5,7 +5,7 @@ ext { extName = 'Golden Mangás' pkgNameSuffix = 'pt.goldenmangas' extClass = '.GoldenMangas' - extVersionCode = 6 + extVersionCode = 7 libVersion = '1.2' } diff --git a/src/pt/goldenmangas/src/eu/kanade/tachiyomi/extension/pt/goldenmangas/GoldenMangas.kt b/src/pt/goldenmangas/src/eu/kanade/tachiyomi/extension/pt/goldenmangas/GoldenMangas.kt index 7bd6cbcdc..bfa42eba3 100644 --- a/src/pt/goldenmangas/src/eu/kanade/tachiyomi/extension/pt/goldenmangas/GoldenMangas.kt +++ b/src/pt/goldenmangas/src/eu/kanade/tachiyomi/extension/pt/goldenmangas/GoldenMangas.kt @@ -6,6 +6,7 @@ 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.online.ParsedHttpSource +import eu.kanade.tachiyomi.util.asJsoup import java.text.ParseException import java.text.SimpleDateFormat import java.util.Locale @@ -14,6 +15,7 @@ import okhttp3.Headers import okhttp3.HttpUrl import okhttp3.OkHttpClient import okhttp3.Request +import okhttp3.Response import org.jsoup.nodes.Document import org.jsoup.nodes.Element @@ -45,12 +47,15 @@ class GoldenMangas : ParsedHttpSource() { override fun popularMangaRequest(page: Int): Request = GET(baseUrl, headers) - override fun popularMangaSelector(): String = "div#maisLidos div.itemmanga" + override fun popularMangaSelector(): String = + "div.section:contains(Mais Lídos) + div.section div.manga_item div.andro_product-thumb a" override fun popularMangaFromElement(element: Element): SManga = SManga.create().apply { - title = element.select("h3").first().text().withoutLanguage() - thumbnail_url = element.select("img").first()?.attr("abs:src") - url = element.attr("href") + title = element.select("img").attr("alt") + .substringAfter("online ") + .withoutLanguage() + thumbnail_url = element.select("img").attr("abs:data-src") + url = "/" + element.attr("href") } override fun popularMangaNextPageSelector(): String? = null @@ -60,81 +65,106 @@ class GoldenMangas : ParsedHttpSource() { return GET("$baseUrl$path", headers) } - override fun latestUpdatesSelector() = "div.col-sm-12.atualizacao > div.row" + override fun latestUpdatesSelector() = "div.row.atualizacoes div.manga_item div.andro_product" override fun latestUpdatesFromElement(element: Element): SManga = SManga.create().apply { - val infoElement = element.select("div.col-sm-10.col-xs-8 h3").first() - val thumb = element.select("a:first-child div img").first().attr("abs:src") + val titleElement = element.select("h5.andro_product-title > a") - title = infoElement.text().withoutLanguage() - thumbnail_url = thumb.replace("w=80&h=120", "w=380&h=600") - url = element.select("a:first-child").attr("href") + title = titleElement.text().withoutLanguage() + thumbnail_url = element.select("div.andro_product-thumb img").attr("abs:src") + url = "/" + titleElement.attr("href") } - override fun latestUpdatesNextPageSelector() = "ul.pagination li:last-child a" + override fun latestUpdatesNextPageSelector() = "ul.pagination li.active + li" override fun searchMangaRequest(page: Int, query: String, filters: FilterList): Request { val newHeaders = headers.newBuilder() .set("Referer", "$baseUrl/mangas") .build() - val url = HttpUrl.parse("$baseUrl/mangabr")!!.newBuilder() + val url = HttpUrl.parse("$baseUrl/manga")!!.newBuilder() .addQueryParameter("busca", query) + .toString() - return GET(url.toString(), newHeaders) + return GET(url, newHeaders) } - override fun searchMangaSelector() = "div.mangas.col-lg-2 a" + override fun searchMangaSelector() = "div.container div.row:contains(Resultados) div.andro_product" override fun searchMangaFromElement(element: Element): SManga = SManga.create().apply { - title = element.select("h3").first().text().withoutLanguage() - thumbnail_url = element.select("img").first().attr("abs:src") - url = element.attr("href") + val titleElement = element.select("p.andro_product-title a") + + title = titleElement.text().withoutLanguage() + thumbnail_url = element.select("div.andro_product-thumb img").attr("abs:data-src") + url = "/" + titleElement.attr("href") } - override fun searchMangaNextPageSelector() = "ul.pagination li:last-child a" + override fun searchMangaNextPageSelector(): String? = null override fun mangaDetailsParse(document: Document): SManga = SManga.create().apply { - val infoElement = document.select("div.row > div.col-sm-8 > div.row").first() - val firstColumn = infoElement.select("div.col-sm-4.text-right > img").first() - val secondColumn = infoElement.select("div.col-sm-8").first() + val infoElement = document.select("div.andro_subheader + div.section div.row").first() + val firstColumn = infoElement.select("div.col-md-3 div.andro_product-single-thumb > img").first() + val secondColumn = infoElement.select("div.col-md-9 div.andro_product-single-content").first() + val metadata = secondColumn.select("div.row:eq(2) ul.andro_product-meta").first() - title = secondColumn.select("h2:eq(0)").text().withoutLanguage() - author = secondColumn.select("h5:eq(3)")!!.text().withoutLabel() - artist = secondColumn.select("h5:eq(4)")!!.text().withoutLabel() - genre = secondColumn.select("h5:eq(2) a") - .filter { it.text().isNotEmpty() } - .joinToString { it.text() } - status = parseStatus(secondColumn.select("h5:eq(5) a").text().orEmpty()) - description = document.select("#manga_capitulo_descricao").text() + title = secondColumn.select("div.row:eq(0) h3").text().withoutLanguage() + author = metadata.select("li:eq(1) div a").text().trim() + artist = metadata.select("li:eq(2) div a").text().trim() + genre = metadata.select("li:eq(0) div a").joinToString { it.text() } + status = metadata.select("li:eq(3) div a").text().toStatus() + description = secondColumn.select("div.row:eq(3) p").text().trim() thumbnail_url = firstColumn.attr("abs:src") } - private fun parseStatus(status: String) = when { - status.contains("Ativo") -> SManga.ONGOING - status.contains("Completo") -> SManga.COMPLETED - else -> SManga.UNKNOWN + /** + * Need to override the method to get the API endpoint URL that + * uses the manga id to return the chapter list. + */ + override fun chapterListParse(response: Response): List { + val chapterScript = response.asJsoup() + .select("script:containsData(capitulos_cache.php)") + .first() + val chapterEndpointUrl = chapterScript.data() + .substringAfter("url: \"") + .substringBefore("\"") + + val chapterListHeaders = headersBuilder() + .set("Accept", "*/*") + .set("Referer", response.request().url().toString()) + .set("X-Requested-With", "XMLHttpRequest") + .build() + + val chapterRequest = GET("$baseUrl/$chapterEndpointUrl", chapterListHeaders) + val chapterResponse = client.newCall(chapterRequest).execute() + + return super.chapterListParse(chapterResponse) } - override fun chapterListSelector() = "ul#capitulos li.row" + override fun chapterListSelector() = "div.andro_single-pagination-item div.row" override fun chapterFromElement(element: Element): SChapter = SChapter.create().apply { - val firstColumn = element.select("a > div.col-sm-5") - val secondColumn = element.select("div.col-sm-5.text-right a[href^='http']") + val firstColumn = element.select("div.col-sm-7").first() + val secondColumn = element.select("div.col-sm-5 a") - name = firstColumn.select("div.col-sm-5").first().text() - .substringBefore("(").trim() - scanlator = secondColumn?.joinToString { it.text() } - date_upload = DATE_FORMATTER.tryParseTime(firstColumn.select("div.col-sm-5 span[style]").first().text()) - url = element.select("a").first().attr("href") + name = firstColumn.select("b").first().text() + scanlator = secondColumn.joinToString { it.text() } + date_upload = firstColumn.select("span[style]").last().text().toDate() + url = "/" + firstColumn.select("a").attr("href") + } + + override fun pageListRequest(chapter: SChapter): Request { + val newHeaders = headersBuilder() + .set("Referer", baseUrl + chapter.url.substringBeforeLast("/")) + .build() + + return GET(baseUrl + chapter.url, newHeaders) } override fun pageListParse(document: Document): List { - val chapterUrl = document.location() - val chapterImages = document.select("div.col-sm-12[id^='capitulos_images']").first() - - return chapterImages.select("img[pag]") - .mapIndexed { i, element -> Page(i, chapterUrl, element.attr("abs:src")) } + return document.select("div.container_images_img img.img-responsive") + .mapIndexed { i, element -> + Page(i, document.location(), element.attr("abs:src")) + } } override fun imageUrlParse(document: Document) = "" @@ -148,23 +178,26 @@ class GoldenMangas : ParsedHttpSource() { return GET(page.imageUrl!!, newHeaders) } - private fun String.withoutLanguage(): String = replace(FLAG_REGEX, "").trim() - - private fun String.withoutLabel(): String = substringAfter(":").trim() - - private fun SimpleDateFormat.tryParseTime(date: String): Long { + private fun String.toDate(): Long { return try { - parse(date)!!.time + DATE_FORMATTER.parse(this.trim())?.time ?: 0L } catch (e: ParseException) { 0L } } + private fun String.toStatus() = when { + contains("Ativo") -> SManga.ONGOING + contains("Completo") -> SManga.COMPLETED + else -> SManga.UNKNOWN + } + private fun String.withoutLanguage(): String = replace(FLAG_REGEX, "").trim() + companion object { private const val ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9" private const val ACCEPT_IMAGE = "image/webp,image/apng,image/*,*/*;q=0.8" private const val ACCEPT_LANGUAGE = "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7,es;q=0.6,gl;q=0.5" - private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36" + private const val USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36" private val FLAG_REGEX = "\\((Pt[-/]br|Scan)\\)".toRegex(RegexOption.IGNORE_CASE)