Add e-hentai site support
This commit is contained in:
1 parent
25d75deb3c
commit
6e315ea94d
15 files changed
+118
-31
No files matched your search
@@ -201,6 +201,17 @@ public class Settings {
|
||||
/********************
|
||||
****** Eh
|
||||
********************/
|
||||
public static final String KEY_GALLERY_SITE = "gallery_site";
|
||||
private static final int DEFAULT_GALLERY_SITE = 1;
|
||||
|
||||
public static int getGallerySite() {
|
||||
return getIntFromStr(KEY_GALLERY_SITE, DEFAULT_GALLERY_SITE);
|
||||
}
|
||||
|
||||
public static void putGallerySite(int value) {
|
||||
putIntToStr(KEY_GALLERY_SITE, value);
|
||||
}
|
||||
|
||||
public static final String KEY_LIST_MODE = "list_mode";
|
||||
private static final int DEFAULT_LIST_MODE = 0;
|
||||
|
||||
|
||||
@@ -30,6 +30,16 @@ public class EhCookieStore extends CookieDBStore {
|
||||
|
||||
public static final String KEY_IPD_MEMBER_ID = "ipb_member_id";
|
||||
public static final String KEY_IPD_PASS_HASH = "ipb_pass_hash";
|
||||
public static final String KEY_TIPS = "tips";
|
||||
|
||||
public static final Cookie sTipsCookie =
|
||||
new Cookie.Builder()
|
||||
.name(KEY_TIPS)
|
||||
.value("0")
|
||||
.domain(EhUrl.DOMAIN_G)
|
||||
.path("/")
|
||||
.expiresAt(Long.MAX_VALUE)
|
||||
.build();
|
||||
|
||||
public void signOut() {
|
||||
removeAll();
|
||||
@@ -68,27 +78,39 @@ public class EhCookieStore extends CookieDBStore {
|
||||
public List<Cookie> loadForRequest(HttpUrl url, Request request) {
|
||||
List<Cookie> cookies = super.loadForRequest(url, request);
|
||||
Object tag = request.tag();
|
||||
String host = url.host();
|
||||
|
||||
if (url.host().equals(EhUrl.DOMAIN_EX) && tag instanceof EhConfig) {
|
||||
EhConfig ehConfig = (EhConfig) tag;
|
||||
boolean checkTips = domainMatch(host, EhUrl.DOMAIN_G);
|
||||
boolean checkUconfig = (domainMatch(host, EhUrl.DOMAIN_E) || domainMatch(host, EhUrl.DOMAIN_EX)) && tag instanceof EhConfig;
|
||||
|
||||
if (checkTips || checkUconfig) {
|
||||
List<Cookie> result = new ArrayList<>(cookies.size() + 1);
|
||||
// Add all but skip uconfig
|
||||
// Add all but skip some
|
||||
for (Cookie cookie: cookies) {
|
||||
if (EhConfig.KEY_UCONFIG.equals(cookie.name())) {
|
||||
String name = cookie.name();
|
||||
if (checkTips && KEY_TIPS.equals(name)) {
|
||||
continue;
|
||||
}
|
||||
if (checkUconfig && EhConfig.KEY_UCONFIG.equals(name)) {
|
||||
continue;
|
||||
}
|
||||
result.add(cookie);
|
||||
}
|
||||
// Add uconfig from EhConfig
|
||||
Cookie uconfigCookie = new Cookie.Builder()
|
||||
.name(EhConfig.KEY_UCONFIG)
|
||||
.value(ehConfig.uconfig())
|
||||
.domain(EhUrl.DOMAIN_EX)
|
||||
.path("/")
|
||||
.build();
|
||||
result.add(uconfigCookie);
|
||||
|
||||
// Add some
|
||||
if (checkTips) {
|
||||
result.add(sTipsCookie);
|
||||
}
|
||||
if (checkUconfig) {
|
||||
EhConfig ehConfig = (EhConfig) tag;
|
||||
Cookie uconfigCookie = new Cookie.Builder()
|
||||
.name(EhConfig.KEY_UCONFIG)
|
||||
.value(ehConfig.uconfig())
|
||||
.domain(host)
|
||||
.path("/")
|
||||
.expiresAt(Long.MAX_VALUE)
|
||||
.build();
|
||||
result.add(uconfigCookie);
|
||||
}
|
||||
return Collections.unmodifiableList(result);
|
||||
} else {
|
||||
return cookies;
|
||||
|
||||
@@ -229,7 +229,7 @@ public class EhEngine {
|
||||
}
|
||||
json.put("gidlist", ja);
|
||||
json.put("namespace", 1);
|
||||
String url = EhUrl.API_EX;
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url)
|
||||
.post(RequestBody.create(JSON, json.toString()))
|
||||
@@ -314,7 +314,7 @@ public class EhEngine {
|
||||
json.put("token", token);
|
||||
json.put("rating", (int) Math.ceil(rating * 2));
|
||||
final RequestBody requestBody = RequestBody.create(JSON, json.toString());
|
||||
String url = EhUrl.API_EX;
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
.post(requestBody)
|
||||
@@ -375,7 +375,7 @@ public class EhEngine {
|
||||
.put("pagelist", new JSONArray().put(
|
||||
new JSONArray().put(gid).put(gtoken).put(page + 1)));
|
||||
final RequestBody requestBody = RequestBody.create(JSON, json.toString());
|
||||
String url = EhUrl.API_EX;
|
||||
String url = EhUrl.getApiUrl();
|
||||
Log.d(TAG, url);
|
||||
Request request = new EhRequestBuilder(url, task.getEhConfig())
|
||||
.post(requestBody)
|
||||
|
||||
@@ -16,10 +16,14 @@
|
||||
|
||||
package com.hippo.ehviewer.client;
|
||||
|
||||
import com.hippo.ehviewer.Settings;
|
||||
import com.hippo.network.UrlBuilder;
|
||||
|
||||
public class EhUrl {
|
||||
|
||||
public static final int SITE_G = 0;
|
||||
public static final int SITE_EX = 1;
|
||||
|
||||
public static final String DOMAIN_EX = "exhentai.org";
|
||||
public static final String DOMAIN_E = "e-hentai.org";
|
||||
public static final String DOMAIN_G = "g.e-hentai.org";
|
||||
@@ -30,19 +34,51 @@ public class EhUrl {
|
||||
|
||||
public static final String API_SIGN_IN = "http://forums.e-hentai.org/index.php?act=Login&CODE=01";
|
||||
|
||||
public static final String API_G = HOST_G + "api.php";
|
||||
public static final String API_EX = HOST_EX + "api.php";
|
||||
|
||||
public static final String URL_SIGN_IN = "http://forums.e-hentai.org/index.php?act=Login";
|
||||
public static final String URL_REGISTER = "http://forums.e-hentai.org/index.php?act=Reg&CODE=00";
|
||||
public static final String URL_FAVORITES = HOST_EX + "favorites.php";
|
||||
public static final String URL_FAVORITES_G = HOST_G + "favorites.php";
|
||||
public static final String URL_FAVORITES_EX = HOST_EX + "favorites.php";
|
||||
public static final String URL_FORUMS = "https://forums.e-hentai.org/";
|
||||
|
||||
public static String getGalleryDetailUrl(long gid, String token) {
|
||||
return getGalleryDetailUrl(gid, token, 0, false);
|
||||
}
|
||||
|
||||
public static String getHost() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_G:
|
||||
return HOST_G;
|
||||
case SITE_EX:
|
||||
return HOST_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFavoritesUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_G:
|
||||
return URL_FAVORITES_G;
|
||||
case SITE_EX:
|
||||
return URL_FAVORITES_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getApiUrl() {
|
||||
switch (Settings.getGallerySite()) {
|
||||
default:
|
||||
case SITE_G:
|
||||
return API_G;
|
||||
case SITE_EX:
|
||||
return API_EX;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getGalleryDetailUrl(long gid, String token, int index, boolean allComment) {
|
||||
UrlBuilder builder = new UrlBuilder(HOST_EX + "g/" + gid + '/' + token + '/');
|
||||
UrlBuilder builder = new UrlBuilder(getHost() + "g/" + gid + '/' + token + '/');
|
||||
if (index != 0) {
|
||||
builder.addQuery("p", index);
|
||||
}
|
||||
@@ -53,10 +89,10 @@ public class EhUrl {
|
||||
}
|
||||
|
||||
public static String getPageUrl(long gid, int index, String pToken) {
|
||||
return HOST_EX + "s/" + pToken + '/' + gid + '-' + (index + 1);
|
||||
return getHost() + "s/" + pToken + '/' + gid + '-' + (index + 1);
|
||||
}
|
||||
|
||||
public static String getAddFavorites(long gid, String token) {
|
||||
return HOST_EX + "gallerypopups.php?gid=" + gid + "&t=" + token + "&act=addfav";
|
||||
return getHost() + "gallerypopups.php?gid=" + gid + "&t=" + token + "&act=addfav";
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class FavListUrlBuilder implements Parcelable {
|
||||
}
|
||||
|
||||
public String build() {
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.URL_FAVORITES);
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.getFavoritesUrl());
|
||||
if (isValidFavCat(mFavCat)) {
|
||||
ub.addQuery("favcat", Integer.toString(mFavCat));
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
default:
|
||||
case MODE_NORMAL: {
|
||||
boolean filter = false;
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.HOST_EX);
|
||||
UrlBuilder ub = new UrlBuilder(EhUrl.getHost());
|
||||
if (mCategory != EhUtils.NONE) {
|
||||
ub.addQuery("f_doujinshi", ((mCategory & EhConfig.DOUJINSHI) == 0) ? "0" : "1");
|
||||
ub.addQuery("f_manga", ((mCategory & EhConfig.MANGA) == 0) ? "0" : "1");
|
||||
@@ -367,7 +367,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
return ub.build();
|
||||
}
|
||||
case MODE_UPLOADER: {
|
||||
StringBuilder sb = new StringBuilder(EhUrl.HOST_EX);
|
||||
StringBuilder sb = new StringBuilder(EhUrl.getHost());
|
||||
sb.append("uploader/");
|
||||
try {
|
||||
sb.append(URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
@@ -380,7 +380,7 @@ public class ListUrlBuilder implements Cloneable, Parcelable {
|
||||
return sb.toString();
|
||||
}
|
||||
case MODE_TAG: {
|
||||
StringBuilder sb = new StringBuilder(EhUrl.HOST_EX);
|
||||
StringBuilder sb = new StringBuilder(EhUrl.getHost());
|
||||
sb.append("tag/");
|
||||
try {
|
||||
sb.append(URLEncoder.encode(mKeyword, "UTF-8"));
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
@@ -52,7 +51,7 @@ public class FavoritesParser {
|
||||
int limit;
|
||||
|
||||
try {
|
||||
Document d = Jsoup.parse(body, EhUrl.HOST_EX);
|
||||
Document d = Jsoup.parse(body);
|
||||
Element ido = JsoupUtils.getElementByClass(d, "ido");
|
||||
Elements fps = ido.getElementsByClass("fp");
|
||||
// Last one is "fp fps"
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package com.hippo.ehviewer.client.parser;
|
||||
|
||||
import com.hippo.ehviewer.client.EhUrl;
|
||||
import com.hippo.ehviewer.client.data.GalleryInfo;
|
||||
import com.hippo.ehviewer.client.exception.ParseException;
|
||||
import com.hippo.util.JsoupUtils;
|
||||
@@ -35,7 +34,7 @@ public class WhatsHotParser {
|
||||
public static List<GalleryInfo> parse(String body) throws ParseException {
|
||||
try {
|
||||
List<GalleryInfo> galleryInfoList = new ArrayList<>(15);
|
||||
Document d = Jsoup.parse(body, EhUrl.HOST_G);
|
||||
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++) {
|
||||
|
||||
@@ -987,7 +987,7 @@ public class FavoritesScene extends BaseScene implements
|
||||
String url;
|
||||
if (local) {
|
||||
// Local fav is shown now, but operation need be done for cloud fav
|
||||
url = EhUrl.URL_FAVORITES;
|
||||
url = EhUrl.getFavoritesUrl();
|
||||
} else {
|
||||
url = mUrlBuilder.build();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ public class CookieDBStore implements CookieJar {
|
||||
: domainMatch(urlHost, cookie.domain());
|
||||
}
|
||||
|
||||
private static boolean domainMatch(String urlHost, String cookieDomain) {
|
||||
public static boolean domainMatch(String urlHost, String cookieDomain) {
|
||||
if (urlHost.equals(cookieDomain)) {
|
||||
return true; // As in 'example.com' matching 'example.com'.
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user