package com.strmr.ps.data.remote;

import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.google.gson.Gson;
import com.strmr.ps.data.local.entity.PlaybackProgress;
import com.strmr.ps.data.model.ContentItem;
import defpackage.cr4;
import defpackage.kp6;
import defpackage.m02;
import defpackage.m12;
import defpackage.n41;
import defpackage.n89;
import defpackage.q69;
import defpackage.r69;
import defpackage.sc2;
import defpackage.vx8;
import defpackage.wj0;
import defpackage.y41;
import java.util.List;
import java.util.Locale;
import javax.inject.Inject;
import javax.inject.Singleton;
import kotlin.Metadata;
import kotlin.coroutines.jvm.internal.ContinuationImpl;
import okhttp3.OkHttpClient;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u0000\u0016\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0007\u0018\u00002\u00020\u0001:\u0001\bB\u0019\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004¢\u0006\u0004\b\u0006\u0010\u0007¨\u0006\t"}, d2 = {"Lcom/strmr/ps/data/remote/AddonCatalogClient;", "", "Lokhttp3/OkHttpClient;", "okHttpClient", "Lcom/google/gson/Gson;", "gson", "<init>", "(Lokhttp3/OkHttpClient;Lcom/google/gson/Gson;)V", CmcdData.OBJECT_TYPE_AUDIO_ONLY, "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@vx8
public final class AddonCatalogClient {
    public final OkHttpClient a;
    public final Gson b;

    @Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0010\t\n\u0002\b\u0003\b\u0086\u0003\u0018\u00002\u00020\u0001R\u0014\u0010\u0003\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0003\u0010\u0004R\u0014\u0010\u0005\u001a\u00020\u00028\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0005\u0010\u0004R\u0014\u0010\u0007\u001a\u00020\u00068\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0007\u0010\b¨\u0006\t"}, d2 = {"Lcom/strmr/ps/data/remote/AddonCatalogClient$a;", "", "", "TAG", "Ljava/lang/String;", "USER_AGENT", "", "CATALOG_TIMEOUT_MS", "J", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a {
    }

    @Inject
    public AddonCatalogClient(@kp6 OkHttpClient okHttpClient, @kp6 Gson gson) {
        cr4.g(okHttpClient, "okHttpClient");
        cr4.g(gson, "gson");
        this.a = okHttpClient;
        this.b = gson;
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:32:0x007d  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0080  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final ContentItem a(AddonCatalogClient addonCatalogClient, r69 r69Var, String str) {
        ContentItem.ItemType itemType;
        String releaseInfo;
        Double dBc;
        String name;
        String type = r69Var.getType();
        Locale locale = Locale.ROOT;
        String lowerCase = type.toLowerCase(locale);
        cr4.f(lowerCase, "toLowerCase(...)");
        boolean zEquals = lowerCase.equals("other");
        q69 behaviorHints = r69Var.getBehaviorHints();
        boolean zB = behaviorHints != null ? cr4.b(behaviorHints.getIsFolder(), Boolean.TRUE) : false;
        String lowerCase2 = r69Var.getType().toLowerCase(locale);
        cr4.f(lowerCase2, "toLowerCase(...)");
        switch (lowerCase2.hashCode()) {
            case -905838985:
                itemType = lowerCase2.equals("series") ? ContentItem.ItemType.TV_SHOW : ContentItem.ItemType.MOVIE;
                break;
            case 3714:
                if (!lowerCase2.equals("tv")) {
                }
                break;
            case 92962932:
                if (!lowerCase2.equals("anime")) {
                }
                break;
            case 104087344:
                if (lowerCase2.equals(PlaybackProgress.TYPE_MOVIE)) {
                    itemType = ContentItem.ItemType.MOVIE;
                    break;
                }
                break;
            case 106069776:
                if (lowerCase2.equals("other")) {
                    itemType = zB ? ContentItem.ItemType.DEBRID_FOLDER : ContentItem.ItemType.DEBRID_FILE;
                    break;
                }
                break;
            case 738950403:
                if (lowerCase2.equals("channel")) {
                    itemType = ContentItem.ItemType.MOVIE;
                    break;
                }
                break;
        }
        ContentItem.ItemType itemType2 = itemType;
        String imdbId = r69Var.getImdbId();
        if (imdbId == null) {
            imdbId = n89.ar(r69Var.getId(), TtmlNode.TAG_TT, false) ? r69Var.getId() : null;
        }
        if (imdbId == null) {
            imdbId = null;
        } else if (!n89.ar(imdbId, TtmlNode.TAG_TT, false)) {
            int i = 0;
            while (true) {
                if (i >= imdbId.length()) {
                    int length = imdbId.length();
                    if (1 <= length && length < 11) {
                        imdbId = TtmlNode.TAG_TT.concat(imdbId);
                    }
                } else if (Character.isDigit(imdbId.charAt(i))) {
                    i++;
                }
            }
        }
        Integer moviedbId = r69Var.getMoviedbId();
        if (moviedbId == null) {
            if (n89.ar(r69Var.getId(), "tmdb:", false)) {
                moviedbId = n89.be(n89.ai(r69Var.getId(), "tmdb:"));
            } else if (zEquals) {
                moviedbId = null;
            } else {
                String id = r69Var.getId();
                for (int i2 = 0; i2 < id.length(); i2++) {
                    if (!Character.isDigit(id.charAt(i2))) {
                        moviedbId = null;
                    }
                }
                moviedbId = n89.be(r69Var.getId());
            }
        }
        if (!zEquals && ((name = r69Var.getName()) == null || n89.ab(name))) {
            n41.ab("Skipping item without title: ", r69Var.getId(), "AddonCatalogClient");
            return null;
        }
        List cast = r69Var.getCast();
        String strAi = cast != null ? y41.ai(y41.bk(cast, 5), ", ", null, null, null, 62) : null;
        int iIntValue = moviedbId != null ? moviedbId.intValue() : r69Var.getId().hashCode() ^ itemType2.hashCode();
        int iIntValue2 = moviedbId != null ? moviedbId.intValue() : 0;
        if (zEquals) {
            imdbId = r69Var.getId();
        }
        String str2 = imdbId;
        String name2 = r69Var.getName();
        if (name2 == null) {
            name2 = "Unknown";
        }
        String str3 = name2;
        String description = r69Var.getDescription();
        String poster = r69Var.getPoster();
        String background = r69Var.getBackground();
        String logo = r69Var.getLogo();
        Object year = r69Var.getYear();
        if (year == null || (releaseInfo = year.toString()) == null) {
            releaseInfo = r69Var.getReleaseInfo();
        }
        String str4 = releaseInfo;
        String imdbRating = r69Var.getImdbRating();
        Double dBc2 = imdbRating != null ? n89.bc(imdbRating) : null;
        String imdbRating2 = r69Var.getImdbRating();
        Integer numValueOf = (imdbRating2 == null || (dBc = n89.bc(imdbRating2)) == null) ? null : Integer.valueOf((int) (dBc.doubleValue() * ((double) 10)));
        List genres = r69Var.getGenres();
        String strAi2 = genres != null ? y41.ai(genres, ", ", null, null, null, 62) : null;
        String runtime = r69Var.getRuntime();
        String imdbRating3 = r69Var.getImdbRating();
        String id2 = r69Var.getId();
        String lowerCase3 = r69Var.getType().toLowerCase(Locale.ROOT);
        cr4.f(lowerCase3, "toLowerCase(...)");
        return new ContentItem(iIntValue, itemType2, iIntValue2, str2, str3, description, poster, background, logo, null, str4, dBc2, numValueOf, strAi2, runtime, strAi, null, imdbRating3, null, null, null, null, null, null, false, null, str, null, null, null, 0, null, null, null, null, null, null, null, null, id2, lowerCase3, null, null, -117440512, 1663, null);
    }

    public final Object b(String str, String str2, String str3, int i, ContinuationImpl continuationImpl) {
        m12 m12Var = sc2.a;
        return wj0.f(m02.c, new com.strmr.ps.data.remote.a(i, str, str2, str3, this, null), continuationImpl);
    }
}
