package Y2;

import S4.w;
import V4.C;
import androidx.media3.extractor.text.ttml.TtmlNode;
import java.io.EOFException;
import m3.AbstractC2467b;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.json.JSONObject;
import w4.C3137A;

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

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

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

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

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

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        e eVar = new e(this.f8732b, this.f8733c, dVar);
        eVar.f8731a = obj;
        return eVar;
    }

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

    /* JADX WARN: Removed duplicated region for block: B:36:0x00b4 A[Catch: all -> 0x007c, TryCatch #3 {all -> 0x007c, blocks: (B:7:0x003b, B:11:0x0047, B:13:0x004b, B:18:0x005a, B:20:0x0060, B:25:0x007f, B:28:0x009c, B:30:0x00a2, B:33:0x00af, B:36:0x00b4, B:38:0x00ba, B:41:0x00c4, B:43:0x00cc, B:45:0x00d6, B:47:0x00dc, B:52:0x00e6, B:62:0x0107, B:54:0x00ec, B:56:0x00f4, B:58:0x00fe, B:17:0x0056, B:14:0x004f), top: B:83:0x003b, outer: #0, inners: #1 }] */
    /* JADX WARN: Removed duplicated region for block: B:37:0x00b9  */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00e3  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x00ec A[Catch: all -> 0x007c, TryCatch #3 {all -> 0x007c, blocks: (B:7:0x003b, B:11:0x0047, B:13:0x004b, B:18:0x005a, B:20:0x0060, B:25:0x007f, B:28:0x009c, B:30:0x00a2, B:33:0x00af, B:36:0x00b4, B:38:0x00ba, B:41:0x00c4, B:43:0x00cc, B:45:0x00d6, B:47:0x00dc, B:52:0x00e6, B:62:0x0107, B:54:0x00ec, B:56:0x00f4, B:58:0x00fe, B:17:0x0056, B:14:0x004f), top: B:83:0x003b, outer: #0, inners: #1 }] */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0106  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x012a  */
    /* JADX WARN: Removed duplicated region for block: B:87:? A[RETURN, SYNTHETIC] */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) throws EOFException {
        Object objD;
        Response responseD;
        ResponseBody responseBody;
        Object objD2;
        JSONObject jSONObjectOptJSONObject;
        String string;
        String string2;
        String strOptString;
        B4.a aVar = B4.a.f492a;
        AbstractC2467b.l(obj);
        int i6 = this.f8732b;
        if (i6 <= 0) {
            return null;
        }
        String strJ = Z0.o.j(i6, "https://api.themoviedb.org/3/movie/", "?api_key=7ba07eac0fde9485edfc077df9937ab6&append_to_response=external_ids&language=en");
        Request.Builder builder = new Request.Builder();
        builder.i(strJ);
        builder.a("Accept", "application/json");
        try {
            responseD = this.f8733c.f8779a.a(builder.b()).d();
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        try {
            if (responseD.c() && (responseBody = responseD.f22146j) != null) {
                try {
                    objD2 = new JSONObject(responseBody.d());
                } catch (Throwable th2) {
                    objD2 = AbstractC2467b.d(th2);
                }
                if (w4.n.a(objD2) == null) {
                    JSONObject jSONObject = (JSONObject) objD2;
                    String strOptString2 = jSONObject.optString("title", "");
                    kotlin.jvm.internal.o.g(strOptString2, "optString(...)");
                    String string3 = S4.p.o1(strOptString2).toString();
                    if (string3.length() == 0) {
                        string3 = "Movie";
                    }
                    String strOptString3 = jSONObject.optString("release_date", "");
                    kotlin.jvm.internal.o.g(strOptString3, "optString(...)");
                    String strM1 = S4.p.m1(4, S4.p.o1(strOptString3).toString());
                    if (strM1.length() == 4) {
                        for (int i7 = 0; i7 < strM1.length(); i7++) {
                            if (!Character.isDigit(strM1.charAt(i7))) {
                                strM1 = null;
                                break;
                            }
                        }
                        Integer numB0 = strM1 == null ? w.B0(strM1) : null;
                        jSONObjectOptJSONObject = jSONObject.optJSONObject("external_ids");
                        if (jSONObjectOptJSONObject != null || (strOptString = jSONObjectOptJSONObject.optString("imdb_id", "")) == null || (string = S4.p.o1(strOptString).toString()) == null || string.length() <= 0 || !w.A0(string, TtmlNode.TAG_TT, true)) {
                            string = null;
                        }
                        if (string != null || string.length() == 0) {
                            String strB = X2.j.b(i6, "movie");
                            string = (strB == null && (string2 = S4.p.o1(strB).toString()) != null && w.A0(string2, TtmlNode.TAG_TT, true)) ? string2 : null;
                        }
                        objD = new r(string3, string, numB0);
                        responseD.close();
                    } else {
                        strM1 = null;
                        if (strM1 == null) {
                        }
                        jSONObjectOptJSONObject = jSONObject.optJSONObject("external_ids");
                        if (jSONObjectOptJSONObject != null) {
                            string = null;
                            if (string != null) {
                                String strB2 = X2.j.b(i6, "movie");
                                if (strB2 == null) {
                                    objD = new r(string3, string, numB0);
                                    responseD.close();
                                }
                            }
                        }
                    }
                    if (objD instanceof w4.m) {
                        return null;
                    }
                    return objD;
                }
                responseD.close();
                objD = AbstractC2467b.d(th);
                if (objD instanceof w4.m) {
                }
            } else {
                responseD.close();
            }
            objD = null;
            if (objD instanceof w4.m) {
            }
        } finally {
        }
    }
}
