EhViewer v1.9.7.7版本的 MD5 值为:828893cd54837a794dab17a02809e194

以下内容为反编译后的 EhEngine.java 源代码,内容仅作参考


package com.hippo.ehviewer.client;

import android.text.TextUtils;
import android.util.Log;
import android.util.Pair;
import com.hippo.ehviewer.AppConfig;
import com.hippo.ehviewer.EhApplication;
import com.hippo.ehviewer.GetText;
import com.hippo.ehviewer.Settings;
import com.hippo.ehviewer.client.EhClient;
import com.hippo.ehviewer.client.data.EhNewsDetail;
import com.hippo.ehviewer.client.data.EhTopListDetail;
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.HomeDetail;
import com.hippo.ehviewer.client.data.PreviewSet;
import com.hippo.ehviewer.client.data.userTag.TagPushParam;
import com.hippo.ehviewer.client.data.userTag.UserTag;
import com.hippo.ehviewer.client.data.userTag.UserTagList;
import com.hippo.ehviewer.client.exception.CancelledException;
import com.hippo.ehviewer.client.exception.EhException;
import com.hippo.ehviewer.client.exception.NoHAtHClientException;
import com.hippo.ehviewer.client.exception.ParseException;
import com.hippo.ehviewer.client.parser.ArchiveParser;
import com.hippo.ehviewer.client.parser.EhEventParse;
import com.hippo.ehviewer.client.parser.EhHomeParser;
import com.hippo.ehviewer.client.parser.FavoritesParser;
import com.hippo.ehviewer.client.parser.ForumsParser;
import com.hippo.ehviewer.client.parser.GalleryApiParser;
import com.hippo.ehviewer.client.parser.GalleryDetailParser;
import com.hippo.ehviewer.client.parser.GalleryListParser;
import com.hippo.ehviewer.client.parser.GalleryPageApiParser;
import com.hippo.ehviewer.client.parser.GalleryPageParser;
import com.hippo.ehviewer.client.parser.GalleryTokenApiParser;
import com.hippo.ehviewer.client.parser.MyTagLitParser;
import com.hippo.ehviewer.client.parser.ProfileParser;
import com.hippo.ehviewer.client.parser.RateGalleryParser;
import com.hippo.ehviewer.client.parser.SignInParser;
import com.hippo.ehviewer.client.parser.TopListParser;
import com.hippo.ehviewer.client.parser.TorrentParser;
import com.hippo.ehviewer.client.parser.VoteCommentParser;
import com.hippo.ehviewer.download.DownloadService;
import com.hippo.network.StatusCodeException;
import com.hippo.util.ExceptionUtils;
import com.hippo.yorozuya.AssertUtils;
import com.xjs.ehviewer.R;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.Headers;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.Response;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
public class EhEngine {
    static final boolean $assertionsDisabled = false;
    private static final String KOKOMADE_URL = "https://exhentai.org/img/kokomade.jpg";
    private static final String SAD_PANDA_DISPOSITION = "inline; filename=\"sadpanda.jpg\"";
    private static final String SAD_PANDA_LENGTH = "9615";
    private static final String SAD_PANDA_TYPE = "image/gif";
    private static final String TAG = "EhEngine";
    public static EhFilter sEhFilter;
    public static final MediaType MEDIA_TYPE_JSON = MediaType.parse("application/json; charset=utf-8");
    public static final MediaType MEDIA_TYPE_URLENCODED = MediaType.parse("application/x-www-form-urlencoded");
    private static final MediaType MEDIA_TYPE_JPEG = MediaType.parse("image/jpeg");
    private static final Pattern PATTERN_NEED_HATH_CLIENT = Pattern.compile("(You must have a H@H client assigned to your account to use this feature\\.)");

    public static Response editWatchedTag() throws Throwable {
        return null;
    }

    public static void initialize() {
        sEhFilter = EhFilter.getInstance();
    }

    private static void doThrowException(Call call, int i, Headers headers, String str, Throwable th) throws Throwable {
        if (call.isCanceled()) {
            throw new CancelledException();
        }
        if (headers != null && SAD_PANDA_DISPOSITION.equals(headers.get("Content-Disposition")) && SAD_PANDA_TYPE.equals(headers.get("Content-Type")) && SAD_PANDA_LENGTH.equals(headers.get("Content-Length"))) {
            throw new EhException("Sad Panda");
        }
        if (str != null && str.contains(KOKOMADE_URL)) {
            throw new EhException("今回はここまで\n\n" + GetText.getString(R.string.kokomade_tip));
        } else if (!(th instanceof ParseException)) {
            if (i >= 400) {
                throw new StatusCodeException(i);
            }
            if (th != null) {
                throw th;
            }
        } else if (str != null && !str.contains("<")) {
            throw new EhException(str);
        } else {
            if (TextUtils.isEmpty(str)) {
                throw new EhException(GetText.getString(R.string.error_empty_html));
            }
            if (Settings.getSaveParseErrorBody()) {
                AppConfig.saveParseErrorBody((ParseException) th);
            }
            throw new EhException(GetText.getString(R.string.error_parse_error));
        }
    }

    private static void throwException(Call call, int i, Headers headers, String str, Throwable th) throws Throwable {
        try {
            doThrowException(call, i, headers, str, th);
        } catch (Throwable th2) {
            th2.printStackTrace();
            throw th2;
        }
    }

    public static String signIn(EhClient.Task task, OkHttpClient okHttpClient, String str, String str2) throws Throwable {
        Throwable th;
        int i;
        String str3;
        Response execute;
        Headers headers;
        FormBody.Builder add = new FormBody.Builder().add("UserName", str).add("PassWord", str2).add("submit", "Log me in").add("CookieDate", "1").add("temporary_https", "off");
        Log.d(TAG, EhUrl.API_SIGN_IN);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(EhUrl.API_SIGN_IN, "https://forums.e-hentai.org/index.php?act=Login&CODE=00", "https://forums.e-hentai.org").post(add.build()).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers2 = null;
        int i2 = -1;
        try {
            execute = newCall.execute();
            i2 = execute.code();
            headers = execute.headers();
        } catch (Throwable th2) {
            th = th2;
            i = i2;
            str3 = null;
        }
        try {
            return SignInParser.parse(execute.body().string());
        } catch (Throwable th3) {
            str3 = null;
            headers2 = headers;
            th = th3;
            i = i2;
            ExceptionUtils.throwIfFatal(th);
            throwException(newCall, i, headers2, str3, th);
            throw th;
        }
    }

    private static void fillGalleryList(EhClient.Task task, OkHttpClient okHttpClient, List<GalleryInfo> list, String str, boolean z) throws Throwable {
        int i = 0;
        if (z) {
            int size = list.size();
            int i2 = 0;
            while (i2 < size) {
                GalleryInfo galleryInfo = list.get(i2);
                if (!sEhFilter.filterTitle(galleryInfo) || !sEhFilter.filterUploader(galleryInfo)) {
                    list.remove(i2);
                    i2--;
                    size--;
                }
                i2++;
            }
        }
        boolean z2 = false;
        boolean z3 = false;
        boolean z4 = false;
        for (GalleryInfo galleryInfo2 : list) {
            if (galleryInfo2.simpleTags != null) {
                z2 = true;
            }
            if (galleryInfo2.pages != 0) {
                z3 = true;
            }
            if (galleryInfo2.rated) {
                z4 = true;
            }
        }
        if ((z && sEhFilter.needTags() && !z2) || (Settings.getShowGalleryPages() && !z3) || z4) {
            fillGalleryListByApi(task, okHttpClient, list, str);
        }
        if (z) {
            int size2 = list.size();
            while (i < size2) {
                GalleryInfo galleryInfo3 = list.get(i);
                if (!sEhFilter.filterUploader(galleryInfo3) || !sEhFilter.filterTag(galleryInfo3) || !sEhFilter.filterTagNamespace(galleryInfo3)) {
                    list.remove(i);
                    i--;
                    size2--;
                }
                i++;
            }
        }
        for (GalleryInfo galleryInfo4 : list) {
            galleryInfo4.thumb = EhUrl.getFixedPreviewThumbUrl(galleryInfo4.thumb);
        }
    }

    public static GalleryListParser.Result getGalleryList(EhClient.Task task, OkHttpClient okHttpClient, String str) throws Throwable {
        String str2;
        Response execute;
        Headers headers;
        String referer = EhUrl.getReferer();
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, referer).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers2 = null;
        String str3 = null;
        int i = -1;
        try {
            execute = newCall.execute();
            i = execute.code();
            headers = execute.headers();
        } catch (Throwable th) {
            th = th;
            str2 = null;
        }
        try {
            str3 = execute.body().string();
            GalleryListParser.Result parse = GalleryListParser.parse(str3);
            fillGalleryList(task, okHttpClient, parse.galleryInfoList, str, true);
            return parse;
        } catch (Throwable th2) {
            th = th2;
            str2 = str3;
            headers2 = headers;
            ExceptionUtils.throwIfFatal(th);
            throwException(newCall, i, headers2, str2, th);
            throw th;
        }
    }

    public static List<GalleryInfo> fillGalleryListByApi(EhClient.Task task, OkHttpClient okHttpClient, List<GalleryInfo> list, String str) throws Throwable {
        ArrayList arrayList = new ArrayList(25);
        int size = list.size();
        for (int i = 0; i < size; i++) {
            arrayList.add(list.get(i));
            if (arrayList.size() == 25 || i == size - 1) {
                doFillGalleryListByApi(task, okHttpClient, arrayList, str);
                arrayList.clear();
            }
        }
        return list;
    }

    private static void doFillGalleryListByApi(EhClient.Task task, OkHttpClient okHttpClient, List<GalleryInfo> list, String str) throws Throwable {
        int i;
        Throwable th;
        String str2;
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("method", "gdata");
        JSONArray jSONArray = new JSONArray();
        int size = list.size();
        for (int i2 = 0; i2 < size; i2++) {
            GalleryInfo galleryInfo = list.get(i2);
            JSONArray jSONArray2 = new JSONArray();
            jSONArray2.put(galleryInfo.gid);
            jSONArray2.put(galleryInfo.token);
            jSONArray.put(jSONArray2);
        }
        jSONObject.put("gidlist", jSONArray);
        jSONObject.put("namespace", 1);
        String apiUrl = EhUrl.getApiUrl();
        String origin = EhUrl.getOrigin();
        Log.d(TAG, apiUrl);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(apiUrl, str, origin).post(RequestBody.create(MEDIA_TYPE_JSON, jSONObject.toString())).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        String str3 = null;
        int i3 = -1;
        try {
            Response execute = newCall.execute();
            i3 = execute.code();
            Headers headers2 = execute.headers();
            try {
                str3 = execute.body().string();
                GalleryApiParser.parse(str3, list);
            } catch (Throwable th2) {
                i = i3;
                th = th2;
                str2 = str3;
                headers = headers2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str2, th);
                throw th;
            }
        } catch (Throwable th3) {
            i = i3;
            th = th3;
            str2 = null;
        }
    }

    public static GalleryDetail getGalleryDetail(EhClient.Task task, OkHttpClient okHttpClient, String str) throws Throwable {
        Throwable th;
        int i;
        String str2;
        String referer = EhUrl.getReferer();
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, referer).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                String string = execute.body().string();
                String parse = EhEventParse.parse(string);
                if (parse != null) {
                    EhApplication.getInstance().showEventPane(parse);
                }
                return GalleryDetailParser.parse(string);
            } catch (Throwable th2) {
                str2 = null;
                headers = headers2;
                th = th2;
                i = i2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str2, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i = i2;
            str2 = null;
        }
    }

    public static Pair<PreviewSet, Integer> getPreviewSet(EhClient.Task task, OkHttpClient okHttpClient, String str) throws Throwable {
        Throwable th;
        int i;
        String str2;
        String referer = EhUrl.getReferer();
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, referer).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                String string = execute.body().string();
                return Pair.create(GalleryDetailParser.parsePreviewSet(string), Integer.valueOf(GalleryDetailParser.parsePreviewPages(string)));
            } catch (Throwable th2) {
                str2 = null;
                headers = headers2;
                th = th2;
                i = i2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str2, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i = i2;
            str2 = null;
        }
    }

    public static RateGalleryParser.Result rateGallery(EhClient.Task task, OkHttpClient okHttpClient, long j, String str, long j2, String str2, float f) throws Throwable {
        Throwable th;
        int i;
        String str3;
        Response execute;
        Headers headers;
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("method", "rategallery");
        jSONObject.put("apiuid", j);
        jSONObject.put("apikey", str);
        jSONObject.put("gid", j2);
        jSONObject.put("token", str2);
        jSONObject.put("rating", (int) Math.ceil(f * 2.0f));
        RequestBody create = RequestBody.create(MEDIA_TYPE_JSON, jSONObject.toString());
        String apiUrl = EhUrl.getApiUrl();
        String galleryDetailUrl = EhUrl.getGalleryDetailUrl(j2, str2);
        String origin = EhUrl.getOrigin();
        Log.d(TAG, apiUrl);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(apiUrl, galleryDetailUrl, origin).post(create).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers2 = null;
        int i2 = -1;
        try {
            execute = newCall.execute();
            i2 = execute.code();
            headers = execute.headers();
        } catch (Throwable th2) {
            th = th2;
            i = i2;
            str3 = null;
        }
        try {
            return RateGalleryParser.parse(execute.body().string());
        } catch (Throwable th3) {
            str3 = null;
            headers2 = headers;
            th = th3;
            i = i2;
            ExceptionUtils.throwIfFatal(th);
            throwException(newCall, i, headers2, str3, th);
            throw th;
        }
    }

    public static GalleryCommentList commentGallery(EhClient.Task task, OkHttpClient okHttpClient, String str, String str2, String str3) throws Throwable {
        Throwable th;
        int i;
        String str4;
        FormBody.Builder builder = new FormBody.Builder();
        if (str3 == null) {
            builder.add("commenttext_new", str2);
        } else {
            builder.add("commenttext_edit", str2);
            builder.add("edit_comment", str3);
        }
        String origin = EhUrl.getOrigin();
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, str, origin).post(builder.build()).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                Document parse = Jsoup.parse(execute.body().string());
                Elements select = parse.select("#chd + p");
                if (select.size() > 0) {
                    throw new EhException(select.get(0).text());
                }
                return GalleryDetailParser.parseComments(parse);
            } catch (Throwable th2) {
                str4 = null;
                headers = headers2;
                th = th2;
                i = i2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str4, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i = i2;
            str4 = null;
        }
    }

    public static String getGalleryToken(EhClient.Task task, OkHttpClient okHttpClient, long j, String str, int i) throws Throwable {
        Throwable th;
        int i2;
        String str2;
        Response execute;
        Headers headers;
        RequestBody create = RequestBody.create(MEDIA_TYPE_JSON, new JSONObject().put("method", "gtoken").put("pagelist", new JSONArray().put(new JSONArray().put(j).put(str).put(i + 1))).toString());
        String apiUrl = EhUrl.getApiUrl();
        String referer = EhUrl.getReferer();
        String origin = EhUrl.getOrigin();
        Log.d(TAG, apiUrl);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(apiUrl, referer, origin).post(create).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers2 = null;
        int i3 = -1;
        try {
            execute = newCall.execute();
            i3 = execute.code();
            headers = execute.headers();
        } catch (Throwable th2) {
            th = th2;
            i2 = i3;
            str2 = null;
        }
        try {
            return GalleryTokenApiParser.parse(execute.body().string());
        } catch (Throwable th3) {
            str2 = null;
            headers2 = headers;
            th = th3;
            i2 = i3;
            ExceptionUtils.throwIfFatal(th);
            throwException(newCall, i2, headers2, str2, th);
            throw th;
        }
    }

    public static FavoritesParser.Result getFavorites(EhClient.Task task, OkHttpClient okHttpClient, String str, boolean z) throws Throwable {
        String str2;
        Response execute;
        Headers headers;
        String referer = EhUrl.getReferer();
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, referer).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers2 = null;
        String str3 = null;
        int i = -1;
        try {
            execute = newCall.execute();
            i = execute.code();
            headers = execute.headers();
        } catch (Throwable th) {
            th = th;
            str2 = null;
        }
        try {
            str3 = execute.body().string();
            FavoritesParser.Result parse = FavoritesParser.parse(str3);
            fillGalleryList(task, okHttpClient, parse.galleryInfoList, str, false);
            return parse;
        } catch (Throwable th2) {
            th = th2;
            str2 = str3;
            headers2 = headers;
            ExceptionUtils.throwIfFatal(th);
            throwException(newCall, i, headers2, str2, th);
            throw th;
        }
    }

    public static Void addFavorites(EhClient.Task task, OkHttpClient okHttpClient, long j, String str, int i, String str2) throws Throwable {
        String valueOf;
        Headers headers;
        Throwable th;
        String str3;
        int i2 = -1;
        if (i == -1) {
            valueOf = "favdel";
        } else if (i >= 0 && i <= 9) {
            valueOf = String.valueOf(i);
        } else {
            throw new EhException("Invalid dstCat: " + i);
        }
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("favcat", valueOf);
        if (str2 == null) {
            str2 = "";
        }
        builder.add("favnote", str2);
        builder.add("submit", "Apply Changes");
        builder.add("update", "1");
        String addFavorites = EhUrl.getAddFavorites(j, str);
        String origin = EhUrl.getOrigin();
        Log.d(TAG, addFavorites);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(addFavorites, addFavorites, origin).post(builder.build()).build());
        if (task != null) {
            task.setCall(newCall);
        }
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            headers = execute.headers();
            try {
                str3 = execute.body().string();
                try {
                    throwException(newCall, i2, headers, str3, null);
                    return null;
                } catch (Throwable th2) {
                    th = th2;
                    ExceptionUtils.throwIfFatal(th);
                    throwException(newCall, i2, headers, str3, th);
                    throw th;
                }
            } catch (Throwable th3) {
                str3 = null;
                th = th3;
            }
        } catch (Throwable th4) {
            headers = null;
            th = th4;
            str3 = null;
        }
    }

    public static Void addFavoritesRange(EhClient.Task task, OkHttpClient okHttpClient, long[] jArr, String[] strArr, int i) throws Throwable {
        AssertUtils.assertEquals(jArr.length, strArr.length);
        int length = jArr.length;
        for (int i2 = 0; i2 < length; i2++) {
            addFavorites(task, okHttpClient, jArr[i2], strArr[i2], i, null);
        }
        return null;
    }

    public static FavoritesParser.Result modifyFavorites(EhClient.Task task, OkHttpClient okHttpClient, String str, long[] jArr, int i, boolean z) throws Throwable {
        String str2;
        String str3;
        int i2 = -1;
        if (i == -1) {
            str2 = DownloadService.ACTION_DELETE;
        } else if (i < 0 || i > 9) {
            throw new EhException("Invalid dstCat: " + i);
        } else {
            str2 = "fav" + i;
        }
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("ddact", str2);
        for (long j : jArr) {
            builder.add("modifygids[]", Long.toString(j));
        }
        builder.add("apply", "Apply");
        String origin = EhUrl.getOrigin();
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, str, origin).post(builder.build()).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        String str4 = null;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                str4 = execute.body().string();
                FavoritesParser.Result parse = FavoritesParser.parse(str4);
                fillGalleryList(task, okHttpClient, parse.galleryInfoList, str, false);
                return parse;
            } catch (Throwable th) {
                th = th;
                str3 = str4;
                headers = headers2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i2, headers, str3, th);
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
            str3 = null;
        }
    }

    public static Pair<String, String>[] getTorrentList(EhClient.Task task, OkHttpClient okHttpClient, String str, long j, String str2) throws Throwable {
        Throwable th;
        int i;
        String str3;
        String galleryDetailUrl = EhUrl.getGalleryDetailUrl(j, str2);
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, galleryDetailUrl).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                return TorrentParser.parse(execute.body().string());
            } catch (Throwable th2) {
                str3 = null;
                headers = headers2;
                th = th2;
                i = i2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str3, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i = i2;
            str3 = null;
        }
    }

    public static EhTopListDetail getTopList(EhClient.Task task, OkHttpClient okHttpClient, String str) throws Throwable {
        Throwable th;
        int i;
        String str2;
        String topListUrl = EhUrl.getTopListUrl();
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, topListUrl).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                return TopListParser.parse(execute.body().string());
            } catch (Throwable th2) {
                str2 = null;
                headers = headers2;
                th = th2;
                i = i2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str2, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i = i2;
            str2 = null;
        }
    }

    public static Pair<String, Pair<String, String>[]> getArchiveList(EhClient.Task task, OkHttpClient okHttpClient, String str, long j, String str2) throws Throwable {
        Throwable th;
        int i;
        String str3;
        String galleryDetailUrl = EhUrl.getGalleryDetailUrl(j, str2);
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, galleryDetailUrl).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                return ArchiveParser.parse(execute.body().string());
            } catch (Throwable th2) {
                str3 = null;
                headers = headers2;
                th = th2;
                i = i2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str3, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i = i2;
            str3 = null;
        }
    }

    public static Void downloadArchive(EhClient.Task task, OkHttpClient okHttpClient, long j, String str, String str2, String str3) throws Throwable {
        Headers headers;
        Throwable th;
        String str4;
        if (str2 == null || str2.length() == 0) {
            throw new EhException("Invalid form param or: " + str2);
        } else if (str3 == null || str3.length() == 0) {
            throw new EhException("Invalid res: " + str3);
        } else {
            FormBody.Builder builder = new FormBody.Builder();
            builder.add("hathdl_xres", str3);
            String downloadArchive = EhUrl.getDownloadArchive(j, str, str2);
            String galleryDetailUrl = EhUrl.getGalleryDetailUrl(j, str);
            String origin = EhUrl.getOrigin();
            Log.d(TAG, downloadArchive);
            Call newCall = okHttpClient.newCall(new EhRequestBuilder(downloadArchive, galleryDetailUrl, origin).post(builder.build()).build());
            if (task != null) {
                task.setCall(newCall);
            }
            int i = -1;
            try {
                Response execute = newCall.execute();
                i = execute.code();
                headers = execute.headers();
                try {
                    str4 = execute.body().string();
                    try {
                        throwException(newCall, i, headers, str4, null);
                        if (PATTERN_NEED_HATH_CLIENT.matcher(str4).find()) {
                            throw new NoHAtHClientException("No H@H client");
                        }
                        return null;
                    } catch (Throwable th2) {
                        th = th2;
                        ExceptionUtils.throwIfFatal(th);
                        throwException(newCall, i, headers, str4, th);
                        throw th;
                    }
                } catch (Throwable th3) {
                    str4 = null;
                    th = th3;
                }
            } catch (Throwable th4) {
                headers = null;
                th = th4;
                str4 = null;
            }
        }
    }

    private static ProfileParser.Result getProfileInternal(EhClient.Task task, OkHttpClient okHttpClient, String str, String str2) throws Throwable {
        Throwable th;
        int i;
        String str3;
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, str2).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                return ProfileParser.parse(execute.body().string());
            } catch (Throwable th2) {
                str3 = null;
                headers = headers2;
                th = th2;
                i = i2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str3, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i = i2;
            str3 = null;
        }
    }

    public static ProfileParser.Result getProfile(EhClient.Task task, OkHttpClient okHttpClient) throws Throwable {
        String str;
        Log.d(TAG, EhUrl.URL_FORUMS);
        Headers headers = null;
        String str2 = null;
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(EhUrl.URL_FORUMS, (String) null).build());
        if (task != null) {
            task.setCall(newCall);
        }
        int i = -1;
        try {
            Response execute = newCall.execute();
            i = execute.code();
            Headers headers2 = execute.headers();
            try {
                str2 = execute.body().string();
                return getProfileInternal(task, okHttpClient, ForumsParser.parse(str2), EhUrl.URL_FORUMS);
            } catch (Throwable th) {
                th = th;
                str = str2;
                headers = headers2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str, th);
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
            str = null;
        }
    }

    public static VoteCommentParser.Result voteComment(EhClient.Task task, OkHttpClient okHttpClient, long j, String str, long j2, String str2, long j3, int i) throws Throwable {
        Throwable th;
        int i2;
        String str3;
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("method", "votecomment");
        jSONObject.put("apiuid", j);
        jSONObject.put("apikey", str);
        jSONObject.put("gid", j2);
        jSONObject.put("token", str2);
        jSONObject.put("comment_id", j3);
        jSONObject.put("comment_vote", i);
        RequestBody create = RequestBody.create(MEDIA_TYPE_JSON, jSONObject.toString());
        String apiUrl = EhUrl.getApiUrl();
        String referer = EhUrl.getReferer();
        String origin = EhUrl.getOrigin();
        Log.d(TAG, apiUrl);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(apiUrl, referer, origin).post(create).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i3 = -1;
        try {
            Response execute = newCall.execute();
            i3 = execute.code();
            Headers headers2 = execute.headers();
            try {
                return VoteCommentParser.parse(execute.body().string(), i);
            } catch (Throwable th2) {
                str3 = null;
                headers = headers2;
                th = th2;
                i2 = i3;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i2, headers, str3, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i2 = i3;
            str3 = null;
        }
    }

    public static GalleryListParser.Result imageSearch(EhClient.Task task, OkHttpClient okHttpClient, File file, boolean z, boolean z2, boolean z3) throws Throwable {
        String str;
        Response execute;
        Headers headers;
        MultipartBody.Builder builder = new MultipartBody.Builder();
        builder.setType(MultipartBody.FORM);
        builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"sfile\"; filename=\"a.jpg\""), RequestBody.create(MEDIA_TYPE_JPEG, file));
        Headers headers2 = null;
        String str2 = null;
        if (z) {
            builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"fs_similar\""), RequestBody.create((MediaType) null, "on"));
        }
        if (z2) {
            builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"fs_covers\""), RequestBody.create((MediaType) null, "on"));
        }
        if (z3) {
            builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"fs_exp\""), RequestBody.create((MediaType) null, "on"));
        }
        builder.addPart(Headers.of("Content-Disposition", "form-data; name=\"f_sfile\""), RequestBody.create((MediaType) null, "File Search"));
        String imageSearchUrl = EhUrl.getImageSearchUrl();
        String str3 = EhUrl.getReferer() + '/';
        String origin = EhUrl.getOrigin();
        String str4 = TAG;
        Log.d(str4, imageSearchUrl);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(imageSearchUrl, str3, origin).post(builder.build()).build());
        if (task != null) {
            task.setCall(newCall);
        }
        int i = -1;
        try {
            execute = newCall.execute();
            Log.d(str4, "" + execute.request().url().toString());
            i = execute.code();
            if (i == 302) {
                newCall = okHttpClient.newCall(new EhRequestBuilder(execute.headers().get("Location"), str3).build());
                execute = newCall.execute();
            }
            execute.headers();
        } catch (Throwable th) {
            th = th;
            str = null;
        }
        try {
            str2 = execute.body().string();
            GalleryListParser.Result parse = GalleryListParser.parse(str2);
            fillGalleryList(task, okHttpClient, parse.galleryInfoList, imageSearchUrl, true);
            return parse;
        } catch (Throwable th2) {
            th = th2;
            str = str2;
            headers2 = headers;
            ExceptionUtils.throwIfFatal(th);
            throwException(newCall, i, headers2, str, th);
            throw th;
        }
    }

    public static GalleryPageParser.Result getGalleryPage(EhClient.Task task, OkHttpClient okHttpClient, String str, long j, String str2) throws Throwable {
        Throwable th;
        int i;
        String str3;
        String galleryDetailUrl = EhUrl.getGalleryDetailUrl(j, str2);
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str, galleryDetailUrl).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                return GalleryPageParser.parse(execute.body().string());
            } catch (Throwable th2) {
                str3 = null;
                headers = headers2;
                th = th2;
                i = i2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str3, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i = i2;
            str3 = null;
        }
    }

    public static GalleryPageApiParser.Result getGalleryPageApi(EhClient.Task task, OkHttpClient okHttpClient, long j, int i, String str, String str2, String str3) throws Throwable {
        String str4;
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("method", "showpage");
        jSONObject.put("gid", j);
        jSONObject.put("page", i + 1);
        jSONObject.put("imgkey", str);
        jSONObject.put("showkey", str2);
        RequestBody create = RequestBody.create(MEDIA_TYPE_JSON, jSONObject.toString());
        String apiUrl = EhUrl.getApiUrl();
        Headers headers = null;
        String str5 = null;
        String pageUrl = (i <= 0 || str3 == null) ? null : EhUrl.getPageUrl(j, i - 1, str3);
        String origin = EhUrl.getOrigin();
        Log.d(TAG, apiUrl);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(apiUrl, pageUrl, origin).post(create).build());
        if (task != null) {
            task.setCall(newCall);
        }
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                str5 = execute.body().string();
                return GalleryPageApiParser.parse(str5);
            } catch (Throwable th) {
                th = th;
                String str6 = str5;
                headers = headers2;
                str4 = str6;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i2, headers, str4, th);
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
            str4 = null;
        }
    }

    public static UserTagList getWatchedList(EhClient.Task task, OkHttpClient okHttpClient, String str) throws Throwable {
        String str2;
        Headers headers = null;
        String str3 = null;
        if (!Settings.isLogin()) {
            return null;
        }
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str).build());
        task.setCall(newCall);
        int i = -1;
        try {
            Response execute = newCall.execute();
            i = execute.code();
            Headers headers2 = execute.headers();
            try {
                str3 = execute.body().string();
                return MyTagLitParser.parse(str3);
            } catch (Throwable th) {
                th = th;
                String str4 = str3;
                headers = headers2;
                str2 = str4;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str2, th);
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
            str2 = null;
        }
    }

    public static UserTagList addTag(EhClient.Task task, OkHttpClient okHttpClient, String str, TagPushParam tagPushParam) throws Throwable {
        String str2;
        Headers headers;
        if (!Settings.isLogin()) {
            return null;
        }
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str).post(RequestBody.create(MEDIA_TYPE_URLENCODED, tagPushParam.addTagParam())).build());
        task.setCall(newCall);
        int i = -1;
        try {
            Response execute = newCall.execute();
            i = execute.code();
            headers = execute.headers();
            try {
                str2 = execute.body().string();
                try {
                    return MyTagLitParser.parse(str2);
                } catch (Throwable th) {
                    th = th;
                    ExceptionUtils.throwIfFatal(th);
                    throwException(newCall, i, headers, str2, th);
                    return null;
                }
            } catch (Throwable th2) {
                th = th2;
                str2 = null;
            }
        } catch (Throwable th3) {
            th = th3;
            str2 = null;
            headers = null;
        }
    }

    public static UserTagList deleteWatchedTag(EhClient.Task task, OkHttpClient okHttpClient, String str, UserTag userTag) throws Throwable {
        String str2;
        Headers headers;
        if (!Settings.isLogin()) {
            return null;
        }
        Log.d(TAG, str);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(str).post(RequestBody.create(MEDIA_TYPE_URLENCODED, userTag.deleteParam())).build());
        task.setCall(newCall);
        int i = -1;
        try {
            Response execute = newCall.execute();
            i = execute.code();
            headers = execute.headers();
            try {
                str2 = execute.body().string();
                try {
                    return MyTagLitParser.parse(str2);
                } catch (Throwable th) {
                    th = th;
                    ExceptionUtils.throwIfFatal(th);
                    throwException(newCall, i, headers, str2, th);
                    return null;
                }
            } catch (Throwable th2) {
                th = th2;
                str2 = null;
            }
        } catch (Throwable th3) {
            th = th3;
            str2 = null;
            headers = null;
        }
    }

    public static EhNewsDetail getEhNews(EhClient.Task task, OkHttpClient okHttpClient) throws Throwable {
        Headers headers;
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(EhUrl.getEhNewsUrl(), (String) null).build());
        if (task != null) {
            task.setCall(newCall);
        }
        int i = -1;
        try {
            Response execute = newCall.execute();
            i = execute.code();
            headers = execute.headers();
            try {
                if (execute.body() == null) {
                    return null;
                }
                return new EhNewsDetail(execute.body().string());
            } catch (IOException e) {
                e = e;
                ExceptionUtils.throwIfFatal(e);
                throwException(newCall, i, headers, null, e);
                e.printStackTrace();
                return new EhNewsDetail();
            }
        } catch (IOException e2) {
            e = e2;
            headers = null;
        }
    }

    public static HomeDetail getHomeDetail(EhClient.Task task, OkHttpClient okHttpClient) throws Throwable {
        Throwable th;
        int i;
        String str;
        String referer = EhUrl.getReferer();
        String homeUrl = EhUrl.getHomeUrl();
        Log.d(TAG, homeUrl);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(homeUrl, referer).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers = null;
        int i2 = -1;
        try {
            Response execute = newCall.execute();
            i2 = execute.code();
            Headers headers2 = execute.headers();
            try {
                String string = execute.body().string();
                String parse = EhEventParse.parse(string);
                if (parse != null) {
                    EhApplication.getInstance().showEventPane(parse);
                }
                return EhHomeParser.parse(string);
            } catch (Throwable th2) {
                str = null;
                headers = headers2;
                th = th2;
                i = i2;
                ExceptionUtils.throwIfFatal(th);
                throwException(newCall, i, headers, str, th);
                throw th;
            }
        } catch (Throwable th3) {
            th = th3;
            i = i2;
            str = null;
        }
    }

    public static HomeDetail resetLimit(EhClient.Task task, OkHttpClient okHttpClient) throws Throwable {
        Throwable th;
        int i;
        String str;
        Response execute;
        Headers headers;
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("reset_imagelimit", "Reset Limit");
        String referer = EhUrl.getReferer();
        String homeUrl = EhUrl.getHomeUrl();
        Log.d(TAG, homeUrl);
        Call newCall = okHttpClient.newCall(new EhRequestBuilder(homeUrl, referer).post(builder.build()).build());
        if (task != null) {
            task.setCall(newCall);
        }
        Headers headers2 = null;
        int i2 = -1;
        try {
            execute = newCall.execute();
            i2 = execute.code();
            headers = execute.headers();
        } catch (Throwable th2) {
            th = th2;
            i = i2;
            str = null;
        }
        try {
            String string = execute.body().string();
            String parse = EhEventParse.parse(string);
            if (parse != null) {
                EhApplication.getInstance().showEventPane(parse);
            }
            return EhHomeParser.parse(string);
        } catch (Throwable th3) {
            str = null;
            headers2 = headers;
            th = th3;
            i = i2;
            ExceptionUtils.throwIfFatal(th);
            throwException(newCall, i, headers2, str, th);
            throw th;
        }
    }
}