From 34201bece1a837ddae62774032d33cb16b653c2e Mon Sep 17 00:00:00 2001 From: inorichi Date: Sat, 28 Nov 2015 20:02:30 +0100 Subject: [PATCH] Support Batoto webtoons --- .../mangafeed/data/source/base/Source.java | 4 +- .../data/source/online/english/Batoto.java | 38 +++++++++++++++++-- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java index fd139584f0..3e25bcf872 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/base/Source.java @@ -159,7 +159,7 @@ public abstract class Source extends BaseSource { mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages); } - private List convertToPages(List pageUrls) { + protected List convertToPages(List pageUrls) { List pages = new ArrayList<>(); for (int i = 0; i < pageUrls.size(); i++) { pages.add(new Page(i, pageUrls.get(i))); @@ -167,7 +167,7 @@ public abstract class Source extends BaseSource { return pages; } - private List getFirstImageFromPageUrls(List pageUrls, String unparsedHtml) { + protected List getFirstImageFromPageUrls(List pageUrls, String unparsedHtml) { List pages = convertToPages(pageUrls); String firstImage = parseHtmlToImageUrl(unparsedHtml); pages.get(0).setImageUrl(firstImage); diff --git a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java index 45e849c18d..55a4cea447 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/source/online/english/Batoto.java @@ -21,11 +21,12 @@ import java.util.Date; import java.util.List; import java.util.Locale; -import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.database.models.Chapter; import eu.kanade.mangafeed.data.database.models.Manga; +import eu.kanade.mangafeed.data.source.SourceManager; import eu.kanade.mangafeed.data.source.base.Source; import eu.kanade.mangafeed.data.source.model.MangasPage; +import eu.kanade.mangafeed.data.source.model.Page; import rx.Observable; public class Batoto extends Source { @@ -348,14 +349,43 @@ public class Batoto extends Source { List pageUrlList = new ArrayList<>(); - Elements pageUrlElements = parsedDocument.getElementById("page_select").getElementsByTag("option"); - for (Element pageUrlElement : pageUrlElements) { - pageUrlList.add(pageUrlElement.attr("value")); + Element selectElement = parsedDocument.select("#page_select").first(); + + if (selectElement != null) { + for (Element pageUrlElement : selectElement.select("option")) { + pageUrlList.add(pageUrlElement.attr("value")); + } + } else { + // For webtoons in one page + Element page = parsedDocument.select("div > a").first(); + String url = page.attr("href"); + url = BASE_URL + "/reader" + url.substring(0, url.length() - 1) + "f"; + + for (int i = 0; i < parsedDocument.select("div > img").size(); i++) { + pageUrlList.add(url); + } } return pageUrlList; } + @Override + protected List getFirstImageFromPageUrls(List pageUrls, String unparsedHtml) { + List pages = convertToPages(pageUrls); + if (!unparsedHtml.contains("Want to see this chapter per page instead?")) { + String firstImage = parseHtmlToImageUrl(unparsedHtml); + pages.get(0).setImageUrl(firstImage); + } else { + // For webtoons in one page + Document parsedDocument = Jsoup.parse(unparsedHtml); + Elements imageUrls = parsedDocument.select("div > img"); + for (int i = 0; i < pages.size(); i++) { + pages.get(i).setImageUrl(imageUrls.get(i).attr("src")); + } + } + return pages; + } + @Override protected String parseHtmlToImageUrl(String unparsedHtml) { int beginIndex = unparsedHtml.indexOf("