Get show key from gallery page html
This commit is contained in:
1 parent
cc9205700c
commit
cca6e2a72e
3 files changed
+73
-4
No files matched your search
@@ -17,10 +17,8 @@
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.yorozuya.StringUtils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -29,6 +27,8 @@ public class GalleryPageParser {
|
||||
private static final Pattern PATTERN_IMAGE_URL = Pattern.compile("<img[^>]*src=\"([^\"]+)\" style");
|
||||
private static final Pattern PATTERN_SKIP_HATH_KEY = Pattern.compile("onclick=\"return nl\\('([^\\)]+)'\\)");
|
||||
private static final Pattern PATTERN_ORIGIN_IMAGE_URL = Pattern.compile("<a href=\"([^\"]+)fullimg.php([^\"]+)\">");
|
||||
// TODO Not sure about the size of show keys
|
||||
private static final Pattern PATTERN_SHOW_KEY = Pattern.compile("var showkey=\"([0-9a-z]+)\";");
|
||||
|
||||
public static Result parse(String body) throws ParseException {
|
||||
Matcher m;
|
||||
@@ -45,11 +45,15 @@ public class GalleryPageParser {
|
||||
if (m.find()) {
|
||||
result.originImageUrl = StringUtils.unescapeXml(m.group(1)) + "fullimg.php" + StringUtils.unescapeXml(m.group(2));
|
||||
}
|
||||
m = PATTERN_SHOW_KEY.matcher(body);
|
||||
if (m.find()) {
|
||||
result.showKey = m.group(1);
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(result.imageUrl)) {
|
||||
if (!TextUtils.isEmpty(result.imageUrl) && !TextUtils.isEmpty(result.showKey)) {
|
||||
return result;
|
||||
} else {
|
||||
throw new ParseException("Parse image url and skip hath key error", body);
|
||||
throw new ParseException("Parse image url and show error", body);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,5 +61,6 @@ public class GalleryPageParser {
|
||||
public String imageUrl;
|
||||
public String skipHathKey;
|
||||
public String originImageUrl;
|
||||
public String showKey;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2019 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 static org.junit.Assert.assertEquals;
|
||||
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import okio.BufferedSource;
|
||||
import okio.Okio;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
@Config(manifest = Config.NONE)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class GalleryPageParserTest {
|
||||
|
||||
@Test
|
||||
public void testParse() throws IOException, ParseException {
|
||||
InputStream resource = GalleryPageParserTest.class.getResourceAsStream("GalleryPageParserTest.html");
|
||||
BufferedSource source = Okio.buffer(Okio.source(resource));
|
||||
String body = source.readUtf8();
|
||||
|
||||
GalleryPageParser.Result result = GalleryPageParser.parse(body);
|
||||
assertEquals("http://108.6.41.160:2688/h/5c63e9a5810d8d9c873d9e0dfaadc4a0d70a13bf-188862-1280-879-jpg/keystamp=1550291700-145ecbbb10;fileindex=67290651;xres=1280/10.jpg", result.imageUrl);
|
||||
assertEquals("26664-430636", result.skipHathKey);
|
||||
assertEquals("https://e-hentai.org/fullimg.php?gid=1363978&page=10&key=qt2hwrx98a4", result.originImageUrl);
|
||||
assertEquals("ghz0e5m98a4", result.showKey);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>(C95) [rurudot (rurudo)] Innocence</title>
|
||||
<link rel="stylesheet" type="text/css" href="https://e-hentai.org/z/0339/g.css" />
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
function popUp(URL,w,h) {
|
||||
window.open(URL,"_pu"+(Math.random()+"").replace(/0\./,""),"toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+w+",height="+h+",left="+((screen.width-w)/2)+",top="+((screen.height-h)/2));
|
||||
return false;
|
||||
}
|
||||
</script>
|
||||
<div id="i1" class="sni" style="width:1300px"><h1>(C95) [rurudot (rurudo)] Innocence</h1><div id="i2"><div class="sn"><a onclick="return load_image(1, '0e82cbc893')" href="https://e-hentai.org/s/0e82cbc893/1363978-1"><img src="https://ehgt.org/g/f.png" /></a><a id="prev" onclick="return load_image(9, '3393c57a44')" href="https://e-hentai.org/s/3393c57a44/1363978-9"><img src="https://ehgt.org/g/p.png" /></a><div><span>10</span> / <span>11</span></div><a id="next" onclick="return load_image(11, 'fab3e858c9')" href="https://e-hentai.org/s/fab3e858c9/1363978-11"><img src="https://ehgt.org/g/n.png" /></a><a onclick="return load_image(11, 'fab3e858c9')" href="https://e-hentai.org/s/fab3e858c9/1363978-11"><img src="https://ehgt.org/g/l.png" /></a></div><div>10.jpg :: 1280 x 879 :: 184.4 KB</div></div><script async src="//adserver.juicyads.com/js/jads.js"></script><ins id="265909" data-width="728" data-height="90"></ins><script>(adsbyjuicy = window.adsbyjuicy || []).push({'adzone':265909});</script><div id="i3"><a onclick="return load_image(11, 'fab3e858c9')" href="https://e-hentai.org/s/fab3e858c9/1363978-11"><img id="img" src="http://108.6.41.160:2688/h/5c63e9a5810d8d9c873d9e0dfaadc4a0d70a13bf-188862-1280-879-jpg/keystamp=1550291700-145ecbbb10;fileindex=67290651;xres=1280/10.jpg" style="width:1280px;height:879px" onerror="this.onerror=null; nl('26664-430636')" /></a></div><script async src="//adserver.juicyads.com/js/jads.js"></script><ins id="249007" data-width="728" data-height="90"></ins><script>(adsbyjuicy = window.adsbyjuicy || []).push({'adzone':249007});</script><div id="i4"><div>10.jpg :: 1280 x 879 :: 184.4 KB</div><div class="sn"><a onclick="return load_image(1, '0e82cbc893')" href="https://e-hentai.org/s/0e82cbc893/1363978-1"><img src="https://ehgt.org/g/f.png" /></a><a id="prev" onclick="return load_image(9, '3393c57a44')" href="https://e-hentai.org/s/3393c57a44/1363978-9"><img src="https://ehgt.org/g/p.png" /></a><div><span>10</span> / <span>11</span></div><a id="next" onclick="return load_image(11, 'fab3e858c9')" href="https://e-hentai.org/s/fab3e858c9/1363978-11"><img src="https://ehgt.org/g/n.png" /></a><a onclick="return load_image(11, 'fab3e858c9')" href="https://e-hentai.org/s/fab3e858c9/1363978-11"><img src="https://ehgt.org/g/l.png" /></a></div></div><div id="i5"><div class="sb"><a href="https://e-hentai.org/g/1363978/88616cdd73/"><img src="https://ehgt.org/g/b.png" referrerpolicy="no-referrer" /></a></div></div><div id="i6" class="if"> <img src="https://ehgt.org/g/mr.gif" class="mr" /> <a href="https://e-hentai.org/?f_shash=49c9e58c17d96448671602159677541915aa6948&fs_from=10.jpg+from+%28C95%29+%5Brurudot+%28rurudo%29%5D+Innocence">Show all galleries with this file</a> <img src="https://ehgt.org/g/mr.gif" class="mr" /> <a href="#" onclick="prompt('Copy the URL below.', 'https://e-hentai.org/r/5c63e9a5810d8d9c873d9e0dfaadc4a0d70a13bf-188862-1280-879-jpg/forumtoken/1363978-10/10.jpg'); return false">Generate a static forum image link</a> <img src="https://ehgt.org/g/mr.gif" class="mr" /> <a href="#" id="loadfail" onclick="return nl('26664-430636')">Click here if the image fails loading</a> </div><div id="i7" class="if"> <img src="https://ehgt.org/g/mr.gif" class="mr" /> <a href="https://e-hentai.org/fullimg.php?gid=1363978&page=10&key=qt2hwrx98a4">Download original 4893 x 3360 15.05 MB source</a></div></div><p class="ip">[<a href="https://e-hentai.org/">Front Page</a>]</p><script type="text/javascript">var gid=1363978;var startpage=10;var startkey="49c9e58c17";var showkey="ghz0e5m98a4";var base_url="https://e-hentai.org/";var api_url = "https://api.e-hentai.org/api.php";var prl=9999;var si=26664;var xres = 1280;var yres = 879;</script><script type="text/javascript" src="https://e-hentai.org/z/0339/ehg_show.c.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user