Support Batoto webtoons

This commit is contained in:
inorichi 2015-11-28 20:02:30 +01:00
parent 5dcaeffa0b
commit 34201bece1
2 changed files with 36 additions and 6 deletions

View File

@ -159,7 +159,7 @@ public abstract class Source extends BaseSource {
mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages); mCacheManager.putPageUrlsToDiskCache(chapterUrl, pages);
} }
private List<Page> convertToPages(List<String> pageUrls) { protected List<Page> convertToPages(List<String> pageUrls) {
List<Page> pages = new ArrayList<>(); List<Page> pages = new ArrayList<>();
for (int i = 0; i < pageUrls.size(); i++) { for (int i = 0; i < pageUrls.size(); i++) {
pages.add(new Page(i, pageUrls.get(i))); pages.add(new Page(i, pageUrls.get(i)));
@ -167,7 +167,7 @@ public abstract class Source extends BaseSource {
return pages; return pages;
} }
private List<Page> getFirstImageFromPageUrls(List<String> pageUrls, String unparsedHtml) { protected List<Page> getFirstImageFromPageUrls(List<String> pageUrls, String unparsedHtml) {
List<Page> pages = convertToPages(pageUrls); List<Page> pages = convertToPages(pageUrls);
String firstImage = parseHtmlToImageUrl(unparsedHtml); String firstImage = parseHtmlToImageUrl(unparsedHtml);
pages.get(0).setImageUrl(firstImage); pages.get(0).setImageUrl(firstImage);

View File

@ -21,11 +21,12 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale; 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.Chapter;
import eu.kanade.mangafeed.data.database.models.Manga; 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.base.Source;
import eu.kanade.mangafeed.data.source.model.MangasPage; import eu.kanade.mangafeed.data.source.model.MangasPage;
import eu.kanade.mangafeed.data.source.model.Page;
import rx.Observable; import rx.Observable;
public class Batoto extends Source { public class Batoto extends Source {
@ -348,14 +349,43 @@ public class Batoto extends Source {
List<String> pageUrlList = new ArrayList<>(); List<String> pageUrlList = new ArrayList<>();
Elements pageUrlElements = parsedDocument.getElementById("page_select").getElementsByTag("option"); Element selectElement = parsedDocument.select("#page_select").first();
for (Element pageUrlElement : pageUrlElements) {
if (selectElement != null) {
for (Element pageUrlElement : selectElement.select("option")) {
pageUrlList.add(pageUrlElement.attr("value")); 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; return pageUrlList;
} }
@Override
protected List<Page> getFirstImageFromPageUrls(List<String> pageUrls, String unparsedHtml) {
List<Page> 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 @Override
protected String parseHtmlToImageUrl(String unparsedHtml) { protected String parseHtmlToImageUrl(String unparsedHtml) {
int beginIndex = unparsedHtml.indexOf("<img id=\"comic_page\""); int beginIndex = unparsedHtml.indexOf("<img id=\"comic_page\"");