Parse newer version of gallery correctly
This commit is contained in:
5 files changed
+52
-30
No files matched your search
@@ -19,6 +19,7 @@ package com.hippo.ehviewer.client.data;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class GalleryDetail extends GalleryInfo {
|
||||
@@ -40,9 +41,7 @@ public class GalleryDetail extends GalleryInfo {
|
||||
public String torrentUrl;
|
||||
public String archiveUrl;
|
||||
public String parent;
|
||||
public String newerUrl;
|
||||
public String newerName;
|
||||
public String newerDate;
|
||||
public ArrayList<GalleryInfo> newerVersions = new ArrayList<>();
|
||||
public String visible;
|
||||
public String language;
|
||||
public String size;
|
||||
@@ -64,9 +63,8 @@ public class GalleryDetail extends GalleryInfo {
|
||||
this.torrentUrl = in.readString();
|
||||
this.archiveUrl = in.readString();
|
||||
this.parent = in.readString();
|
||||
this.newerUrl = in.readString();
|
||||
this.newerName = in.readString();
|
||||
this.newerDate = in.readString();
|
||||
//noinspection unchecked
|
||||
this.newerVersions = in.readArrayList(GalleryInfo.class.getClassLoader());
|
||||
this.visible = in.readString();
|
||||
this.language = in.readString();
|
||||
this.size = in.readString();
|
||||
@@ -97,9 +95,7 @@ public class GalleryDetail extends GalleryInfo {
|
||||
dest.writeString(this.torrentUrl);
|
||||
dest.writeString(this.archiveUrl);
|
||||
dest.writeString(this.parent);
|
||||
dest.writeString(this.newerUrl);
|
||||
dest.writeString(this.newerName);
|
||||
dest.writeString(this.newerDate);
|
||||
dest.writeList(this.newerVersions);
|
||||
dest.writeString(this.visible);
|
||||
dest.writeString(this.language);
|
||||
dest.writeString(this.size);
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.hippo.ehviewer.client.EhUtils;
|
||||
import com.hippo.ehviewer.client.data.GalleryComment;
|
||||
import com.hippo.ehviewer.client.data.GalleryCommentList;
|
||||
import com.hippo.ehviewer.client.data.GalleryDetail;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.data.GalleryTagGroup;
|
||||
import com.hippo.ehviewer.client.data.LargePreviewSet;
|
||||
import com.hippo.ehviewer.client.data.NormalPreviewSet;
|
||||
@@ -72,7 +73,7 @@ public class GalleryDetailParser {
|
||||
private static final Pattern PATTERN_PREVIEW_PAGES = Pattern.compile("<td[^>]+><a[^>]+>([\\d,]+)</a></td><td[^>]+>(?:<a[^>]+>)?>(?:</a>)?</td>");
|
||||
private static final Pattern PATTERN_NORMAL_PREVIEW = Pattern.compile("<div class=\"gdtm\"[^<>]*><div[^<>]*width:(\\d+)[^<>]*height:(\\d+)[^<>]*\\((.+?)\\)[^<>]*-(\\d+)px[^<>]*><a[^<>]*href=\"(.+?)\"[^<>]*><img alt=\"([\\d,]+)\"");
|
||||
private static final Pattern PATTERN_LARGE_PREVIEW = Pattern.compile("<div class=\"gdtl\".+?<a href=\"(.+?)\"><img alt=\"([\\d,]+)\".+?src=\"(.+?)\"");
|
||||
private static final Pattern PATTERN_NEWER_VERSION = Pattern.compile("<div id=\"gnd\".+?<a href=\"([^<>]+)\">([^<>]+)</a>.+?added ([^<>]+)<br /></div>");
|
||||
private static final Pattern PATTERN_NEWER_DATE = Pattern.compile(", added (.+?)<br />");
|
||||
|
||||
private static final GalleryTagGroup[] EMPTY_GALLERY_TAG_GROUP_ARRAY = new GalleryTagGroup[0];
|
||||
private static final GalleryCommentList EMPTY_GALLERY_COMMENT_ARRAY = new GalleryCommentList(new GalleryComment[0], false);
|
||||
@@ -136,17 +137,6 @@ public class GalleryDetailParser {
|
||||
gd.torrentUrl = "";
|
||||
}
|
||||
|
||||
matcher = PATTERN_NEWER_VERSION.matcher(body);
|
||||
if (matcher.find()) {
|
||||
gd.newerUrl = StringUtils.unescapeXml(StringUtils.trim(matcher.group(1)));
|
||||
gd.newerName = StringUtils.unescapeXml(StringUtils.trim(matcher.group(2)));
|
||||
gd.newerDate = StringUtils.unescapeXml(StringUtils.trim(matcher.group(3)));
|
||||
} else {
|
||||
gd.newerUrl = "";
|
||||
gd.newerName = "";
|
||||
gd.newerDate = "";
|
||||
}
|
||||
|
||||
matcher = PATTERN_ARCHIVE.matcher(body);
|
||||
if (matcher.find()) {
|
||||
gd.archiveUrl = StringUtils.unescapeXml(StringUtils.trim(matcher.group(1)));
|
||||
@@ -263,6 +253,33 @@ public class GalleryDetailParser {
|
||||
ExceptionUtils.throwIfFatal(e);
|
||||
throw new ParseException("Can't parse gallery detail", body);
|
||||
}
|
||||
|
||||
// newer version
|
||||
try {
|
||||
Element gnd = d.getElementById("gnd");
|
||||
if (gnd != null) {
|
||||
matcher = PATTERN_NEWER_DATE.matcher(body);
|
||||
ArrayList<String> dates = new ArrayList<>();
|
||||
while (matcher.find()) {
|
||||
dates.add(matcher.group(1));
|
||||
}
|
||||
Elements elements = gnd.select("a");
|
||||
for (int i = 0; i< elements.size(); i++) {
|
||||
Element element = elements.get(i);
|
||||
GalleryInfo gi = new GalleryInfo();
|
||||
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(element.attr("href"));
|
||||
if (result != null) {
|
||||
gi.gid = result.gid;
|
||||
gi.token = result.token;
|
||||
gi.title = StringUtils.trim(element.text());
|
||||
gi.posted = dates.get(i);
|
||||
gd.newerVersions.add(gi);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// width:250px; height:356px; background:transparent url(https://exhentai.org/t/fe/1f/fe1fcfa9bf8fba2f03982eda0aa347cc9d6a6372-145921-1050-1492-jpg_250.jpg) 0 0 no-repeat
|
||||
|
||||
@@ -84,7 +84,6 @@ import com.hippo.ehviewer.client.data.GalleryTagGroup;
|
||||
import com.hippo.ehviewer.client.data.ListUrlBuilder;
|
||||
import com.hippo.ehviewer.client.data.PreviewSet;
|
||||
import com.hippo.ehviewer.client.exception.NoHAtHClientException;
|
||||
import com.hippo.ehviewer.client.parser.GalleryDetailUrlParser;
|
||||
import com.hippo.ehviewer.client.parser.RateGalleryParser;
|
||||
import com.hippo.ehviewer.dao.DownloadInfo;
|
||||
import com.hippo.ehviewer.dao.Filter;
|
||||
@@ -121,6 +120,7 @@ import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
@@ -888,7 +888,7 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
mSize.setText(gd.size);
|
||||
mPosted.setText(gd.posted);
|
||||
mFavoredTimes.setText(resources.getString(R.string.favored_times, gd.favoriteCount));
|
||||
if (!TextUtils.isEmpty(gd.newerUrl)) {
|
||||
if (gd.newerVersions != null && gd.newerVersions.size() != 0) {
|
||||
mNewerVersion.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@@ -1211,14 +1211,20 @@ public class GalleryDetailScene extends BaseScene implements View.OnClickListene
|
||||
}
|
||||
} else if (mNewerVersion == v) {
|
||||
if (mGalleryDetail != null) {
|
||||
GalleryDetailUrlParser.Result result = GalleryDetailUrlParser.parse(mGalleryDetail.newerUrl, false);
|
||||
if (result != null) {
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
|
||||
args.putLong(GalleryDetailScene.KEY_GID, result.gid);
|
||||
args.putString(GalleryDetailScene.KEY_TOKEN, result.token);
|
||||
startScene(new Announcer(GalleryDetailScene.class).setArgs(args));
|
||||
ArrayList<CharSequence> titles = new ArrayList<>();
|
||||
for (GalleryInfo newerVersion : mGalleryDetail.newerVersions) {
|
||||
titles.add(getString(R.string.newer_version_title, newerVersion.title, newerVersion.posted));
|
||||
}
|
||||
new MaterialAlertDialogBuilder(requireContext())
|
||||
.setItems(titles.toArray(new CharSequence[0]), (dialog, which) -> {
|
||||
GalleryInfo newerVersion = mGalleryDetail.newerVersions.get(which);
|
||||
Bundle args = new Bundle();
|
||||
args.putString(GalleryDetailScene.KEY_ACTION, GalleryDetailScene.ACTION_GID_TOKEN);
|
||||
args.putLong(GalleryDetailScene.KEY_GID, newerVersion.gid);
|
||||
args.putString(GalleryDetailScene.KEY_TOKEN, newerVersion.token);
|
||||
startScene(new Announcer(GalleryDetailScene.class).setArgs(args));
|
||||
})
|
||||
.show();
|
||||
}
|
||||
} else if (mInfo == v) {
|
||||
Bundle args = new Bundle();
|
||||
|
||||
Reference in new issue
Block a user