package V2;

import androidx.media3.exoplayer.DecoderReuseEvaluation;
import com.debridstream.tv.data.home.HomeMetaItem;
import java.util.Locale;
import m3.AbstractC2467b;
import org.json.JSONObject;
import w4.C3137A;

/* JADX INFO: renamed from: V2.p1, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0707p1 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final C0707p1 f8004a = new C0707p1();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final e5.i f8005b = e5.j.a(35);

    /* JADX WARN: Removed duplicated region for block: B:43:0x0094  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00a4  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x00b4  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00e7  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x00fa  */
    /* JADX WARN: Removed duplicated region for block: B:79:0x0109  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0019  */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object a(Y2.o oVar, HomeMetaItem homeMetaItem, HomeMetaItem homeMetaItem2, C4.c cVar) throws Throwable {
        C0664g1 c0664g1;
        int i6;
        int i7;
        HomeMetaItem homeMetaItem3;
        HomeMetaItem homeMetaItem4 = homeMetaItem;
        C0707p1 c0707p1 = f8004a;
        if (cVar instanceof C0664g1) {
            c0664g1 = (C0664g1) cVar;
            int i8 = c0664g1.f7779e;
            if ((i8 & Integer.MIN_VALUE) != 0) {
                c0664g1.f7779e = i8 - Integer.MIN_VALUE;
            } else {
                c0664g1 = new C0664g1(cVar);
            }
        }
        Object obj = c0664g1.f7778d;
        B4.a aVar = B4.a.f492a;
        int i9 = c0664g1.f7779e;
        if (i9 == 0) {
            AbstractC2467b.l(obj);
            String posterUrl = homeMetaItem4.getPosterUrl();
            int i10 = (posterUrl == null || S4.p.Q0(posterUrl)) ? 1 : 0;
            String backdropUrl = homeMetaItem4.getBackdropUrl();
            i6 = (backdropUrl == null || S4.p.Q0(backdropUrl)) ? 1 : 0;
            if (i10 == 0 && i6 == 0) {
                return homeMetaItem4;
            }
            if (homeMetaItem2 != null) {
                i7 = i10;
                homeMetaItem3 = homeMetaItem2;
                HomeMetaItem homeMetaItemCopy = homeMetaItem4;
                String str = null;
                if (i7 != 0) {
                    String posterUrl2 = homeMetaItem3.getPosterUrl();
                    if (posterUrl2 == null) {
                        posterUrl2 = homeMetaItem3.getBackdropUrl();
                        if (posterUrl2 == null || S4.p.Q0(posterUrl2)) {
                            posterUrl2 = null;
                        }
                        if (posterUrl2 != null) {
                            String strA = g3.u.a(posterUrl2, false);
                            homeMetaItemCopy = homeMetaItemCopy.copy((65407 & 1) != 0 ? homeMetaItemCopy.id : null, (65407 & 2) != 0 ? homeMetaItemCopy.tmdbId : 0, (65407 & 4) != 0 ? homeMetaItemCopy.type : null, (65407 & 8) != 0 ? homeMetaItemCopy.title : null, (65407 & 16) != 0 ? homeMetaItemCopy.overview : null, (65407 & 32) != 0 ? homeMetaItemCopy.year : null, (65407 & 64) != 0 ? homeMetaItemCopy.rating : 0.0d, (65407 & 128) != 0 ? homeMetaItemCopy.posterUrl : S4.p.Q0(strA) ? posterUrl2 : strA, (65407 & 256) != 0 ? homeMetaItemCopy.backdropUrl : null, (65407 & 512) != 0 ? homeMetaItemCopy.logoUrl : null, (65407 & 1024) != 0 ? homeMetaItemCopy.certificate : null, (65407 & 2048) != 0 ? homeMetaItemCopy.runTimeMinutes : 0, (65407 & 4096) != 0 ? homeMetaItemCopy.primaryGenre : null, (65407 & 8192) != 0 ? homeMetaItemCopy.secondaryGenre : null, (65407 & 16384) != 0 ? homeMetaItemCopy.originCountries : null, (65407 & DecoderReuseEvaluation.DISCARD_REASON_AUDIO_BYPASS_POSSIBLE) != 0 ? homeMetaItemCopy.originalLanguage : null);
                        }
                    } else {
                        if (S4.p.Q0(posterUrl2)) {
                            posterUrl2 = null;
                        }
                        if (posterUrl2 == null) {
                        }
                        if (posterUrl2 != null) {
                        }
                    }
                }
                HomeMetaItem homeMetaItem5 = homeMetaItemCopy;
                if (i6 != 0) {
                    String backdropUrl2 = homeMetaItem3.getBackdropUrl();
                    if (backdropUrl2 == null) {
                        String posterUrl3 = homeMetaItem3.getPosterUrl();
                        if (posterUrl3 != null && !S4.p.Q0(posterUrl3)) {
                            str = posterUrl3;
                        }
                        if (str != null) {
                            String strA2 = g3.u.a(str, true);
                            return homeMetaItem5.copy((65407 & 1) != 0 ? homeMetaItem5.id : null, (65407 & 2) != 0 ? homeMetaItem5.tmdbId : 0, (65407 & 4) != 0 ? homeMetaItem5.type : null, (65407 & 8) != 0 ? homeMetaItem5.title : null, (65407 & 16) != 0 ? homeMetaItem5.overview : null, (65407 & 32) != 0 ? homeMetaItem5.year : null, (65407 & 64) != 0 ? homeMetaItem5.rating : 0.0d, (65407 & 128) != 0 ? homeMetaItem5.posterUrl : null, (65407 & 256) != 0 ? homeMetaItem5.backdropUrl : S4.p.Q0(strA2) ? str : strA2, (65407 & 512) != 0 ? homeMetaItem5.logoUrl : null, (65407 & 1024) != 0 ? homeMetaItem5.certificate : null, (65407 & 2048) != 0 ? homeMetaItem5.runTimeMinutes : 0, (65407 & 4096) != 0 ? homeMetaItem5.primaryGenre : null, (65407 & 8192) != 0 ? homeMetaItem5.secondaryGenre : null, (65407 & 16384) != 0 ? homeMetaItem5.originCountries : null, (65407 & DecoderReuseEvaluation.DISCARD_REASON_AUDIO_BYPASS_POSSIBLE) != 0 ? homeMetaItem5.originalLanguage : null);
                        }
                    } else {
                        if (S4.p.Q0(backdropUrl2)) {
                            backdropUrl2 = null;
                        }
                        if (backdropUrl2 != null) {
                            str = backdropUrl2;
                        }
                        if (str != null) {
                        }
                    }
                }
                return homeMetaItem5;
            }
            int tmdbId = homeMetaItem4.getTmdbId();
            String type = homeMetaItem4.getType();
            c0664g1.f7775a = homeMetaItem4;
            c0664g1.f7776b = i10;
            c0664g1.f7777c = i6;
            c0664g1.f7779e = 1;
            Object objF = c0707p1.f(oVar, tmdbId, type, c0664g1);
            if (objF == aVar) {
                return aVar;
            }
            i7 = i10;
            obj = objF;
        } else {
            if (i9 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            int i11 = c0664g1.f7777c;
            i7 = c0664g1.f7776b;
            HomeMetaItem homeMetaItem6 = c0664g1.f7775a;
            AbstractC2467b.l(obj);
            i6 = i11;
            homeMetaItem4 = homeMetaItem6;
        }
        homeMetaItem3 = (HomeMetaItem) obj;
        if (homeMetaItem3 == null) {
            return homeMetaItem4;
        }
        HomeMetaItem homeMetaItemCopy2 = homeMetaItem4;
        String str2 = null;
        if (i7 != 0) {
        }
        HomeMetaItem homeMetaItem52 = homeMetaItemCopy2;
        if (i6 != 0) {
        }
        return homeMetaItem52;
    }

    /* JADX WARN: Removed duplicated region for block: B:21:0x0077  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x00a5  */
    /* JADX WARN: Removed duplicated region for block: B:45:0x00cf  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x00df  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x00ef  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x0100  */
    /* JADX WARN: Removed duplicated region for block: B:73:0x0111 A[PHI: r13
      0x0111: PHI (r13v8 java.lang.String) = (r13v6 java.lang.String), (r13v9 java.lang.String) binds: [B:77:0x011d, B:71:0x010e] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:74:0x0113  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0019  */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object b(Y2.o oVar, int i6, String str, JSONObject jSONObject, HomeMetaItem homeMetaItem, C4.c cVar) throws Throwable {
        C0669h1 c0669h1;
        int i7;
        int i8;
        HomeMetaItem homeMetaItem2;
        int i9;
        JSONObject jSONObject2 = jSONObject;
        C0707p1 c0707p1 = f8004a;
        if (cVar instanceof C0669h1) {
            c0669h1 = (C0669h1) cVar;
            int i10 = c0669h1.f7794e;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                c0669h1.f7794e = i10 - Integer.MIN_VALUE;
            } else {
                c0669h1 = new C0669h1(cVar);
            }
        }
        Object obj = c0669h1.f7793d;
        B4.a aVar = B4.a.f492a;
        int i11 = c0669h1.f7794e;
        C3137A c3137a = C3137A.f25453a;
        if (i11 == 0) {
            AbstractC2467b.l(obj);
            String strOptString = jSONObject2.optString("posterUrl", "");
            kotlin.jvm.internal.o.g(strOptString, "optString(...)");
            if (S4.p.Q0(strOptString)) {
                String strOptString2 = jSONObject2.optString("poster", "");
                kotlin.jvm.internal.o.g(strOptString2, "optString(...)");
                if (S4.p.Q0(strOptString2)) {
                    String strOptString3 = jSONObject2.optString("posterHD", "");
                    kotlin.jvm.internal.o.g(strOptString3, "optString(...)");
                    i7 = S4.p.Q0(strOptString3) ? 1 : 0;
                    String strOptString4 = jSONObject2.optString("backdropUrl", "");
                    kotlin.jvm.internal.o.g(strOptString4, "optString(...)");
                    if (S4.p.Q0(strOptString4)) {
                        String strOptString5 = jSONObject2.optString("backdrop", "");
                        kotlin.jvm.internal.o.g(strOptString5, "optString(...)");
                        if (S4.p.Q0(strOptString5)) {
                            String strOptString6 = jSONObject2.optString("backdropSD", "");
                            kotlin.jvm.internal.o.g(strOptString6, "optString(...)");
                            int i12 = S4.p.Q0(strOptString6) ? 1 : 0;
                            if (i7 != 0 || i12 != 0) {
                                if (homeMetaItem == null) {
                                    c0669h1.f7790a = jSONObject2;
                                    c0669h1.f7791b = i7;
                                    c0669h1.f7792c = i12;
                                    c0669h1.f7794e = 1;
                                    Object objF = c0707p1.f(oVar, i6, str, c0669h1);
                                    if (objF == aVar) {
                                        return aVar;
                                    }
                                    int i13 = i12;
                                    obj = objF;
                                    i8 = i13;
                                    i9 = i7;
                                } else {
                                    i8 = i12;
                                    homeMetaItem2 = homeMetaItem;
                                    String str2 = null;
                                    if (i7 != 0) {
                                        String posterUrl = homeMetaItem2.getPosterUrl();
                                        if (posterUrl == null) {
                                            posterUrl = homeMetaItem2.getBackdropUrl();
                                            if (posterUrl == null || S4.p.Q0(posterUrl)) {
                                                posterUrl = null;
                                            }
                                            if (posterUrl != null) {
                                                String strA = g3.u.a(posterUrl, false);
                                                if (!S4.p.Q0(strA)) {
                                                    posterUrl = strA;
                                                }
                                                jSONObject2.put("posterUrl", posterUrl);
                                            }
                                        } else {
                                            if (S4.p.Q0(posterUrl)) {
                                                posterUrl = null;
                                            }
                                            if (posterUrl == null) {
                                            }
                                            if (posterUrl != null) {
                                            }
                                        }
                                    }
                                    if (i8 != 0) {
                                        String backdropUrl = homeMetaItem2.getBackdropUrl();
                                        if (backdropUrl == null) {
                                            backdropUrl = homeMetaItem2.getPosterUrl();
                                            if (backdropUrl != null && !S4.p.Q0(backdropUrl)) {
                                                str2 = backdropUrl;
                                            }
                                            if (str2 != null) {
                                                String strA2 = g3.u.a(str2, true);
                                                if (!S4.p.Q0(strA2)) {
                                                    str2 = strA2;
                                                }
                                                jSONObject2.put("backdropUrl", str2);
                                            }
                                        } else {
                                            if (S4.p.Q0(backdropUrl)) {
                                                backdropUrl = null;
                                            }
                                            if (backdropUrl == null) {
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return c3137a;
        }
        if (i11 != 1) {
            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
        i8 = c0669h1.f7792c;
        i9 = c0669h1.f7791b;
        jSONObject2 = c0669h1.f7790a;
        AbstractC2467b.l(obj);
        homeMetaItem2 = (HomeMetaItem) obj;
        if (homeMetaItem2 != null) {
            i7 = i9;
            String str22 = null;
            if (i7 != 0) {
            }
            if (i8 != 0) {
            }
        }
        return c3137a;
    }

    public static final boolean c(JSONObject jSONObject, int i6, String str) {
        if (jSONObject.optInt("tmdbId", 0) != i6) {
            return false;
        }
        String strP = A0.a.p(jSONObject, "type", "movie", "optString(...)");
        Locale locale = Locale.ROOT;
        String lowerCase = strP.toLowerCase(locale);
        kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
        if (S4.p.Q0(lowerCase)) {
            lowerCase = "movie";
        }
        String lowerCase2 = S4.p.o1(str).toString().toLowerCase(locale);
        kotlin.jvm.internal.o.g(lowerCase2, "toLowerCase(...)");
        return lowerCase.equals(S4.p.Q0(lowerCase2) ? "movie" : lowerCase2);
    }

    public static final boolean d(HomeMetaItem homeMetaItem, int i6, String str) {
        if (homeMetaItem.getTmdbId() != i6) {
            return false;
        }
        String string = S4.p.o1(homeMetaItem.getType()).toString();
        Locale locale = Locale.ROOT;
        String lowerCase = string.toLowerCase(locale);
        kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
        if (S4.p.Q0(lowerCase)) {
            lowerCase = "movie";
        }
        String lowerCase2 = S4.p.o1(str).toString().toLowerCase(locale);
        kotlin.jvm.internal.o.g(lowerCase2, "toLowerCase(...)");
        return lowerCase.equals(S4.p.Q0(lowerCase2) ? "movie" : lowerCase2);
    }

    public static String e(int i6, String str) {
        String lowerCase = S4.p.o1(str).toString().toLowerCase(Locale.ROOT);
        kotlin.jvm.internal.o.g(lowerCase, "toLowerCase(...)");
        if (S4.p.Q0(lowerCase)) {
            lowerCase = "movie";
        }
        return lowerCase + "-" + i6;
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object f(Y2.o oVar, int i6, String str, C4.c cVar) throws Throwable {
        C0674i1 c0674i1;
        e5.i iVar;
        Object obj;
        if (cVar instanceof C0674i1) {
            c0674i1 = (C0674i1) cVar;
            int i7 = c0674i1.f7813j;
            if ((i7 & Integer.MIN_VALUE) != 0) {
                c0674i1.f7813j = i7 - Integer.MIN_VALUE;
            } else {
                c0674i1 = new C0674i1(this, cVar);
            }
        }
        Object obj2 = c0674i1.f7811e;
        B4.a aVar = B4.a.f492a;
        int i8 = c0674i1.f7813j;
        try {
            try {
                if (i8 == 0) {
                    AbstractC2467b.l(obj2);
                    c0674i1.f7807a = oVar;
                    c0674i1.f7808b = str;
                    iVar = f8005b;
                    c0674i1.f7809c = iVar;
                    c0674i1.f7810d = i6;
                    c0674i1.f7813j = 1;
                    if (iVar.a(c0674i1) != aVar) {
                    }
                    return aVar;
                }
                if (i8 != 1) {
                    if (i8 != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    obj = (e5.e) c0674i1.f7807a;
                    try {
                        AbstractC2467b.l(obj2);
                        HomeMetaItem homeMetaItem = (HomeMetaItem) obj2;
                        ((e5.h) obj).c();
                        return homeMetaItem;
                    } catch (Throwable th) {
                        th = th;
                        ((e5.h) obj).c();
                        throw th;
                    }
                }
                i6 = c0674i1.f7810d;
                e5.i iVar2 = c0674i1.f7809c;
                str = c0674i1.f7808b;
                Y2.o oVar2 = (Y2.o) c0674i1.f7807a;
                AbstractC2467b.l(obj2);
                iVar = iVar2;
                oVar = oVar2;
                oVar.getClass();
                c5.e eVar = V4.N.f8259a;
                Object objH = V4.E.H(c5.d.f13466b, new Y2.c(i6, str, oVar, null), c0674i1);
                if (objH != aVar) {
                    e5.i iVar3 = iVar;
                    obj2 = objH;
                    obj = iVar3;
                    HomeMetaItem homeMetaItem2 = (HomeMetaItem) obj2;
                    ((e5.h) obj).c();
                    return homeMetaItem2;
                }
                return aVar;
            } catch (Throwable th2) {
                th = th2;
                obj = iVar;
                ((e5.h) obj).c();
                throw th;
            }
            c0674i1.f7807a = iVar;
            c0674i1.f7808b = null;
            c0674i1.f7809c = null;
            c0674i1.f7813j = 2;
        } catch (Throwable th3) {
            th = th3;
        }
    }
}
