\"]+)\">" // rating
+ + ".+?"
+ + "
(.+?)"); // uploader
+ m = p.matcher(pageContext);
+ while (m.find()) {
+ GalleryInfo gi = new GalleryInfo();
+
+ gi.category = EhClient.getType(m.group(1));
+ gi.posted = m.group(2);
+ if (m.group(3) == null) {
+ gi.thumb = "http://"
+ + m.group(5).replace('~', '/');
+ gi.title = StringEscapeUtils.unescapeHtml4(m
+ .group(6));
+ } else {
+ gi.thumb = m.group(3);
+ gi.title = StringEscapeUtils.unescapeHtml4(m
+ .group(4));
+ }
+
+ Pattern pattern = Pattern
+ .compile("/(\\d+)/(\\w+)");
+ Matcher matcher = pattern.matcher(m.group(7));
+ if (matcher.find()) {
+ gi.gid = Integer.parseInt(matcher.group(1));
+ gi.token = matcher.group(2);
+ } else
+ continue;
+
+ gi.rating = Float.parseFloat(getRate(m.group(9)));
+ gi.uploader = m.group(10);
+ giList.add(gi);
+ }
+
+ return ALL;
+ }
+
+ private String getRate(String rawRate) {
+ Pattern p = Pattern.compile("\\d+px");
+ Matcher m = p.matcher(rawRate);
+ int num1;
+ int num2;
+ int rate = 5;
+ String re;
+ if (m.find())
+ num1 = Integer.parseInt(m.group().replace("px", ""));
+ else
+ return null;
+ if (m.find())
+ num2 = Integer.parseInt(m.group().replace("px", ""));
+ else
+ return null;
+ rate = rate - num1 / 16;
+ if (num2 == 21) {
+ rate--;
+ re = Integer.toString(rate);
+ re = re + ".5";
+ } else
+ re = Integer.toString(rate);
+ return re;
}
}
diff --git a/src/com/hippo/ehviewer/exception/SadPandaException.java b/src/com/hippo/ehviewer/exception/SadPandaException.java
new file mode 100644
index 000000000..e62383969
--- /dev/null
+++ b/src/com/hippo/ehviewer/exception/SadPandaException.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2014 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.exception;
+
+public class SadPandaException extends Exception {
+ private static final long serialVersionUID = 1L;
+}
diff --git a/src/com/hippo/ehviewer/network/HttpHelper.java b/src/com/hippo/ehviewer/network/HttpHelper.java
index 8d1c3bff3..fddf74e97 100644
--- a/src/com/hippo/ehviewer/network/HttpHelper.java
+++ b/src/com/hippo/ehviewer/network/HttpHelper.java
@@ -42,6 +42,7 @@ import com.hippo.ehviewer.DiskCache;
import com.hippo.ehviewer.R;
import com.hippo.ehviewer.exception.RedirectionException;
import com.hippo.ehviewer.exception.ResponseCodeException;
+import com.hippo.ehviewer.exception.SadPandaException;
import com.hippo.ehviewer.util.Constants;
import com.hippo.ehviewer.util.Ui;
import com.hippo.ehviewer.util.Util;
@@ -143,6 +144,9 @@ public class HttpHelper {
else if (e instanceof SocketException)
return "SocketException : " + e.getMessage();
+ else if (e instanceof SadPandaException)
+ return "Sad Panda";
+
else
return e.getMessage();
}
@@ -214,6 +218,11 @@ public class HttpHelper {
switch (responseCode) {
case HttpURLConnection.HTTP_OK:
case HttpURLConnection.HTTP_PARTIAL:
+ // Test sad panda
+ String contentType = conn.getHeaderField("Content-Type");
+ if (contentType != null && contentType.equals("image/gif"))
+ throw new SadPandaException();
+
String pageContext = getPageContext(conn);
if (msg != null) {
Package p = new Package();
@@ -364,6 +373,11 @@ public class HttpHelper {
switch (responseCode) {
case HttpURLConnection.HTTP_OK:
case HttpURLConnection.HTTP_PARTIAL:
+ // Test sad panda
+ String contentType = conn.getHeaderField("Content-Type");
+ if (contentType != null && contentType.equals("image/gif"))
+ throw new SadPandaException();
+
String pageContext = getPageContext(conn);
if (msg != null) {
Package p = new Package();
@@ -538,6 +552,11 @@ public class HttpHelper {
switch (responseCode) {
case HttpURLConnection.HTTP_OK:
case HttpURLConnection.HTTP_PARTIAL:
+ // Test sad panda
+ String contentType = conn.getHeaderField("Content-Type");
+ if (contentType != null && contentType.equals("image/gif"))
+ throw new SadPandaException();
+
String pageContext = getPageContext(conn);
if (msg != null) {
Package p = new Package();
|