package c3;

import A4.d;
import C4.j;
import J4.e;
import S4.p;
import V4.C;
import Z0.o;
import java.net.URLEncoder;
import m3.AbstractC2467b;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.json.JSONObject;
import w4.C3137A;
import w4.m;

/* JADX INFO: renamed from: c3.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1238a extends j implements e {

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

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

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C1238a(int i6, int i7, d dVar, String str) {
        super(2, dVar);
        this.f13422b = str;
        this.f13423c = i6;
        this.f13424d = i7;
    }

    @Override // C4.a
    public final d create(Object obj, d dVar) {
        C1238a c1238a = new C1238a(this.f13423c, this.f13424d, dVar, this.f13422b);
        c1238a.f13421a = obj;
        return c1238a;
    }

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

    /* JADX WARN: Removed duplicated region for block: B:56:0x00dc  */
    /* JADX WARN: Removed duplicated region for block: B:66:? A[RETURN, SYNTHETIC] */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        int i6;
        int i7;
        Object objD;
        Response responseD;
        long j4;
        long j6;
        B4.a aVar = B4.a.f492a;
        AbstractC2467b.l(obj);
        String string = p.o1(this.f13422b).toString();
        if (string.length() == 0 || (i6 = this.f13423c) <= 0 || (i7 = this.f13424d) <= 0) {
            return null;
        }
        String strQ = o.q(o.s(i6, "https://api.introdb.app/intro?imdb_id=", URLEncoder.encode(string, S4.a.f6257a.name()), "&season=", "&episode="), i7, "&segment_type=intro");
        try {
            OkHttpClient okHttpClient = AbstractC1239b.f13425a;
            Request.Builder builder = new Request.Builder();
            builder.i(strQ);
            builder.d();
            responseD = okHttpClient.a(builder.b()).d();
            try {
            } finally {
            }
        } catch (Throwable th) {
            objD = AbstractC2467b.d(th);
        }
        if (!responseD.c()) {
            responseD.close();
            return null;
        }
        ResponseBody responseBody = responseD.f22146j;
        String strD = responseBody != null ? responseBody.d() : null;
        if (strD == null) {
            strD = "";
        }
        JSONObject jSONObject = new JSONObject(strD);
        if (jSONObject.has("start_ms")) {
            j4 = jSONObject.getLong("start_ms");
        } else {
            if (!jSONObject.has("start_sec")) {
                responseD.close();
                return null;
            }
            j4 = (long) (jSONObject.getDouble("start_sec") * 1000.0d);
        }
        if (jSONObject.has("end_ms")) {
            j6 = jSONObject.getLong("end_ms");
        } else {
            if (!jSONObject.has("end_sec")) {
                responseD.close();
                return null;
            }
            j6 = (long) (jSONObject.getDouble("end_sec") * 1000.0d);
        }
        if (j6 <= j4) {
            responseD.close();
            return null;
        }
        objD = new C1240c(j4, j6);
        responseD.close();
        if (objD instanceof m) {
            return objD;
        }
        return null;
        objD = AbstractC2467b.d(th);
        if (objD instanceof m) {
        }
    }
}
