Fix batoto parser

This commit is contained in:
inorichi 2015-10-25 00:08:15 +02:00
parent c7e9016ad7
commit e857a44987
2 changed files with 28 additions and 2 deletions

View file

@ -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<Manga> parseMangasFromHtml(String unparsedHtml) {
if (unparsedHtml.contains("No (more) comics found!")) {
return new ArrayList<>();

View file

@ -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<String> pageUrls = parseHtmlToPageUrls(unparsedHtml);
return Observable.just(getFirstImageFromPageUrls(pageUrls, unparsedHtml));
@ -119,7 +129,7 @@ public abstract class Source {
private Observable<Page> 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);