Fix parsing popular

This commit is contained in:
seven332 committed 2019-03-19 21:22:43 +08:00
1 parent e5df5714de
commit 2ec229c8ef
7 files changed
+28 -167

No files matched your search

@@ -46,7 +46,6 @@ public class EhClient {
public static final int METHOD_ADD_FAVORITES_RANGE = 10;
public static final int METHOD_MODIFY_FAVORITES = 11;
public static final int METHOD_GET_TORRENT_LIST = 12;
public static final int METHOD_GET_WHATS_HOT = 13;
public static final int METHOD_GET_PROFILE = 14;
public static final int METHOD_VOTE_COMMENT = 15;
public static final int METHOD_IMAGE_SEARCH = 16;
@@ -162,8 +161,6 @@ public class EhClient {
return EhEngine.modifyFavorites(this, mOkHttpClient, (String) params[0], (long[]) params[1], (Integer) params[2], (Boolean) params[3]);
case METHOD_GET_TORRENT_LIST:
return EhEngine.getTorrentList(this, mOkHttpClient, (String) params[0], (Long) params[1], (String) params[2]);
case METHOD_GET_WHATS_HOT:
return EhEngine.getWhatsHot(this, mOkHttpClient);
case METHOD_GET_PROFILE:
return EhEngine.getProfile(this, mOkHttpClient);
case METHOD_VOTE_COMMENT:
@@ -46,7 +46,6 @@ import com.hippo.ehviewer.client.parser.RateGalleryParser;
import com.hippo.ehviewer.client.parser.SignInParser;
import com.hippo.ehviewer.client.parser.TorrentParser;
import com.hippo.ehviewer.client.parser.VoteCommentParser;
import com.hippo.ehviewer.client.parser.WhatsHotParser;
import com.hippo.network.StatusCodeException;
import com.hippo.util.ExceptionUtils;
import com.hippo.yorozuya.AssertUtils;
@@ -750,46 +749,6 @@ public class EhEngine {
return null;
}
public static List<GalleryInfo> getWhatsHot(@Nullable EhClient.Task task,
OkHttpClient okHttpClient) throws Throwable {
String url = EhUrl.HOST_E;
Log.d(TAG, url);
Request request = new EhRequestBuilder(url, null).build();
Call call = okHttpClient.newCall(request);
// Put call
if (null != task) {
task.setCall(call);
}
String body = null;
Headers headers = null;
List<GalleryInfo> list;
int code = -1;
try {
Response response = call.execute();
code = response.code();
headers = response.headers();
body = response.body().string();
list = WhatsHotParser.parse(body);
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
throwException(call, code, headers, body, e);
throw e;
}
if (list.size() > 0) {
// Fill by api
fillGalleryListByApi(task, okHttpClient, list, url);
}
for (GalleryInfo info : list) {
info.thumb = EhUrl.getFixedPreviewThumbUrl(info.thumb);
}
return list;
}
private static ProfileParser.Result getProfileInternal(@Nullable EhClient.Task task,
OkHttpClient okHttpClient, String url, String referer) throws Throwable {
Log.d(TAG, url);
@@ -40,6 +40,9 @@ public class EhUrl {
public static final String API_E = HOST_E + "api.php";
public static final String API_EX = HOST_EX + "api.php";
public static final String URL_POPULAR_E = "https://e-hentai.org/popular";
public static final String URL_POPULAR_EX = "https://exhentai.org/popular";
public static final String URL_IMAGE_SEARCH_E = "https://upload.e-hentai.org/image_lookup.php";
public static final String URL_IMAGE_SEARCH_EX = "https://exhentai.org/upload/image_lookup.php";
@@ -152,6 +155,17 @@ public class EhUrl {
return "https://ehwiki.org/wiki/" + tag.replace(' ', '_');
}
@NonNull
public static String getPopularUrl() {
switch (Settings.getGallerySite()) {
default:
case SITE_E:
return URL_POPULAR_E;
case SITE_EX:
return URL_POPULAR_EX;
}
}
@NonNull
public static String getImageSearchUrl() {
switch (Settings.getGallerySite()) {
@@ -462,6 +462,8 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
}
return sb.toString();
}
case MODE_WHATS_HOT:
return EhUrl.getPopularUrl();
case MODE_IMAGE_SEARCH:
return EhUrl.getImageSearchUrl();
}
@@ -118,7 +118,7 @@ public class GalleryListParser {
return -2;
}
private static GalleryInfo parseGalleryInfoMinimal(Element e) {
private static GalleryInfo parseGalleryInfo(Element e) {
GalleryInfo gi = new GalleryInfo();
// Title, gid, token (required), tags
@@ -267,8 +267,10 @@ public class GalleryListParser {
//noinspection unchecked
result.galleryInfoList = Collections.EMPTY_LIST;
return result;
} else if (body.contains("Currently Popular Recent Galleries")) {
result.pages = 1;
} else {
throw e;
result.pages = Integer.MAX_VALUE;
}
}
@@ -283,7 +285,7 @@ public class GalleryListParser {
List<GalleryInfo> list = new ArrayList<>(es.size());
// First one is table header, skip it
for (int i = 0; i < es.size(); i++) {
GalleryInfo gi = parseGalleryInfoMinimal(es.get(i));
GalleryInfo gi = parseGalleryInfo(es.get(i));
if (null != gi) {
list.add(gi);
}
@@ -1,61 +0,0 @@
/*
* Copyright 2016 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.parser;
import com.hippo.ehviewer.client.EhUtils;
import com.hippo.ehviewer.client.data.GalleryInfo;
import com.hippo.ehviewer.client.exception.ParseException;
import com.hippo.util.ExceptionUtils;
import com.hippo.util.JsoupUtils;
import java.util.ArrayList;
import java.util.List;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public class WhatsHotParser {
@SuppressWarnings("ConstantConditions")
public static List<GalleryInfo> parse(String body) throws ParseException {
try {
List<GalleryInfo> galleryInfoList = new ArrayList<>(15);
Document d = Jsoup.parse(body);
Element pp = d.getElementById("pp");
Elements id1List = pp.getElementsByClass("id1");
for (int i = 0, n = id1List.size(); i < n; i++) {
GalleryInfo galleryInfo = new GalleryInfo();
Element id1 = id1List.get(i);
Element id3 = JsoupUtils.getElementByClass(id1, "id3");
Element temp = JsoupUtils.getElementByTag(id3, "a");
String url = temp.attr("href");
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(url);
galleryInfo.gid = result.gid;
galleryInfo.token = result.token;
temp = JsoupUtils.getElementByTag(temp, "img");
galleryInfo.thumb = EhUtils.handleThumbUrlResolution(temp.attr("src"));
galleryInfo.title = temp.attr("title");
galleryInfo.generateSLang();
galleryInfoList.add(galleryInfo);
}
return galleryInfoList;
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
throw new ParseException("Parse whats hot error", body);
}
}
}
@@ -1364,15 +1364,7 @@ public final class GalleryListScene extends BaseScene
}
mUrlBuilder.setPageIndex(page);
if (ListUrlBuilder.MODE_WHATS_HOT == mUrlBuilder.getMode()) {
EhRequest request = new EhRequest();
request.setMethod(EhClient.METHOD_GET_WHATS_HOT);
request.setCallback(new GetWhatsHotListener(getContext(),
activity.getStageId(), getTag(), taskId));
request.setArgs();
mClient.execute(request);
Analytics.viewWhatsHot();
} else if (ListUrlBuilder.MODE_IMAGE_SEARCH == mUrlBuilder.getMode()) {
if (ListUrlBuilder.MODE_IMAGE_SEARCH == mUrlBuilder.getMode()) {
EhRequest request = new EhRequest();
request.setMethod(EhClient.METHOD_IMAGE_SEARCH);
request.setCallback(new GetGalleryListListener(getContext(),
@@ -1390,7 +1382,12 @@ public final class GalleryListScene extends BaseScene
activity.getStageId(), getTag(), taskId));
request.setArgs(url);
mClient.execute(request);
Analytics.viewGalleryList();
if (ListUrlBuilder.MODE_WHATS_HOT == mUrlBuilder.getMode()) {
Analytics.viewWhatsHot();
} else {
Analytics.viewGalleryList();
}
}
}
@@ -1454,55 +1451,6 @@ public final class GalleryListScene extends BaseScene
}
}
private void onGetWhatsHotSuccess(List<GalleryInfo> result, int taskId) {
if (mHelper != null && mSearchBarMover != null &&
mHelper.isCurrentTask(taskId)) {
mHelper.setPages(taskId, 1);
mHelper.onGetPageData(taskId, result);
}
}
private void onGetWhatsHotFailure(Exception e, int taskId) {
if (mHelper != null && mSearchBarMover != null &&
mHelper.isCurrentTask(taskId)) {
mHelper.onGetException(taskId, e);
}
}
private static class GetWhatsHotListener extends EhCallback<GalleryListScene, List<GalleryInfo>> {
private final int mTaskId;
public GetWhatsHotListener(Context context, int stageId, String sceneTag, int taskId) {
super(context, stageId, sceneTag);
mTaskId = taskId;
}
@Override
public void onSuccess(List<GalleryInfo> result) {
GalleryListScene scene = getScene();
if (scene != null) {
scene.onGetWhatsHotSuccess(result, mTaskId);
}
}
@Override
public void onFailure(Exception e) {
GalleryListScene scene = getScene();
if (scene != null) {
scene.onGetWhatsHotFailure(e, mTaskId);
}
}
@Override
public void onCancel() {}
@Override
public boolean isInstance(SceneFragment scene) {
return scene instanceof GalleryListScene;
}
}
private static class GetGalleryListListener extends EhCallback<GalleryListScene, GalleryListParser.Result> {
private final int mTaskId;