diff --git a/app/src/main/java/com/hippo/ehviewer/client/DetailUrlParser.java b/app/src/main/java/com/hippo/ehviewer/client/DetailUrlParser.java deleted file mode 100644 index e49fd3496..000000000 --- a/app/src/main/java/com/hippo/ehviewer/client/DetailUrlParser.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2015 Hippo Seven - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hippo.ehviewer.client; - -import com.hippo.yorozuya.AssertUtils; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class DetailUrlParser { - - public int gid; - public String token; - - public void parser(String url) throws Exception { - AssertUtils.assertNotNull("Url is null when parse detail url", url); - - Pattern p = Pattern.compile("/(\\d+)/(\\w+)"); - Matcher m = p.matcher(url); - if (m.find()) { - gid = Integer.parseInt(m.group(1)); - token = m.group(2); - } else { - throw new EhException("Can not parse detail url"); - } - } -} diff --git a/app/src/main/java/com/hippo/ehviewer/client/GalleryDetailParser.java b/app/src/main/java/com/hippo/ehviewer/client/GalleryDetailParser.java index 33c8722b8..b99b29c20 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/GalleryDetailParser.java +++ b/app/src/main/java/com/hippo/ehviewer/client/GalleryDetailParser.java @@ -40,6 +40,45 @@ public class GalleryDetailParser { private static final DateFormat WEB_COMMENT_DATE_FORMAT = new SimpleDateFormat("dd MMMMM yyyy, HH:mm z", Locale.US); private static final DateFormat OUT_COMMENT_DATE_FORMAT = GalleryBase.DEFAULT_DATE_FORMAT; + private static final Pattern ERROR_PATTERN = Pattern.compile("
([^<]+)
"); + private static final Pattern DETAIL_PATTERN = Pattern.compile( + "var gid = (\\d+)" // 1 gid + + ".+?" + + "var token = \"([a-z0-9A]+)\"" // 2 token + + ".+?" + + "([^<]+)
"); - m = p.matcher(body); + m = ERROR_PATTERN.matcher(body); if (m.find()) { throw new EhException(m.group(1)); } @@ -96,36 +134,7 @@ public class GalleryDetailParser { GalleryDetail galleryDetail = new GalleryDetail(); if ((request & REQUEST_DETAIL) != 0) { - p = Pattern.compile("var gid = (\\d+)" // 1 gid - + ".+?" - + "var token = \"([a-z0-9A]+)\"" // 2 token - + ".+?" - + "You are now logged in as: (.+?)
");
+ static final Pattern ERROR_PATTERN = Pattern.compile(
+ "(?:
(.+?)
)" + + "|(?:(.+?))"); + public static String parse(String body) throws Exception { - Pattern p; Matcher m; - p = Pattern.compile("You are now logged in as: (.+?)
");
- m = p.matcher(body);
+ m = NAME_PATTERN.matcher(body);
if (m.find()) {
return m.group(1);
} else {
- p = Pattern.compile("(?:
(.+?)
)" - + "|(?:(.+?))"); - m = p.matcher(body); - + m = ERROR_PATTERN.matcher(body); if (m.find()) { throw new EhException(m.group(1) == null ? m.group(2) : m.group(1)); } else { diff --git a/app/src/main/java/com/hippo/ehviewer/gallery/ImageHandler.java b/app/src/main/java/com/hippo/ehviewer/gallery/ImageHandler.java index cfd62d786..064520166 100644 --- a/app/src/main/java/com/hippo/ehviewer/gallery/ImageHandler.java +++ b/app/src/main/java/com/hippo/ehviewer/gallery/ImageHandler.java @@ -444,6 +444,10 @@ public class ImageHandler { public abstract void onSave(long receivedSize); + public boolean isCancelled() { + return mCancel; + } + public void cancel() { mCancel = true; if (mRequest != null) { diff --git a/app/src/main/java/com/hippo/ehviewer/gallery/SpiderParser.java b/app/src/main/java/com/hippo/ehviewer/gallery/SpiderParser.java index 8076548ee..d76ef543c 100644 --- a/app/src/main/java/com/hippo/ehviewer/gallery/SpiderParser.java +++ b/app/src/main/java/com/hippo/ehviewer/gallery/SpiderParser.java @@ -17,6 +17,7 @@ package com.hippo.ehviewer.gallery; import com.hippo.ehviewer.client.EhConfig; +import com.hippo.ehviewer.client.GalleryDetailParser; import com.hippo.ehviewer.client.ParseException; import com.hippo.ehviewer.client.ParserUtils; @@ -27,6 +28,9 @@ import java.util.regex.Pattern; public class SpiderParser { + private static final Pattern NORMAL_PREVIEW_PATTERN = Pattern.compile("