package V2;

import T0.C0606q;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.debridstream.tv.data.home.HomeMetaItem;
import com.google.android.gms.common.internal.ImagesContract;
import com.revenuecat.purchases.subscriberattributes.SubscriberAttributeKt;
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallActivity;
import com.revenuecat.purchases.ui.revenuecatui.activity.PaywallActivityLauncher;
import g3.AbstractC2060b;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import m3.AbstractC2467b;
import n2.AbstractC2612c;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import x4.AbstractC3251q;
import x4.AbstractC3252r;
import x4.AbstractC3253s;
import x4.AbstractC3256v;
import y4.C3274b;

/* JADX INFO: renamed from: V2.m3, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0696m3 {

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public static volatile Context f7937d0;
    public static Integer e0;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final S1.e f7930a = new S1.e("language");

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final S1.e f7932b = new S1.e("preferred_language");

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final S1.e f7934c = new S1.e(TtmlNode.TAG_REGION);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final S1.e f7936d = new S1.e("trakt_enabled");

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final S1.e f7938e = new S1.e("hide_cloud_manager");

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final S1.e f7939f = new S1.e("use_trakt_continue");

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final S1.e f7940g = new S1.e("use_cinemeta_episode_enrichment");

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final S1.e f7941h = new S1.e("official_just_watch");

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public static final S1.e f7942i = new S1.e("hide_size_above_gb");

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final S1.e f7943j = new S1.e("strict_title_matching_enabled");

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final S1.e f7944k = new S1.e("is_4k_removed");
    public static final S1.e l = new S1.e("is_fhd_removed");

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public static final S1.e f7945m = new S1.e("is_hdr_removed");

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public static final S1.e f7946n = new S1.e("is_ai_upscale_removed");

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public static final S1.e f7947o = new S1.e("is_atmos_removed");

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public static final S1.e f7948p = new S1.e("is_dts_removed");

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public static final S1.e f7949q = new S1.e("is_truehd_removed");

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static final S1.e f7950r = new S1.e("is_remux_removed");

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public static final S1.e f7951s = new S1.e("is_sample_removed");

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public static final S1.e f7952t = new S1.e("is_3d_removed");

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public static final S1.e f7953u = new S1.e("is_cam_removed");

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public static final S1.e f7954v = new S1.e("is_dv_removed");

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public static final S1.e f7955w = new S1.e("is_dvp5_removed");

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public static final S1.e f7956x = new S1.e("is_dvp7_removed");

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public static final S1.e f7957y = new S1.e("is_dtshd_removed");

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public static final S1.e f7958z = new S1.e("is_av1_removed");

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public static final S1.e f7906A = new S1.e("is_hevc_removed");

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public static final S1.e f7907B = new S1.e("auto_play");

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public static final S1.e f7908C = new S1.e("prefer_atmos");

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    public static final S1.e f7909D = new S1.e("prefer_hdr");

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public static final S1.e f7910E = new S1.e("prefer_dv");

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public static final S1.e f7911F = new S1.e("real_debrid");

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public static final S1.e f7912G = new S1.e("premiumize");

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    public static final S1.e f7913H = new S1.e("offcloud");

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public static final S1.e f7914I = new S1.e("all_debrid");

    /* JADX INFO: renamed from: J, reason: collision with root package name */
    public static final S1.e f7915J = new S1.e("torbox");

    /* JADX INFO: renamed from: K, reason: collision with root package name */
    public static final S1.e f7916K = new S1.e("debrider");

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public static final S1.e f7917L = new S1.e("match_frame_rate");

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public static final S1.e f7918M = new S1.e("force_dvp7_conversion");

    /* JADX INFO: renamed from: N, reason: collision with root package name */
    public static final S1.e f7919N = new S1.e("convert_dvp7_to_p8");

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    public static final S1.e f7920O = new S1.e("force_dvp8_conversion");

    /* JADX INFO: renamed from: P, reason: collision with root package name */
    public static final S1.e f7921P = new S1.e("trailer_on_open_card_enabled");

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    public static final S1.e f7922Q = new S1.e("trailer_on_open_card_muted");

    /* JADX INFO: renamed from: R, reason: collision with root package name */
    public static final S1.e f7923R = new S1.e("downmix_to_stereo");

    /* JADX INFO: renamed from: S, reason: collision with root package name */
    public static final S1.e f7924S = new S1.e("force_ffmpeg");

    /* JADX INFO: renamed from: T, reason: collision with root package name */
    public static final S1.e f7925T = new S1.e("subtitle_size");

    /* JADX INFO: renamed from: U, reason: collision with root package name */
    public static final S1.e f7926U = new S1.e("subtitle_style");

    /* JADX INFO: renamed from: V, reason: collision with root package name */
    public static final S1.e f7927V = new S1.e("subtitle_offset_level");

    /* JADX INFO: renamed from: W, reason: collision with root package name */
    public static final S1.e f7928W = new S1.e("primary_subtitle_language");
    public static final S1.e X = new S1.e("secondary_subtitle_language");
    public static final S1.e Y = new S1.e("primary_audio_language");

    /* JADX INFO: renamed from: Z, reason: collision with root package name */
    public static final S1.e f7929Z = new S1.e("secondary_audio_language");

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public static final S1.e f7931a0 = new S1.e("disable_japanese_korean");

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public static final S1.e f7933b0 = new S1.e("tv_settings_bg_theme");

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public static final S1.e f7935c0 = new S1.e("tv_settings_bg_theme_schema");

    public static final ArrayList a(List app, List trakt, boolean z6) throws JSONException {
        kotlin.jvm.internal.o.h(app, "app");
        kotlin.jvm.internal.o.h(trakt, "trakt");
        if (!z6 || trakt.isEmpty()) {
            ArrayList arrayList = new ArrayList(AbstractC3253s.G(app, 10));
            Iterator it = app.iterator();
            while (it.hasNext()) {
                arrayList.add(r((JSONObject) it.next()));
            }
            return arrayList;
        }
        if (app.isEmpty()) {
            ArrayList arrayList2 = new ArrayList(AbstractC3253s.G(trakt, 10));
            Iterator it2 = trakt.iterator();
            while (it2.hasNext()) {
                arrayList2.add(r((JSONObject) it2.next()));
            }
            return arrayList2;
        }
        String[] strArr = new String[app.size()];
        HashMap map = new HashMap(((app.size() * 4) / 3) + 1);
        int size = app.size();
        for (int i6 = 0; i6 < size; i6++) {
            String strC = c((JSONObject) app.get(i6));
            strArr[i6] = strC;
            map.put(strC, app.get(i6));
        }
        String[] strArr2 = new String[trakt.size()];
        HashSet hashSet = new HashSet(((trakt.size() * 4) / 3) + 1);
        int size2 = trakt.size();
        for (int i7 = 0; i7 < size2; i7++) {
            String strC2 = c((JSONObject) trakt.get(i7));
            strArr2[i7] = strC2;
            hashSet.add(strC2);
        }
        ArrayList arrayList3 = new ArrayList(app.size() + trakt.size());
        int size3 = trakt.size();
        for (int i8 = 0; i8 < size3; i8++) {
            JSONObject jSONObject = (JSONObject) trakt.get(i8);
            JSONObject jSONObject2 = (JSONObject) map.get(strArr2[i8]);
            if (jSONObject2 == null) {
                arrayList3.add(jSONObject);
            } else {
                JSONObject jSONObjectO = o(jSONObject2);
                String strOptString = jSONObject.optString("sortDate");
                kotlin.jvm.internal.o.e(strOptString);
                if (strOptString.length() > 0) {
                    jSONObjectO.put("sortDate", strOptString);
                }
                arrayList3.add(jSONObjectO);
            }
        }
        int size4 = app.size();
        for (int i9 = 0; i9 < size4; i9++) {
            if (!AbstractC3251q.Y(hashSet, strArr[i9])) {
                arrayList3.add(app.get(i9));
            }
        }
        AbstractC3256v.J(arrayList3, new C0702o0(2));
        ArrayList arrayList4 = new ArrayList(AbstractC3253s.G(arrayList3, 10));
        Iterator it3 = arrayList3.iterator();
        while (it3.hasNext()) {
            arrayList4.add(r((JSONObject) it3.next()));
        }
        return arrayList4;
    }

    public static final ArrayList b(String profileKey) {
        kotlin.jvm.internal.o.h(profileKey, "profileKey");
        Y4.c0 c0Var = C0706p0.f7996a;
        return a(C0706p0.b(profileKey), (List) ((Y4.c0) C0706p0.f8003h.f8871a).getValue(), ((n3) ((Y4.c0) u3.f8112c.f8871a).getValue()).f7972b.f7759c && profileKey.equals("main"));
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x003b A[PHI: r0
      0x003b: PHI (r0v2 java.lang.String) = (r0v1 java.lang.String), (r0v1 java.lang.String), (r0v7 java.lang.String) binds: [B:3:0x000c, B:5:0x0014, B:11:0x0038] A[DONT_GENERATE, DONT_INLINE]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final String c(JSONObject jSONObject) {
        String str = "movie";
        String strOptString = jSONObject.optString("type", "movie");
        if (kotlin.jvm.internal.o.c(strOptString, "movie") || kotlin.jvm.internal.o.c(strOptString, "tv")) {
            str = strOptString;
        } else {
            kotlin.jvm.internal.o.e(strOptString);
            if (strOptString.length() != 0) {
                strOptString = S4.p.o1(strOptString).toString().toLowerCase(Locale.ROOT);
                kotlin.jvm.internal.o.g(strOptString, "toLowerCase(...)");
                if (!S4.p.Q0(strOptString)) {
                }
            }
        }
        return str + "-" + jSONObject.optInt("tmdbId", 0);
    }

    public static HomeMetaItem d(JSONObject jSONObject) {
        int iOptInt = jSONObject.optInt("tmdbId", 0);
        String strP = A0.a.p(jSONObject, "type", "", "optString(...)");
        Locale locale = Locale.ROOT;
        String lowerCase = strP.toLowerCase(locale);
        kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
        if (iOptInt <= 0) {
            return null;
        }
        if (!lowerCase.equals("movie") && !lowerCase.equals("tv")) {
            return null;
        }
        String strOptString = jSONObject.optString("id");
        kotlin.jvm.internal.o.g(strOptString, "optString(...)");
        String strOptString2 = jSONObject.optString("title");
        kotlin.jvm.internal.o.g(strOptString2, "optString(...)");
        String strOptString3 = jSONObject.optString("overview");
        kotlin.jvm.internal.o.g(strOptString3, "optString(...)");
        String strOptString4 = jSONObject.optString("year");
        kotlin.jvm.internal.o.g(strOptString4, "optString(...)");
        double dOptDouble = jSONObject.optDouble("rating");
        String strOptString5 = jSONObject.optString("posterUrl");
        if (S4.p.Q0(strOptString5)) {
            strOptString5 = null;
        }
        String strOptString6 = jSONObject.optString("backdropUrl");
        if (S4.p.Q0(strOptString6)) {
            strOptString6 = null;
        }
        String strOptString7 = jSONObject.optString("logoUrl");
        if (S4.p.Q0(strOptString7)) {
            strOptString7 = null;
        }
        String strOptString8 = jSONObject.optString("certificate");
        kotlin.jvm.internal.o.g(strOptString8, "optString(...)");
        String strI = W0.e.i(strOptString8);
        int iOptInt2 = jSONObject.optInt("runTimeMinutes");
        String strOptString9 = jSONObject.optString("primaryGenre");
        kotlin.jvm.internal.o.g(strOptString9, "optString(...)");
        String strOptString10 = jSONObject.optString("secondaryGenre");
        kotlin.jvm.internal.o.g(strOptString10, "optString(...)");
        List listH = h(jSONObject.optJSONArray("originCountries"));
        String strOptString11 = jSONObject.optString("originalLanguage", "");
        kotlin.jvm.internal.o.g(strOptString11, "optString(...)");
        String lowerCase2 = S4.p.o1(strOptString11).toString().toLowerCase(locale);
        kotlin.jvm.internal.o.g(lowerCase2, "toLowerCase(...)");
        return new HomeMetaItem(strOptString, iOptInt, lowerCase, strOptString2, strOptString3, strOptString4, dOptDouble, strOptString5, strOptString6, strOptString7, strI, iOptInt2, strOptString9, strOptString10, listH, lowerCase2);
    }

    /* JADX WARN: Removed duplicated region for block: B:54:0x016d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static Q2 e(JSONObject jSONObject) {
        P2 p22;
        g3.n nVar;
        Long l6;
        Integer numValueOf;
        String strP = A0.a.p(jSONObject, ImagesContract.URL, "", "optString(...)");
        boolean zOptBoolean = jSONObject.optBoolean("pendingOpenLinksPanelForManualPick", false);
        if (S4.p.Q0(strP) && !zOptBoolean) {
            return null;
        }
        JSONObject jSONObjectOptJSONObject = jSONObject.optJSONObject("openSubtitlesContext");
        if (jSONObjectOptJSONObject != null) {
            int iOptInt = jSONObjectOptJSONObject.optInt("tmdbId", 0);
            String strOptString = jSONObjectOptJSONObject.optString("imdbId");
            String str = S4.p.Q0(strOptString) ? null : strOptString;
            boolean zOptBoolean2 = jSONObjectOptJSONObject.optBoolean("isTv", false);
            int iOptInt2 = jSONObjectOptJSONObject.optInt("season", 1);
            int iOptInt3 = jSONObjectOptJSONObject.optInt("episode", 1);
            Object objOpt = jSONObjectOptJSONObject.opt("episodeTmdbId");
            if (objOpt != null) {
                numValueOf = (!objOpt.equals(JSONObject.NULL) && (objOpt instanceof Number)) ? Integer.valueOf(((Number) objOpt).intValue()) : null;
            } else {
                numValueOf = null;
            }
            p22 = new P2(iOptInt, str, zOptBoolean2, iOptInt2, iOptInt3, numValueOf);
        } else {
            p22 = null;
        }
        JSONObject jSONObjectOptJSONObject2 = jSONObject.optJSONObject("progressMeta");
        if (jSONObjectOptJSONObject2 != null) {
            int iOptInt4 = jSONObjectOptJSONObject2.optInt("tmdbId", 0);
            String strP2 = A0.a.p(jSONObjectOptJSONObject2, "type", "movie", "optString(...)");
            Locale locale = Locale.ROOT;
            String lowerCase = strP2.toLowerCase(locale);
            kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
            String str2 = S4.p.Q0(lowerCase) ? "movie" : lowerCase;
            String strOptString2 = jSONObjectOptJSONObject2.optString("title");
            kotlin.jvm.internal.o.g(strOptString2, "optString(...)");
            String strOptString3 = jSONObjectOptJSONObject2.optString("overview");
            kotlin.jvm.internal.o.g(strOptString3, "optString(...)");
            String strOptString4 = jSONObjectOptJSONObject2.optString("year");
            kotlin.jvm.internal.o.g(strOptString4, "optString(...)");
            double dOptDouble = jSONObjectOptJSONObject2.optDouble("rating");
            String strOptString5 = jSONObjectOptJSONObject2.optString("posterUrl");
            String str3 = S4.p.Q0(strOptString5) ? null : strOptString5;
            String strOptString6 = jSONObjectOptJSONObject2.optString("backdropUrl");
            String str4 = S4.p.Q0(strOptString6) ? null : strOptString6;
            String strOptString7 = jSONObjectOptJSONObject2.optString("logoUrl");
            String str5 = S4.p.Q0(strOptString7) ? null : strOptString7;
            String strOptString8 = jSONObjectOptJSONObject2.optString("certificate");
            kotlin.jvm.internal.o.g(strOptString8, "optString(...)");
            String strI = W0.e.i(strOptString8);
            int iOptInt5 = jSONObjectOptJSONObject2.optInt("runTimeMinutes");
            String strOptString9 = jSONObjectOptJSONObject2.optString("primaryGenre");
            kotlin.jvm.internal.o.g(strOptString9, "optString(...)");
            List listH = h(jSONObjectOptJSONObject2.optJSONArray("originCountries"));
            String strOptString10 = jSONObjectOptJSONObject2.optString("originalLanguage", "");
            kotlin.jvm.internal.o.g(strOptString10, "optString(...)");
            String lowerCase2 = S4.p.o1(strOptString10).toString().toLowerCase(locale);
            kotlin.jvm.internal.o.g(lowerCase2, "toLowerCase(...)");
            nVar = new g3.n(iOptInt4, str2, strOptString2, strOptString3, strOptString4, dOptDouble, str3, str4, str5, strI, iOptInt5, strOptString9, listH, lowerCase2, null);
        } else {
            nVar = null;
        }
        Object objOpt2 = jSONObject.opt("initialSeekPositionMs");
        if (objOpt2 == null || objOpt2.equals(JSONObject.NULL) || !(objOpt2 instanceof Number)) {
            l6 = null;
        } else {
            long jLongValue = ((Number) objOpt2).longValue();
            Long lValueOf = Long.valueOf(jLongValue);
            if (jLongValue > 0) {
                l6 = lValueOf;
            }
        }
        String strOptString11 = jSONObject.optString("currentLinkHash");
        String str6 = S4.p.Q0(strOptString11) ? null : strOptString11;
        String strOptString12 = jSONObject.optString("currentDebridProviderKey");
        String str7 = S4.p.Q0(strOptString12) ? null : strOptString12;
        String strOptString13 = jSONObject.optString("playbackTitleOverride");
        return new Q2(strP, str6, str7, p22, S4.p.Q0(strOptString13) ? null : strOptString13, nVar, zOptBoolean, l6, 1584);
    }

    /* JADX WARN: Removed duplicated region for block: B:40:0x00b1  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final C0654e1 f(JSONObject jSONObject, int i6) {
        Long lValueOf;
        int iV;
        double dOptDouble = jSONObject.optDouble("progress", Double.NaN);
        Long lValueOf2 = null;
        if (!Double.isNaN(dOptDouble) && dOptDouble >= 0.0d) {
            int iOptInt = jSONObject.optInt("season", 0);
            Integer numValueOf = Integer.valueOf(iOptInt);
            if (iOptInt <= 0) {
                numValueOf = null;
            }
            int iOptInt2 = jSONObject.optInt("episode", 0);
            Integer numValueOf2 = Integer.valueOf(iOptInt2);
            if (iOptInt2 <= 0) {
                numValueOf2 = null;
            }
            long jOptLong = jSONObject.optLong("durationSeconds", 0L);
            if (jOptLong <= 0) {
                int iV2 = L4.a.v(L4.a.c0(dOptDouble), 0, 100);
                if (iV2 < 100) {
                    Integer numValueOf3 = Integer.valueOf(i6);
                    if (i6 <= 0) {
                        numValueOf3 = null;
                    }
                    if (numValueOf3 != null) {
                        long jIntValue = ((long) numValueOf3.intValue()) * 60000;
                        lValueOf = Long.valueOf(jIntValue);
                        if (jIntValue <= 0) {
                            lValueOf = null;
                        }
                    }
                    if (lValueOf != null) {
                        long jLongValue = lValueOf.longValue();
                        long j4 = (long) ((((double) iV2) / 100.0d) * jLongValue);
                        long j6 = jLongValue - 1;
                        lValueOf2 = Long.valueOf(L4.a.x(j4, 0L, j6 < 0 ? 0L : j6));
                    }
                    return new C0654e1(iV2, lValueOf2, numValueOf, numValueOf2);
                }
            } else if (dOptDouble >= 60.0d && (iV = L4.a.v(L4.a.c0((dOptDouble / jOptLong) * 100.0d), 0, 100)) < 100) {
                long j7 = (jOptLong * 1000) - 1;
                return new C0654e1(iV, Long.valueOf(L4.a.x((long) (dOptDouble * 1000.0d), 0L, j7 < 0 ? 0L : j7)), numValueOf, numValueOf2);
            }
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x0031  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final JSONObject g(int i6, String type, List app, List trakt, boolean z6, String profileKey) {
        kotlin.jvm.internal.o.h(type, "type");
        kotlin.jvm.internal.o.h(app, "app");
        kotlin.jvm.internal.o.h(trakt, "trakt");
        kotlin.jvm.internal.o.h(profileKey, "profileKey");
        if (i6 <= 0) {
            return null;
        }
        if (!type.equals("movie") && !type.equals("tv")) {
            if (type.length() == 0) {
                type = "movie";
            } else {
                type = S4.p.o1(type).toString().toLowerCase(Locale.ROOT);
                kotlin.jvm.internal.o.g(type, "toLowerCase(...)");
                if (S4.p.Q0(type)) {
                }
            }
        }
        int size = app.size();
        for (int i7 = 0; i7 < size; i7++) {
            JSONObject jSONObject = (JSONObject) app.get(i7);
            if (jSONObject.optInt("tmdbId", 0) == i6) {
                String strOptString = jSONObject.optString("type", "movie");
                if (!kotlin.jvm.internal.o.c(strOptString, type)) {
                    kotlin.jvm.internal.o.e(strOptString);
                    String lowerCase = S4.p.o1(strOptString).toString().toLowerCase(Locale.ROOT);
                    kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
                    if (S4.p.Q0(lowerCase)) {
                        lowerCase = "movie";
                    }
                    if (lowerCase.equals(type)) {
                    }
                }
                return AbstractC2060b.b(jSONObject, profileKey);
            }
        }
        if (!z6 || trakt.isEmpty()) {
            return null;
        }
        int size2 = trakt.size();
        for (int i8 = 0; i8 < size2; i8++) {
            JSONObject jSONObject2 = (JSONObject) trakt.get(i8);
            if (jSONObject2.optInt("tmdbId", 0) == i6) {
                String strOptString2 = jSONObject2.optString("type", "movie");
                if (!kotlin.jvm.internal.o.c(strOptString2, type)) {
                    kotlin.jvm.internal.o.e(strOptString2);
                    String lowerCase2 = S4.p.o1(strOptString2).toString().toLowerCase(Locale.ROOT);
                    kotlin.jvm.internal.o.g(lowerCase2, "toLowerCase(...)");
                    if (S4.p.Q0(lowerCase2)) {
                        lowerCase2 = "movie";
                    }
                    if (lowerCase2.equals(type)) {
                    }
                }
                return AbstractC2060b.b(jSONObject2, profileKey);
            }
        }
        return null;
    }

    public static List h(JSONArray jSONArray) {
        if (jSONArray == null || jSONArray.length() == 0) {
            return x4.y.f26065a;
        }
        C3274b c3274bK = AbstractC2612c.k();
        int length = jSONArray.length();
        for (int i6 = 0; i6 < length; i6++) {
            String strOptString = jSONArray.optString(i6, "");
            kotlin.jvm.internal.o.g(strOptString, "optString(...)");
            String upperCase = S4.p.o1(strOptString).toString().toUpperCase(Locale.ROOT);
            kotlin.jvm.internal.o.g(upperCase, "toUpperCase(...)");
            if (upperCase.length() == 2) {
                c3274bK.add(upperCase);
            }
        }
        return AbstractC2612c.e(c3274bK);
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:56:0x0119  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static List i(String str) {
        Object objD;
        try {
            objD = new JSONArray(str);
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        if (w4.n.a(objD) != null) {
            return x4.y.f26065a;
        }
        JSONArray jSONArray = (JSONArray) objD;
        ArrayList arrayList = new ArrayList(jSONArray.length());
        int length = jSONArray.length();
        for (int i6 = 0; i6 < length; i6++) {
            JSONObject jSONObjectOptJSONObject = jSONArray.optJSONObject(i6);
            if (jSONObjectOptJSONObject != null) {
                String strOptString = jSONObjectOptJSONObject.optString("id");
                kotlin.jvm.internal.o.g(strOptString, "optString(...)");
                String string = S4.p.o1(strOptString).toString();
                String strOptString2 = jSONObjectOptJSONObject.optString("title");
                kotlin.jvm.internal.o.g(strOptString2, "optString(...)");
                String string2 = S4.p.o1(strOptString2).toString();
                String strOptString3 = jSONObjectOptJSONObject.optString("catalogType");
                kotlin.jvm.internal.o.g(strOptString3, "optString(...)");
                String lowerCase = S4.p.o1(strOptString3).toString().toLowerCase(Locale.ROOT);
                kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
                String strOptString4 = jSONObjectOptJSONObject.optString(ImagesContract.URL);
                kotlin.jvm.internal.o.g(strOptString4, "optString(...)");
                String string3 = S4.p.o1(strOptString4).toString();
                String strOptString5 = jSONObjectOptJSONObject.optString("traktSortBy");
                kotlin.jvm.internal.o.g(strOptString5, "optString(...)");
                String string4 = S4.p.o1(strOptString5).toString();
                AbstractC0742y1 c0734w1 = null;
                if (string4.length() == 0) {
                    string4 = null;
                }
                int iOptInt = jSONObjectOptJSONObject.optInt("minRating", 0);
                Integer numValueOf = Integer.valueOf(iOptInt);
                if (iOptInt <= 0) {
                    numValueOf = null;
                }
                int iOptInt2 = jSONObjectOptJSONObject.optInt("minYear", 0);
                Integer numValueOf2 = Integer.valueOf(iOptInt2);
                if (iOptInt2 <= 0) {
                    numValueOf2 = null;
                }
                boolean zOptBoolean = jSONObjectOptJSONObject.optBoolean("inPlace", false);
                if (string.length() != 0 && string2.length() != 0) {
                    switch (lowerCase.hashCode()) {
                        case -1184365990:
                            if (lowerCase.equals("continuewatching")) {
                                c0734w1 = C0726u1.f8101a;
                            }
                            break;
                        case -1067147826:
                            if (lowerCase.equals("trakttv")) {
                                if (string3.length() != 0) {
                                    c0734w1 = new C0738x1(string, string2, string3, string4, numValueOf, numValueOf2, zOptBoolean);
                                }
                            }
                            break;
                        case -59515804:
                            if (lowerCase.equals("traktmovie")) {
                            }
                            break;
                        case 5573730:
                            if (lowerCase.equals("tmdbtvdiscover") && string3.length() != 0) {
                                c0734w1 = new C0734w1(string, string2, string3, zOptBoolean);
                            }
                            break;
                        case 110621260:
                            if (lowerCase.equals("trakt")) {
                            }
                            break;
                        case 1867728834:
                            if (lowerCase.equals("tmdbmoviediscover") && string3.length() != 0) {
                                c0734w1 = new C0730v1(string, string2, string3, zOptBoolean);
                            }
                            break;
                    }
                }
                if (c0734w1 != null) {
                    arrayList.add(c0734w1);
                }
            }
        }
        return arrayList;
    }

    public static void j(LinkedHashMap linkedHashMap) throws JSONException {
        Context context = f7937d0;
        if (context == null) {
            return;
        }
        JSONObject jSONObject = new JSONObject();
        for (Map.Entry entry : linkedHashMap.entrySet()) {
            String str = (String) entry.getKey();
            List list = (List) entry.getValue();
            JSONArray jSONArray = new JSONArray();
            Iterator it = list.iterator();
            while (it.hasNext()) {
                jSONArray.put((JSONObject) it.next());
            }
            jSONObject.put(str, jSONArray);
        }
        context.getSharedPreferences("debridstream_app_progress_cache", 0).edit().putString("app_continue_watching_by_profile_json", jSONObject.toString()).apply();
    }

    public static void k(LinkedHashMap linkedHashMap) throws JSONException {
        Context context = f7937d0;
        if (context == null) {
            return;
        }
        JSONObject jSONObject = new JSONObject();
        for (Map.Entry entry : linkedHashMap.entrySet()) {
            String str = (String) entry.getKey();
            List list = (List) entry.getValue();
            JSONArray jSONArray = new JSONArray();
            Iterator it = list.iterator();
            while (it.hasNext()) {
                jSONArray.put((JSONObject) it.next());
            }
            jSONObject.put(str, jSONArray);
        }
        context.getSharedPreferences("debridstream_app_progress_cache", 0).edit().putString("app_watchlist_by_profile_json", jSONObject.toString()).apply();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r1v1 */
    /* JADX WARN: Type inference failed for: r1v3 */
    /* JADX WARN: Type inference failed for: r1v4 */
    /* JADX WARN: Type inference failed for: r2v3, types: [w4.m] */
    /* JADX WARN: Type inference failed for: r2v4, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r2v5, types: [java.util.LinkedHashMap, java.util.Map] */
    public static Map l() {
        Object objD;
        ?? D3;
        Context context = f7937d0;
        x4.z zVar = x4.z.f26066a;
        if (context == null) {
            return zVar;
        }
        try {
            objD = context.getSharedPreferences("debridstream_app_progress_cache", 0).getString("app_continue_watching_by_profile_json", null);
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        String str = (String) (objD instanceof w4.m ? null : objD);
        if (str == null || S4.p.Q0(str)) {
            return zVar;
        }
        try {
            JSONObject jSONObject = new JSONObject(str);
            D3 = new LinkedHashMap();
            Iterator<String> itKeys = jSONObject.keys();
            while (itKeys.hasNext()) {
                String next = itKeys.next();
                JSONArray jSONArrayOptJSONArray = jSONObject.optJSONArray(next);
                if (jSONArrayOptJSONArray != null) {
                    ArrayList arrayList = new ArrayList(jSONArrayOptJSONArray.length());
                    int length = jSONArrayOptJSONArray.length();
                    for (int i6 = 0; i6 < length; i6++) {
                        JSONObject jSONObjectOptJSONObject = jSONArrayOptJSONArray.optJSONObject(i6);
                        if (jSONObjectOptJSONObject != null) {
                            arrayList.add(jSONObjectOptJSONObject);
                        }
                    }
                    D3.put(next, arrayList);
                }
            }
        } catch (Throwable th2) {
            D3 = AbstractC2467b.d(th2);
        }
        ?? r12 = zVar;
        if (w4.n.a(D3) == null) {
            r12 = D3;
        }
        return (Map) r12;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r1v1 */
    /* JADX WARN: Type inference failed for: r1v3 */
    /* JADX WARN: Type inference failed for: r1v4 */
    /* JADX WARN: Type inference failed for: r2v3, types: [w4.m] */
    /* JADX WARN: Type inference failed for: r2v4, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r2v5, types: [java.util.LinkedHashMap, java.util.Map] */
    public static Map m() {
        Object objD;
        ?? D3;
        Context context = f7937d0;
        x4.z zVar = x4.z.f26066a;
        if (context == null) {
            return zVar;
        }
        try {
            objD = context.getSharedPreferences("debridstream_app_progress_cache", 0).getString("app_watchlist_by_profile_json", null);
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        String str = (String) (objD instanceof w4.m ? null : objD);
        if (str == null || S4.p.Q0(str)) {
            return zVar;
        }
        try {
            JSONObject jSONObject = new JSONObject(str);
            D3 = new LinkedHashMap();
            Iterator<String> itKeys = jSONObject.keys();
            while (itKeys.hasNext()) {
                String next = itKeys.next();
                JSONArray jSONArrayOptJSONArray = jSONObject.optJSONArray(next);
                if (jSONArrayOptJSONArray != null) {
                    ArrayList arrayList = new ArrayList(jSONArrayOptJSONArray.length());
                    int length = jSONArrayOptJSONArray.length();
                    for (int i6 = 0; i6 < length; i6++) {
                        JSONObject jSONObjectOptJSONObject = jSONArrayOptJSONArray.optJSONObject(i6);
                        if (jSONObjectOptJSONObject != null) {
                            arrayList.add(jSONObjectOptJSONObject);
                        }
                    }
                    D3.put(next, arrayList);
                }
            }
        } catch (Throwable th2) {
            D3 = AbstractC2467b.d(th2);
        }
        ?? r12 = zVar;
        if (w4.n.a(D3) == null) {
            r12 = D3;
        }
        return (Map) r12;
    }

    public static void n(androidx.lifecycle.U u6, HomeMetaItem homeMetaItem) throws JSONException {
        kotlin.jvm.internal.o.h(u6, "<this>");
        if (homeMetaItem == null) {
            C0606q c0606q = u6.f12136b;
            ((LinkedHashMap) c0606q.f6543b).remove("nav_details_item_json");
            ((LinkedHashMap) c0606q.f6545d).remove("nav_details_item_json");
            ((LinkedHashMap) c0606q.f6546e).remove("nav_details_item_json");
            if (u6.f12135a.remove("nav_details_item_json") != null) {
                throw new ClassCastException();
            }
            return;
        }
        JSONObject jSONObjectPut = new JSONObject().put("id", homeMetaItem.getId()).put("tmdbId", homeMetaItem.getTmdbId()).put("type", homeMetaItem.getType()).put("title", homeMetaItem.getTitle()).put("overview", homeMetaItem.getOverview()).put("year", homeMetaItem.getYear()).put("rating", homeMetaItem.getRating()).put("posterUrl", homeMetaItem.getPosterUrl()).put("backdropUrl", homeMetaItem.getBackdropUrl()).put("logoUrl", homeMetaItem.getLogoUrl()).put("certificate", homeMetaItem.getCertificate()).put("runTimeMinutes", homeMetaItem.getRunTimeMinutes()).put("primaryGenre", homeMetaItem.getPrimaryGenre()).put("secondaryGenre", homeMetaItem.getSecondaryGenre());
        JSONArray jSONArray = new JSONArray();
        Iterator<T> it = homeMetaItem.getOriginCountries().iterator();
        while (it.hasNext()) {
            jSONArray.put((String) it.next());
        }
        JSONObject jSONObjectPut2 = jSONObjectPut.put("originCountries", jSONArray).put("originalLanguage", homeMetaItem.getOriginalLanguage());
        kotlin.jvm.internal.o.g(jSONObjectPut2, "put(...)");
        u6.b(jSONObjectPut2.toString(), "nav_details_item_json");
    }

    public static final JSONObject o(JSONObject jSONObject) throws JSONException {
        JSONObject jSONObject2 = new JSONObject();
        Iterator<String> itKeys = jSONObject.keys();
        while (itKeys.hasNext()) {
            String next = itKeys.next();
            jSONObject2.putOpt(next, jSONObject.opt(next));
        }
        return jSONObject2;
    }

    /* JADX WARN: Removed duplicated region for block: B:122:? A[RETURN, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:70:0x0122 A[Catch: all -> 0x00a4, TryCatch #2 {all -> 0x00a4, blocks: (B:33:0x0074, B:37:0x0087, B:39:0x0096, B:49:0x00bb, B:44:0x00a7, B:46:0x00ae, B:52:0x00c0, B:77:0x013a, B:53:0x00c9, B:55:0x00d6, B:57:0x00df, B:64:0x00f3, B:66:0x0106, B:68:0x0115, B:73:0x0130, B:70:0x0122, B:76:0x0135, B:60:0x00ec), top: B:101:0x0074 }] */
    /* JADX WARN: Removed duplicated region for block: B:83:0x014a  */
    /* JADX WARN: Removed duplicated region for block: B:99:0x0155 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void p(Activity activity) {
        Object objD;
        Object objD2;
        Object objD3;
        Method[] methods;
        int length;
        int i6;
        Method method;
        Constructor<?> constructor;
        Method method2;
        boolean z6;
        boolean z7 = true;
        Method method3 = null;
        try {
            Method[] methods2 = Class.forName("com.revenuecat.purchases.ui.revenuecatui.RevenueCatUI").getMethods();
            kotlin.jvm.internal.o.e(methods2);
            int length2 = methods2.length;
            int i7 = 0;
            while (true) {
                if (i7 >= length2) {
                    method2 = null;
                    break;
                }
                method2 = methods2[i7];
                if (S4.w.t0(method2.getName(), "showPaywall", true) || S4.w.t0(method2.getName(), "presentPaywall", true)) {
                    if (method2.getParameterTypes().length == 1 && Activity.class.isAssignableFrom(method2.getParameterTypes()[0])) {
                        break;
                    }
                }
                i7++;
            }
            if (method2 != null) {
                method2.invoke(null, activity);
                z6 = true;
            } else {
                z6 = false;
            }
            objD = Boolean.valueOf(z6);
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        if (w4.n.a(objD) != null) {
            objD = Boolean.FALSE;
        }
        if (((Boolean) objD).booleanValue()) {
            return;
        }
        try {
            methods = PaywallActivityLauncher.class.getMethods();
            kotlin.jvm.internal.o.g(methods, "getMethods(...)");
            length = methods.length;
            i6 = 0;
        } catch (Throwable th2) {
            objD2 = AbstractC2467b.d(th2);
        }
        while (true) {
            if (i6 >= length) {
                method = null;
                break;
            }
            method = methods[i6];
            String name = method.getName();
            kotlin.jvm.internal.o.g(name, "getName(...)");
            if (S4.p.D0(name, "launch", true)) {
                if (method.getParameterTypes().length == 1) {
                    continue;
                }
                i6++;
            } else {
                String name2 = method.getName();
                kotlin.jvm.internal.o.g(name2, "getName(...)");
                if (!S4.p.D0(name2, "show", true)) {
                    continue;
                    i6++;
                } else if (method.getParameterTypes().length == 1 && Activity.class.isAssignableFrom(method.getParameterTypes()[0])) {
                    break;
                } else {
                    i6++;
                }
            }
            if (w4.n.a(objD2) != null) {
                objD2 = Boolean.FALSE;
            }
            if (((Boolean) objD2).booleanValue()) {
                return;
            }
            try {
                PaywallActivity.Companion companion = PaywallActivity.Companion;
                activity.startActivity(new Intent(activity, (Class<?>) PaywallActivity.class));
                objD3 = Boolean.TRUE;
            } catch (Throwable th3) {
                objD3 = AbstractC2467b.d(th3);
            }
            if (w4.n.a(objD3) != null) {
                objD3 = Boolean.FALSE;
            }
            return;
        }
        if (method != null) {
            method.invoke(null, activity);
        } else {
            Constructor<?>[] constructors = PaywallActivityLauncher.class.getConstructors();
            kotlin.jvm.internal.o.g(constructors, "getConstructors(...)");
            int length3 = constructors.length;
            int i8 = 0;
            while (true) {
                if (i8 >= length3) {
                    constructor = null;
                    break;
                }
                constructor = constructors[i8];
                if (constructor.getParameterTypes().length == 1 && Activity.class.isAssignableFrom(constructor.getParameterTypes()[0])) {
                    break;
                } else {
                    i8++;
                }
            }
            if (constructor == null) {
                z7 = false;
            } else {
                Object objNewInstance = constructor.newInstance(activity);
                Method[] methods3 = PaywallActivityLauncher.class.getMethods();
                kotlin.jvm.internal.o.g(methods3, "getMethods(...)");
                int length4 = methods3.length;
                int i9 = 0;
                while (true) {
                    if (i9 >= length4) {
                        break;
                    }
                    Method method4 = methods3[i9];
                    String name3 = method4.getName();
                    kotlin.jvm.internal.o.g(name3, "getName(...)");
                    if (!S4.p.D0(name3, "launch", true)) {
                        String name4 = method4.getName();
                        kotlin.jvm.internal.o.g(name4, "getName(...)");
                        if (S4.p.D0(name4, "show", true)) {
                            Class<?>[] parameterTypes = method4.getParameterTypes();
                            kotlin.jvm.internal.o.g(parameterTypes, "getParameterTypes(...)");
                            if (parameterTypes.length == 0) {
                                method3 = method4;
                                break;
                            }
                        } else {
                            continue;
                        }
                        i9++;
                    }
                }
                if (method3 == null) {
                    z7 = false;
                } else {
                    method3.invoke(objNewInstance, new Object[0]);
                }
            }
            if (w4.n.a(objD2) != null) {
            }
            if (((Boolean) objD2).booleanValue()) {
            }
        }
        objD2 = Boolean.valueOf(z7);
        if (w4.n.a(objD2) != null) {
        }
        if (((Boolean) objD2).booleanValue()) {
        }
    }

    public static final List q(List entries) {
        kotlin.jvm.internal.o.h(entries, "entries");
        if (entries.size() >= 2) {
            ArrayList arrayList = new ArrayList();
            for (Object obj : entries) {
                AbstractC0742y1 abstractC0742y1 = (AbstractC0742y1) obj;
                if (!abstractC0742y1.b() && !S4.w.A0(abstractC0742y1.a(), "custom-", false)) {
                    arrayList.add(obj);
                }
            }
            ArrayList arrayListE0 = AbstractC3251q.E0(arrayList);
            if (arrayListE0.size() >= 2) {
                long jNanoTime = System.nanoTime();
                int i6 = (int) jNanoTime;
                int i7 = (int) (jNanoTime >> 32);
                int i8 = ~i6;
                N4.e eVar = new N4.e();
                eVar.f5274b = i6;
                eVar.f5275c = i7;
                eVar.f5276d = 0;
                eVar.f5277e = 0;
                eVar.f5278f = i8;
                eVar.f5279j = (i6 << 10) ^ (i7 >>> 4);
                if ((i7 | i6 | i8) == 0) {
                    throw new IllegalArgumentException("Initial state must have at least one non-zero element.");
                }
                for (int i9 = 0; i9 < 64; i9++) {
                    eVar.b();
                }
                for (int iA = AbstractC3252r.A(arrayListE0); iA > 0; iA--) {
                    int iD = eVar.d(0, iA + 1);
                    arrayListE0.set(iD, arrayListE0.set(iA, arrayListE0.get(iD)));
                }
                ArrayList arrayList2 = new ArrayList(AbstractC3253s.G(entries, 10));
                Iterator it = entries.iterator();
                int i10 = 0;
                while (it.hasNext()) {
                    AbstractC0742y1 abstractC0742y12 = (AbstractC0742y1) it.next();
                    if (!abstractC0742y12.b() && !S4.w.A0(abstractC0742y12.a(), "custom-", false)) {
                        abstractC0742y12 = (AbstractC0742y1) arrayListE0.get(i10);
                        i10++;
                    }
                    arrayList2.add(abstractC0742y12);
                }
                return arrayList2;
            }
        }
        return entries;
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x00a4 A[PHI: r3
      0x00a4: PHI (r3v5 java.lang.String) = 
      (r3v4 java.lang.String)
      (r3v46 java.lang.String)
      (r3v49 java.lang.String)
      (r3v51 java.lang.String)
      (r3v52 java.lang.String)
     binds: [B:17:0x005e, B:22:0x0071, B:27:0x0084, B:32:0x0095, B:34:0x00a2] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:49:0x00d8 A[PHI: r3
      0x00d8: PHI (r3v9 java.lang.String) = (r3v8 java.lang.String), (r3v40 java.lang.String), (r3v41 java.lang.String) binds: [B:41:0x00b8, B:46:0x00c9, B:48:0x00d6] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0154  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x0159  */
    /* JADX WARN: Removed duplicated region for block: B:71:0x015c  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x0163  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final HomeMetaItem r(JSONObject jSONObject) {
        String str;
        String str2;
        int i6;
        int iOptInt;
        int length;
        List list;
        int i7;
        char cCharAt;
        kotlin.jvm.internal.o.h(jSONObject, "<this>");
        int i8 = 0;
        int iOptInt2 = jSONObject.optInt("tmdbId", 0);
        String strOptString = jSONObject.optString("type", "movie");
        String str3 = S4.p.Q0(strOptString) ? "movie" : strOptString;
        String strOptString2 = jSONObject.optString(SubscriberAttributeKt.JSON_NAME_KEY);
        kotlin.jvm.internal.o.e(strOptString2);
        if (S4.p.Q0(strOptString2)) {
            strOptString2 = null;
        }
        if (strOptString2 == null) {
            strOptString2 = str3 + "-" + iOptInt2;
        }
        String strOptString3 = jSONObject.optString("posterUrl", "");
        kotlin.jvm.internal.o.e(strOptString3);
        if (strOptString3.length() <= 0) {
            strOptString3 = null;
        }
        if (strOptString3 == null) {
            strOptString3 = jSONObject.optString("poster", "");
            kotlin.jvm.internal.o.e(strOptString3);
            if (strOptString3.length() <= 0) {
                strOptString3 = null;
            }
            if (strOptString3 == null) {
                strOptString3 = jSONObject.optString("posterHD", "");
                kotlin.jvm.internal.o.e(strOptString3);
                if (strOptString3.length() <= 0) {
                    strOptString3 = null;
                }
                if (strOptString3 == null) {
                    strOptString3 = jSONObject.optString("backdrop", "");
                    kotlin.jvm.internal.o.e(strOptString3);
                    if (strOptString3.length() <= 0) {
                        strOptString3 = null;
                    }
                    if (strOptString3 == null) {
                        strOptString3 = jSONObject.optString("backdropSD", "");
                        kotlin.jvm.internal.o.e(strOptString3);
                        str = strOptString3.length() > 0 ? strOptString3 : null;
                    }
                }
            }
        }
        String strOptString4 = jSONObject.optString("backdropUrl", "");
        kotlin.jvm.internal.o.e(strOptString4);
        if (strOptString4.length() <= 0) {
            strOptString4 = null;
        }
        if (strOptString4 == null) {
            strOptString4 = jSONObject.optString("backdropSD", "");
            kotlin.jvm.internal.o.e(strOptString4);
            if (strOptString4.length() <= 0) {
                strOptString4 = null;
            }
            if (strOptString4 == null) {
                strOptString4 = jSONObject.optString("backdrop", "");
                kotlin.jvm.internal.o.e(strOptString4);
                str2 = strOptString4.length() > 0 ? strOptString4 : null;
            }
        }
        String strOptString5 = jSONObject.optString("logo", "");
        kotlin.jvm.internal.o.e(strOptString5);
        String str4 = strOptString5.length() > 0 ? strOptString5 : null;
        String strOptString6 = jSONObject.optString("year", "");
        double dOptDouble = jSONObject.optDouble("rating", 0.0d);
        String strOptString7 = jSONObject.optString("certificate", "");
        if (S4.p.Q0(strOptString7)) {
            strOptString7 = jSONObject.optString("certification", "");
        }
        kotlin.jvm.internal.o.g(strOptString7, "ifBlank(...)");
        String strI = W0.e.i(strOptString7);
        if (jSONObject.has("runTime")) {
            iOptInt = jSONObject.optInt("runTime", 0);
        } else {
            if (!jSONObject.has("durationSeconds")) {
                i6 = 0;
                w4.k kVarX0 = W.a.x0(jSONObject.optJSONArray("genres"));
                String str5 = (String) kVarX0.f25469a;
                String str6 = (String) kVarX0.f25470b;
                JSONArray jSONArrayOptJSONArray = jSONObject.optJSONArray("originCountries");
                length = jSONArrayOptJSONArray == null ? jSONArrayOptJSONArray.length() : 0;
                if (length != 0) {
                    list = x4.y.f26065a;
                } else {
                    ArrayList arrayList = new ArrayList(length);
                    while (i8 < length) {
                        kotlin.jvm.internal.o.e(jSONArrayOptJSONArray);
                        String str7 = strOptString2;
                        String strOptString8 = jSONArrayOptJSONArray.optString(i8, "");
                        int i9 = i8;
                        JSONArray jSONArray = jSONArrayOptJSONArray;
                        if (strOptString8.length() != 2 || 'A' > (cCharAt = strOptString8.charAt(0)) || cCharAt >= '[') {
                            i7 = length;
                        } else {
                            char cCharAt2 = strOptString8.charAt(1);
                            i7 = length;
                            if ('A' <= cCharAt2 && cCharAt2 < '[') {
                                arrayList.add(strOptString8);
                            }
                            i8 = i9 + 1;
                            strOptString2 = str7;
                            jSONArrayOptJSONArray = jSONArray;
                            length = i7;
                        }
                        String string = S4.p.o1(strOptString8).toString();
                        if (string.length() == 2) {
                            String upperCase = string.toUpperCase(Locale.ROOT);
                            kotlin.jvm.internal.o.g(upperCase, "toUpperCase(...)");
                            arrayList.add(upperCase);
                        }
                        i8 = i9 + 1;
                        strOptString2 = str7;
                        jSONArrayOptJSONArray = jSONArray;
                        length = i7;
                    }
                    list = arrayList;
                }
                String str8 = strOptString2;
                String strOptString9 = jSONObject.optString("title");
                kotlin.jvm.internal.o.g(strOptString9, "optString(...)");
                String strOptString10 = jSONObject.optString("overview");
                kotlin.jvm.internal.o.g(strOptString10, "optString(...)");
                kotlin.jvm.internal.o.e(strOptString6);
                String strOptString11 = jSONObject.optString("originalLanguage", "");
                kotlin.jvm.internal.o.g(strOptString11, "optString(...)");
                String lowerCase = S4.p.o1(strOptString11).toString().toLowerCase(Locale.ROOT);
                kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
                return new HomeMetaItem(str8, iOptInt2, str3, strOptString9, strOptString10, strOptString6, dOptDouble, str, str2, str4, strI, i6, str5, str6, list, lowerCase);
            }
            iOptInt = jSONObject.optInt("durationSeconds", 0) / 60;
        }
        i6 = iOptInt;
        w4.k kVarX02 = W.a.x0(jSONObject.optJSONArray("genres"));
        String str52 = (String) kVarX02.f25469a;
        String str62 = (String) kVarX02.f25470b;
        JSONArray jSONArrayOptJSONArray2 = jSONObject.optJSONArray("originCountries");
        if (jSONArrayOptJSONArray2 == null) {
        }
        if (length != 0) {
        }
        String str82 = strOptString2;
        String strOptString92 = jSONObject.optString("title");
        kotlin.jvm.internal.o.g(strOptString92, "optString(...)");
        String strOptString102 = jSONObject.optString("overview");
        kotlin.jvm.internal.o.g(strOptString102, "optString(...)");
        kotlin.jvm.internal.o.e(strOptString6);
        String strOptString112 = jSONObject.optString("originalLanguage", "");
        kotlin.jvm.internal.o.g(strOptString112, "optString(...)");
        String lowerCase2 = S4.p.o1(strOptString112).toString().toLowerCase(Locale.ROOT);
        kotlin.jvm.internal.o.g(lowerCase2, "toLowerCase(...)");
        return new HomeMetaItem(str82, iOptInt2, str3, strOptString92, strOptString102, strOptString6, dOptDouble, str, str2, str4, strI, i6, str52, str62, list, lowerCase2);
    }
}
