package X2;

import S4.p;
import S4.w;
import android.content.Context;
import e3.AbstractC1964a;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import kotlin.jvm.internal.o;
import m3.AbstractC2467b;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import org.json.JSONObject;
import w4.n;
import x4.z;

/* JADX INFO: loaded from: classes.dex */
public abstract class j {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static volatile Map f8601a = z.f26066a;

    public static void a() throws IOException {
        Object objD;
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        TimeUnit timeUnit = TimeUnit.SECONDS;
        builder.b(30L);
        AbstractC1964a.b(builder);
        OkHttpClient okHttpClient = new OkHttpClient(builder);
        Request.Builder builder2 = new Request.Builder();
        builder2.i("https://raw.githubusercontent.com/lawdev-cmd/map/refs/heads/main/entryMap.json");
        builder2.d();
        Response responseD = okHttpClient.a(builder2.b()).d();
        try {
            if (!responseD.c()) {
                responseD.close();
                return;
            }
            ResponseBody responseBody = responseD.f22146j;
            String string = responseBody != null ? p.o1(responseBody.d()).toString() : null;
            if (string == null) {
                string = "";
            }
            if (string.length() == 0) {
                responseD.close();
                return;
            }
            try {
                objD = c(string);
            } catch (Throwable th) {
                objD = AbstractC2467b.d(th);
            }
            if (n.a(objD) == null) {
                Map map = (Map) objD;
                if (map.isEmpty()) {
                    responseD.close();
                    return;
                }
                f8601a = map;
                Context context = W.c.f8375h;
                if (context != null) {
                    String string2 = p.o1(string).toString();
                    if (string2.length() != 0) {
                        context.getSharedPreferences("debridstream_remote_map", 0).edit().putString("https://raw.githubusercontent.com/lawdev-cmd/map/refs/heads/main/entryMap.json", string2).apply();
                    }
                }
            }
            responseD.close();
        } catch (Throwable th2) {
            try {
                throw th2;
            } catch (Throwable th3) {
                android.support.v4.media.session.b.j(responseD, th2);
                throw th3;
            }
        }
    }

    public static String b(int i6, String type) {
        o.h(type, "type");
        if (type.equals("tv") || type.equals("movie")) {
            return (String) f8601a.get(Integer.valueOf(i6));
        }
        return null;
    }

    public static LinkedHashMap c(String str) {
        JSONObject jSONObject = new JSONObject(str);
        LinkedHashMap linkedHashMap = new LinkedHashMap();
        Iterator<String> itKeys = jSONObject.keys();
        while (itKeys.hasNext()) {
            String next = itKeys.next();
            o.e(next);
            Integer numB0 = w.B0(next);
            if (numB0 != null) {
                String strP = A0.a.p(jSONObject, next, "", "optString(...)");
                if (strP.length() <= 0) {
                    strP = null;
                }
                if (strP != null) {
                    linkedHashMap.put(numB0, strP);
                }
            }
        }
        return linkedHashMap;
    }
}
