package f3;

import S4.p;
import V4.C;
import Z0.o;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
import m3.AbstractC2467b;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.json.JSONObject;
import w4.C3137A;

/* JADX INFO: renamed from: f3.c, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C2038c extends C4.j implements J4.e {

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

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

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

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

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        return new C2038c(this.f16413a, this.f16414b, dVar, this.f16415c);
    }

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

    @Override // C4.a
    public final Object invokeSuspend(Object obj) throws IOException {
        B4.a aVar = B4.a.f492a;
        AbstractC2467b.l(obj);
        int i6 = this.f16413a;
        String str = i6 > 0 ? "episode" : "movie";
        if (i6 <= 0) {
            i6 = this.f16414b;
        }
        String str2 = this.f16415c;
        if (p.Q0(str2)) {
            str2 = "en";
        }
        String strN = com.google.android.recaptcha.internal.a.n(o.s(i6, "https://api.opensubtitles.com/api/v1/subtitles?type=", str, "&tmdb_id=", "&languages="), URLEncoder.encode(str2, S4.a.f6257a.name()), "&order_by=download_count");
        Request.Builder builder = new Request.Builder();
        builder.i(strN);
        builder.f(C2039d.a(0).e());
        builder.d();
        Response responseD = C2039d.f16416a.a(builder.b()).d();
        try {
            if (!responseD.c()) {
                throw new IllegalStateException(("OpenSubtitles " + responseD.f22143d).toString());
            }
            ResponseBody responseBody = responseD.f22146j;
            String strD = responseBody != null ? responseBody.d() : null;
            if (strD == null) {
                strD = "";
            }
            List listA = AbstractC2040e.a(new JSONObject(strD));
            responseD.close();
            return listA;
        } finally {
        }
    }
}
