From 56a45f263e7e1fd81bc7bdf67e90d079705d5f49 Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 12 Feb 2016 15:38:16 +0100 Subject: [PATCH] Strip html tags from batoto notice and directly throw an exception --- .../eu/kanade/tachiyomi/data/source/base/Source.java | 7 +------ .../tachiyomi/data/source/online/english/Batoto.java | 12 +++++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java b/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java index 4550c70b2c..417d60bd13 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/base/Source.java @@ -34,8 +34,6 @@ public abstract class Source extends BaseSource { protected Headers requestHeaders; protected LazyHeaders glideHeaders; - protected String lastError; - public Source() {} public Source(Context context) { @@ -90,7 +88,7 @@ public abstract class Source extends BaseSource { List chapters = parseHtmlToChapters(unparsedHtml); return !chapters.isEmpty() ? Observable.just(chapters) : - Observable.error(new Exception((getLastError().equals("")) ? "No chapters found" : getLastError())); + Observable.error(new Exception("No chapters found")); }); } @@ -218,7 +216,4 @@ public abstract class Source extends BaseSource { return glideHeaders; } - public String getLastError() { - return lastError; - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.java b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.java index 3766654690..827cab0899 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.java +++ b/app/src/main/java/eu/kanade/tachiyomi/data/source/online/english/Batoto.java @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.source.online.english; import android.content.Context; import android.net.Uri; +import android.text.Html; import android.text.TextUtils; import org.jsoup.Jsoup; @@ -24,7 +25,6 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import eu.kanade.tachiyomi.R; import eu.kanade.tachiyomi.data.database.models.Chapter; import eu.kanade.tachiyomi.data.database.models.Manga; import eu.kanade.tachiyomi.data.source.SourceManager; @@ -32,7 +32,6 @@ import eu.kanade.tachiyomi.data.source.base.LoginSource; import eu.kanade.tachiyomi.data.source.model.MangasPage; import eu.kanade.tachiyomi.data.source.model.Page; import eu.kanade.tachiyomi.util.Parser; -import eu.kanade.tachiyomi.util.ToastUtil; import okhttp3.FormBody; import okhttp3.Headers; import okhttp3.Response; @@ -49,7 +48,7 @@ public class Batoto extends LoginSource { public static final String MANGA_URL = "/comic_pop?id=%s"; public static final String LOGIN_URL = BASE_URL + "/forums/index.php?app=core&module=global§ion=login"; - public static final Pattern staffNotice = Pattern.compile("=+Batoto Staff Notice=+([^=]+)=+", Pattern.CASE_INSENSITIVE); + public static final Pattern staffNotice = Pattern.compile("=+Batoto Staff Notice=+([^=]+)==+", Pattern.CASE_INSENSITIVE); private Pattern datePattern; private Map dateFields; @@ -210,9 +209,8 @@ public class Batoto extends LoginSource { protected List parseHtmlToChapters(String unparsedHtml) { Matcher matcher = staffNotice.matcher(unparsedHtml); if (matcher.find()) { - this.lastError = matcher.group(1); - } else { - lastError = ""; + String notice = Html.fromHtml(matcher.group(1)).toString().trim(); + throw new RuntimeException(notice); } Document parsedDocument = Jsoup.parse(unparsedHtml); @@ -245,6 +243,7 @@ public class Batoto extends LoginSource { return chapter; } + @SuppressWarnings("WrongConstant") private long parseDateFromElement(Element dateElement) { String dateAsString = dateElement.text(); @@ -260,7 +259,6 @@ public class Batoto extends LoginSource { String unit = m.group(2); Calendar cal = Calendar.getInstance(); - // Not an error cal.add(dateFields.get(unit), -amount); date = cal.getTime(); } else {