package X2;

import S4.p;
import S4.w;
import V4.C;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.revenuecat.purchases.common.diagnostics.DiagnosticsEntry;
import kotlin.jvm.internal.o;
import m3.AbstractC2467b;
import n2.AbstractC2612c;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import w4.C3137A;
import w4.n;
import x4.y;
import y4.C3274b;

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

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

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

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

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

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

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

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

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public b(String str, boolean z6, int i6, f fVar, int i7, String str2, A4.d dVar) {
        super(2, dVar);
        this.f8556b = str;
        this.f8557c = z6;
        this.f8558d = i6;
        this.f8559e = fVar;
        this.f8560f = i7;
        this.f8561j = str2;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        b bVar = new b(this.f8556b, this.f8557c, this.f8558d, this.f8559e, this.f8560f, this.f8561j, dVar);
        bVar.f8555a = obj;
        return bVar;
    }

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

    @Override // C4.a
    public final Object invokeSuspend(Object obj) throws JSONException {
        Object objD;
        B4.a aVar = B4.a.f492a;
        AbstractC2467b.l(obj);
        String str = this.f8556b;
        String string = str != null ? p.o1(str).toString() : null;
        if (string == null) {
            string = "";
        }
        y yVar = y.f26065a;
        f fVar = this.f8559e;
        boolean z6 = this.f8557c;
        int i6 = this.f8558d;
        if (!z6 || i6 <= 0) {
            JSONArray jSONArrayOptJSONArray = fVar.g("tv/" + this.f8560f + "/season/" + i6, this.f8561j, false).optJSONArray("episodes");
            if (jSONArrayOptJSONArray != null) {
                C3274b c3274bK = AbstractC2612c.k();
                int length = jSONArrayOptJSONArray.length();
                for (int i7 = 0; i7 < length; i7++) {
                    JSONObject jSONObject = jSONArrayOptJSONArray.getJSONObject(i7);
                    o.e(jSONObject);
                    String strG = W0.e.g(jSONObject, "still_path");
                    String strConcat = W0.e.f(strG) ? "https://image.tmdb.org/t/p/w500".concat(strG) : null;
                    int iOptInt = jSONObject.optInt("id");
                    String strOptString = jSONObject.optString(DiagnosticsEntry.NAME_KEY);
                    o.g(strOptString, "optString(...)");
                    String strOptString2 = jSONObject.optString("overview");
                    o.g(strOptString2, "optString(...)");
                    String strOptString3 = jSONObject.optString("air_date");
                    o.g(strOptString3, "optString(...)");
                    c3274bK.add(new i(iOptInt, strOptString, strOptString2, strOptString3, jSONObject.optInt("episode_number"), this.f8558d, jSONObject.has("runtime") ? jSONObject.optInt("runtime", 0) : 0, strConcat));
                }
                return AbstractC2612c.e(c3274bK);
            }
        } else {
            String str2 = w.A0(string, TtmlNode.TAG_TT, true) ? string : null;
            if (str2 != null && !p.Q0(str2)) {
                try {
                    objD = f.b(fVar, str2, i6);
                } catch (Throwable th) {
                    objD = AbstractC2467b.d(th);
                }
                return n.a(objD) == null ? objD : yVar;
            }
        }
        return yVar;
    }
}
