From e857a4498782454492432c48e4685899f74739f1 Mon Sep 17 00:00:00 2001 From: inorichi Date: Sun, 25 Oct 2015 00:08:15 +0200 Subject: [PATCH] Fix batoto parser --- .../java/eu/kanade/mangafeed/sources/Batoto.java | 16 ++++++++++++++++ .../java/eu/kanade/mangafeed/sources/Source.java | 14 ++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java b/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java index 60860cc54..3c591f5e0 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/Batoto.java @@ -28,6 +28,7 @@ public class Batoto extends Source { public static final String INITIAL_UPDATE_URL = "http://bato.to/search_ajax?order_cond=views&order=desc&p="; public static final String INITIAL_SEARCH_URL = "http://bato.to/search_ajax?"; + public static final String INITIAL_PAGE_URL = "http://bato.to/areader?"; public Batoto(NetworkHelper networkService, CacheManager cacheManager) { @@ -43,6 +44,7 @@ public class Batoto extends Source { protected Headers.Builder headersBuilder() { Headers.Builder builder = super.headersBuilder(); builder.add("Cookie", "lang_option=English"); + builder.add("Referer", "http://bato.to/reader"); return builder; } @@ -112,6 +114,20 @@ public class Batoto extends Source { return "http://bato.to/comic_pop?id=" + mangaId; } + @Override + protected String getChapterPageUrl(String defaultPageUrl) { + String id = defaultPageUrl.substring(defaultPageUrl.indexOf("#") + 1); + return INITIAL_PAGE_URL + "id=" + id + "&p=1"; + } + + @Override + protected String getRemainingPagesUrl(String defaultPageUrl) { + int start = defaultPageUrl.indexOf("#") + 1; + int end = defaultPageUrl.indexOf("_", start); + String id = defaultPageUrl.substring(start, end); + return INITIAL_PAGE_URL + "id=" + id + "&p=" + defaultPageUrl.substring(end+1); + } + private List parseMangasFromHtml(String unparsedHtml) { if (unparsedHtml.contains("No (more) comics found!")) { return new ArrayList<>(); diff --git a/app/src/main/java/eu/kanade/mangafeed/sources/Source.java b/app/src/main/java/eu/kanade/mangafeed/sources/Source.java index e41d1d5fb..6e4876654 100644 --- a/app/src/main/java/eu/kanade/mangafeed/sources/Source.java +++ b/app/src/main/java/eu/kanade/mangafeed/sources/Source.java @@ -38,6 +38,16 @@ public abstract class Source { return defaultMangaUrl; } + // Get the URL of the first page that contains a source image and the page list + protected String getChapterPageUrl(String defaultPageUrl) { + return defaultPageUrl; + } + + // Get the URL of the remaining pages that contains source images + protected String getRemainingPagesUrl(String defaultPageUrl) { + return defaultPageUrl; + } + // Default headers, it can be overriden by children or just add new keys protected Headers.Builder headersBuilder() { Headers.Builder builder = new Headers.Builder(); @@ -97,7 +107,7 @@ public abstract class Source { return mCacheManager.getPageUrlsFromDiskCache(chapterUrl) .onErrorResumeNext(throwable -> { return mNetworkService - .getStringResponse(chapterUrl, mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders) + .getStringResponse(getChapterPageUrl(chapterUrl), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders) .flatMap(unparsedHtml -> { List pageUrls = parseHtmlToPageUrls(unparsedHtml); return Observable.just(getFirstImageFromPageUrls(pageUrls, unparsedHtml)); @@ -119,7 +129,7 @@ public abstract class Source { private Observable getImageUrlFromPage(final Page page) { return mNetworkService - .getStringResponse(page.getUrl(), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders) + .getStringResponse(getRemainingPagesUrl(page.getUrl()), mNetworkService.NULL_CACHE_CONTROL, mRequestHeaders) .flatMap(unparsedHtml -> Observable.just(parseHtmlToImageUrl(unparsedHtml))) .flatMap(imageUrl -> { page.setImageUrl(imageUrl);