package com.strmr.ps.data.remote;

import android.util.Log;
import android.util.LruCache;
import androidx.credentials.exceptions.publickeycredential.DomExceptionUtils;
import androidx.media3.exoplayer.rtsp.RtspHeaders;
import defpackage.ak1;
import defpackage.ck1;
import defpackage.e6a;
import defpackage.gr3;
import defpackage.n89;
import defpackage.s38;
import defpackage.u69;
import defpackage.v69;
import defpackage.vx8;
import java.util.concurrent.CancellationException;
import java.util.concurrent.TimeUnit;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0002\u001a\u0004\u0018\u00010\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Lu69;", "<anonymous>", "(Lak1;)Lu69;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.remote.AddonMetadataClient$fetchMetadata$2", f = "AddonMetadataClient.kt", i = {}, l = {}, m = "invokeSuspend", n = {}, s = {})
@vx8
final class b extends SuspendLambda implements gr3<ak1, Continuation<? super u69>, Object> {
    public final /* synthetic */ String a;
    public final /* synthetic */ String b;
    public final /* synthetic */ String c;
    public final /* synthetic */ AddonMetadataClient d;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public b(AddonMetadataClient addonMetadataClient, String str, String str2, String str3, Continuation continuation) {
        super(2, continuation);
        this.a = str;
        this.b = str2;
        this.c = str3;
        this.d = addonMetadataClient;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new b(this.d, this.a, this.b, this.c, continuation);
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((b) create((ak1) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) {
        ck1 ck1Var = ck1.a;
        s38.b(obj);
        StringBuilder sb = new StringBuilder();
        String str = this.a;
        sb.append(str);
        sb.append("|");
        String str2 = this.b;
        sb.append(str2);
        sb.append("|");
        String str3 = this.c;
        sb.append(str3);
        String string = sb.toString();
        AddonMetadataClient addonMetadataClient = this.d;
        LruCache lruCache = addonMetadataClient.c;
        u69 u69Var = (u69) lruCache.get(string);
        if (u69Var != null) {
            return u69Var;
        }
        String str4 = str + "/meta/" + str2 + DomExceptionUtils.SEPARATOR + str3 + ".json";
        try {
            OkHttpClient.Builder builderNewBuilder = addonMetadataClient.a.newBuilder();
            TimeUnit timeUnit = TimeUnit.MILLISECONDS;
            Response responseExecute = builderNewBuilder.callTimeout(15000L, timeUnit).connectTimeout(15000L, timeUnit).readTimeout(15000L, timeUnit).build().newCall(new Request.Builder().url(str4).header(RtspHeaders.USER_AGENT, "Strmr/1.0").build()).execute();
            try {
                if (!responseExecute.isSuccessful()) {
                    Log.e("AddonMetadataClient", "HTTP " + responseExecute.code() + " from " + str4);
                    responseExecute.close();
                    return null;
                }
                ResponseBody responseBodyBody = responseExecute.body();
                String strString = responseBodyBody != null ? responseBodyBody.string() : null;
                if (strString != null && !n89.ab(strString)) {
                    v69 v69Var = (v69) addonMetadataClient.b.fromJson(strString, v69.class);
                    u69 meta = v69Var != null ? v69Var.getMeta() : null;
                    if (meta != null) {
                        lruCache.put(string, meta);
                    } else {
                        Boxing.boxInt(Log.w("AddonMetadataClient", "No meta in response from " + str4));
                    }
                    responseExecute.close();
                    return meta;
                }
                Log.e("AddonMetadataClient", "Empty response from " + str4);
                responseExecute.close();
                return null;
            } finally {
            }
        } catch (CancellationException e) {
            throw e;
        } catch (Exception e2) {
            Log.e("AddonMetadataClient", "Error fetching metadata: " + e2.getMessage(), e2);
            return null;
        }
    }
}
