package Y2;

import V4.C;
import com.debridstream.tv.data.home.HomeMetaItem;
import com.revenuecat.purchases.common.diagnostics.DiagnosticsEntry;
import java.io.EOFException;
import java.util.Set;
import m3.AbstractC2467b;
import org.json.JSONArray;
import org.json.JSONObject;
import w4.C3137A;

/* JADX INFO: loaded from: classes.dex */
public final class c extends C4.j implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public int f8722a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public /* synthetic */ Object f8723b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ int f8724c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ String f8725d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ o f8726e;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public c(int i6, String str, o oVar, A4.d dVar) {
        super(2, dVar);
        this.f8724c = i6;
        this.f8725d = str;
        this.f8726e = oVar;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        c cVar = new c(this.f8724c, this.f8725d, this.f8726e, dVar);
        cVar.f8723b = obj;
        return cVar;
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((c) create((C) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    /* JADX WARN: Removed duplicated region for block: B:128:0x01f0  */
    /* JADX WARN: Removed duplicated region for block: B:141:0x0210  */
    /* JADX WARN: Removed duplicated region for block: B:18:0x0055  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x0114  */
    /* JADX WARN: Removed duplicated region for block: B:87:0x0134  */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws EOFException {
        String strO;
        String strL;
        Object objA;
        Object objD;
        String str;
        String str2;
        JSONObject jSONObjectOptJSONObject;
        String strOptString;
        JSONObject jSONObjectOptJSONObject2;
        String strOptString2;
        String strConcat;
        String str3;
        String str4;
        JSONObject jSONObjectOptJSONObject3;
        String strOptString3;
        JSONObject jSONObjectOptJSONObject4;
        String strOptString4;
        String strConcat2;
        B4.a aVar = B4.a.f492a;
        int i6 = this.f8722a;
        String str5 = this.f8725d;
        int i7 = this.f8724c;
        if (i6 == 0) {
            AbstractC2467b.l(obj);
            C c6 = (C) this.f8723b;
            Set set = q.f8782a;
            if (kotlin.jvm.internal.o.c(str5, "movie")) {
                strL = Z0.o.l("movie/", i7);
            } else {
                if (!kotlin.jvm.internal.o.c(str5, "tv")) {
                    strO = null;
                    if (strO != null) {
                        this.f8723b = c6;
                        this.f8722a = 1;
                        objA = o.a(this.f8726e, strO, this);
                        if (objA == aVar) {
                            return aVar;
                        }
                    }
                    return null;
                }
                strL = Z0.o.l("tv/", i7);
            }
            strO = Z0.o.o("https://api.themoviedb.org/3/", strL, "?api_key=7ba07eac0fde9485edfc077df9937ab6");
            if (strO != null) {
            }
            return null;
        }
        if (i6 != 1) {
            throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
        }
        AbstractC2467b.l(obj);
        objA = obj;
        String str6 = (String) objA;
        if (str6 != null) {
            try {
                objD = new JSONObject(str6);
            } catch (Throwable th) {
                objD = AbstractC2467b.d(th);
            }
            if (objD instanceof w4.m) {
                objD = null;
            }
            JSONObject jSONObject = (JSONObject) objD;
            if (jSONObject != null) {
                if (kotlin.jvm.internal.o.c(str5, "movie")) {
                    String strOptString5 = jSONObject.optString("poster_path", "");
                    kotlin.jvm.internal.o.e(strOptString5);
                    if (!q.a(strOptString5)) {
                        strOptString5 = null;
                    }
                    String strConcat3 = strOptString5 != null ? "https://image.tmdb.org/t/p/w500".concat(strOptString5) : null;
                    String strOptString6 = jSONObject.optString("backdrop_path", "");
                    kotlin.jvm.internal.o.e(strOptString6);
                    if (!q.a(strOptString6)) {
                        strOptString6 = null;
                    }
                    String str7 = (strOptString6 == null || (strConcat2 = "https://image.tmdb.org/t/p/w780".concat(strOptString6)) == null) ? strConcat3 : strConcat2;
                    String strOptString7 = jSONObject.optString("release_date", "");
                    kotlin.jvm.internal.o.e(strOptString7);
                    String strM1 = S4.p.m1(4, strOptString7);
                    if (strM1.length() != 4 || !Character.isDigit(strM1.charAt(0))) {
                        strM1 = null;
                    }
                    String str8 = strM1 == null ? "" : strM1;
                    JSONArray jSONArrayOptJSONArray = jSONObject.optJSONArray("genres");
                    if (jSONArrayOptJSONArray == null || (jSONObjectOptJSONObject4 = jSONArrayOptJSONArray.optJSONObject(0)) == null || (strOptString4 = jSONObjectOptJSONObject4.optString(DiagnosticsEntry.NAME_KEY)) == null) {
                        str3 = "";
                    } else {
                        if (S4.p.Q0(strOptString4)) {
                            strOptString4 = null;
                        }
                        if (strOptString4 != null) {
                            str3 = strOptString4;
                        }
                    }
                    if (jSONArrayOptJSONArray == null || (jSONObjectOptJSONObject3 = jSONArrayOptJSONArray.optJSONObject(1)) == null || (strOptString3 = jSONObjectOptJSONObject3.optString(DiagnosticsEntry.NAME_KEY)) == null) {
                        str4 = "";
                    } else {
                        String str9 = !S4.p.Q0(strOptString3) ? strOptString3 : null;
                        if (str9 != null) {
                            str4 = str9;
                        }
                    }
                    String strValueOf = String.valueOf(i7);
                    String strOptString8 = jSONObject.optString("title");
                    kotlin.jvm.internal.o.g(strOptString8, "optString(...)");
                    String strOptString9 = jSONObject.optString("overview");
                    kotlin.jvm.internal.o.g(strOptString9, "optString(...)");
                    return new HomeMetaItem(strValueOf, this.f8724c, "movie", strOptString8, strOptString9, str8, jSONObject.optDouble("vote_average", 0.0d), strConcat3, str7, null, W0.e.i(""), jSONObject.optInt("runtime", 0), str3, str4, W.a.z0(jSONObject), W.a.A0(jSONObject));
                }
                String strOptString10 = jSONObject.optString("poster_path", "");
                kotlin.jvm.internal.o.e(strOptString10);
                if (!q.a(strOptString10)) {
                    strOptString10 = null;
                }
                String strConcat4 = strOptString10 != null ? "https://image.tmdb.org/t/p/w500".concat(strOptString10) : null;
                String strOptString11 = jSONObject.optString("backdrop_path", "");
                kotlin.jvm.internal.o.e(strOptString11);
                if (!q.a(strOptString11)) {
                    strOptString11 = null;
                }
                String str10 = (strOptString11 == null || (strConcat = "https://image.tmdb.org/t/p/w780".concat(strOptString11)) == null) ? strConcat4 : strConcat;
                String strOptString12 = jSONObject.optString("first_air_date", "");
                kotlin.jvm.internal.o.e(strOptString12);
                String strM12 = S4.p.m1(4, strOptString12);
                if (strM12.length() != 4 || !Character.isDigit(strM12.charAt(0))) {
                    strM12 = null;
                }
                String str11 = strM12 == null ? "" : strM12;
                JSONArray jSONArrayOptJSONArray2 = jSONObject.optJSONArray("genres");
                if (jSONArrayOptJSONArray2 == null || (jSONObjectOptJSONObject2 = jSONArrayOptJSONArray2.optJSONObject(0)) == null || (strOptString2 = jSONObjectOptJSONObject2.optString(DiagnosticsEntry.NAME_KEY)) == null) {
                    str = "";
                } else {
                    if (S4.p.Q0(strOptString2)) {
                        strOptString2 = null;
                    }
                    if (strOptString2 != null) {
                        str = strOptString2;
                    }
                }
                if (jSONArrayOptJSONArray2 == null || (jSONObjectOptJSONObject = jSONArrayOptJSONArray2.optJSONObject(1)) == null || (strOptString = jSONObjectOptJSONObject.optString(DiagnosticsEntry.NAME_KEY)) == null) {
                    str2 = "";
                } else {
                    String str12 = !S4.p.Q0(strOptString) ? strOptString : null;
                    if (str12 != null) {
                        str2 = str12;
                    }
                }
                String strValueOf2 = String.valueOf(i7);
                String strOptString13 = jSONObject.optString(DiagnosticsEntry.NAME_KEY);
                kotlin.jvm.internal.o.g(strOptString13, "optString(...)");
                String strOptString14 = jSONObject.optString("overview");
                kotlin.jvm.internal.o.g(strOptString14, "optString(...)");
                double dOptDouble = jSONObject.optDouble("vote_average", 0.0d);
                String strI = W0.e.i("");
                JSONArray jSONArrayOptJSONArray3 = jSONObject.optJSONArray("episode_run_time");
                return new HomeMetaItem(strValueOf2, this.f8724c, "tv", strOptString13, strOptString14, str11, dOptDouble, strConcat4, str10, null, strI, jSONArrayOptJSONArray3 != null ? jSONArrayOptJSONArray3.optInt(0) : 0, str, str2, W.a.z0(jSONObject), W.a.A0(jSONObject));
            }
        }
        return null;
    }
}
