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.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.Continuation;
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/AddonSearchClient;", "", "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 AddonSearchClient {
    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/AddonSearchClient$a;", "", "", "TAG", "Ljava/lang/String;", "USER_AGENT", "", "SEARCH_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 AddonSearchClient(@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:22:0x004a  */
    /* JADX WARN: Removed duplicated region for block: B:23:0x004d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final ContentItem a(AddonSearchClient addonSearchClient, r69 r69Var, String str) {
        ContentItem.ItemType itemType;
        String str2;
        String releaseInfo;
        int i;
        String str3;
        Integer numValueOf;
        Double dBc;
        String lowerCase = r69Var.getType().toLowerCase(Locale.ROOT);
        cr4.f(lowerCase, "toLowerCase(...)");
        switch (lowerCase.hashCode()) {
            case -905838985:
                itemType = !lowerCase.equals("series") ? ContentItem.ItemType.MOVIE : ContentItem.ItemType.TV_SHOW;
                break;
            case 3714:
                if (!lowerCase.equals("tv")) {
                }
                break;
            case 92962932:
                if (!lowerCase.equals("anime")) {
                }
                break;
            case 104087344:
                if (lowerCase.equals(PlaybackProgress.TYPE_MOVIE)) {
                    itemType = ContentItem.ItemType.MOVIE;
                    break;
                }
                break;
            case 738950403:
                if (lowerCase.equals("channel")) {
                    itemType = ContentItem.ItemType.MOVIE;
                    break;
                }
                break;
        }
        ContentItem.ItemType itemType2 = itemType;
        String name = r69Var.getName();
        if (name == null || n89.ab(name)) {
            n41.ab("Skipping search item without title: ", r69Var.getId(), "AddonSearchClient");
            return null;
        }
        String imdbId = r69Var.getImdbId();
        if (imdbId == null) {
            imdbId = n89.ar(r69Var.getId(), TtmlNode.TAG_TT, false) ? r69Var.getId() : null;
        }
        if (imdbId != null) {
            if (!n89.ar(imdbId, TtmlNode.TAG_TT, false)) {
                int i2 = 0;
                while (true) {
                    if (i2 >= imdbId.length()) {
                        int length = imdbId.length();
                        if (1 <= length && length < 11) {
                            imdbId = TtmlNode.TAG_TT.concat(imdbId);
                        }
                    } else if (Character.isDigit(imdbId.charAt(i2))) {
                        i2++;
                    }
                }
            }
            str2 = imdbId;
        } else {
            str2 = null;
        }
        Integer moviedbId = r69Var.getMoviedbId();
        if (moviedbId == null) {
            if (n89.ar(r69Var.getId(), "tmdb:", false)) {
                moviedbId = n89.be(n89.ai(r69Var.getId(), "tmdb:"));
            } else {
                String id = r69Var.getId();
                int i3 = 0;
                while (true) {
                    if (i3 >= id.length()) {
                        moviedbId = n89.be(r69Var.getId());
                    } else if (Character.isDigit(id.charAt(i3))) {
                        i3++;
                    } else {
                        moviedbId = 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();
        int iIntValue2 = moviedbId != null ? moviedbId.intValue() : 0;
        String name2 = r69Var.getName();
        if (name2 == null) {
            name2 = "Unknown";
        }
        String str4 = 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 str5 = releaseInfo;
        String imdbRating = r69Var.getImdbRating();
        Double dBc2 = imdbRating != null ? n89.bc(imdbRating) : null;
        String imdbRating2 = r69Var.getImdbRating();
        if (imdbRating2 == null || (dBc = n89.bc(imdbRating2)) == null) {
            i = iIntValue;
            str3 = null;
            numValueOf = null;
        } else {
            i = iIntValue;
            str3 = null;
            numValueOf = Integer.valueOf((int) (((double) 10) * dBc.doubleValue()));
        }
        List genres = r69Var.getGenres();
        String strAi2 = genres != null ? y41.ai(genres, ", ", null, null, null, 62) : str3;
        String runtime = r69Var.getRuntime();
        String imdbRating3 = r69Var.getImdbRating();
        String id2 = r69Var.getId();
        String lowerCase2 = r69Var.getType().toLowerCase(Locale.ROOT);
        cr4.f(lowerCase2, "toLowerCase(...)");
        return new ContentItem(i, itemType2, iIntValue2, str2, str4, description, poster, background, logo, null, str5, 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, lowerCase2, null, null, -117440512, 1663, null);
    }

    public final Object b(String str, String str2, String str3, String str4, Continuation continuation) {
        m12 m12Var = sc2.a;
        return wj0.f(m02.c, new c(str4, str, str2, str3, this, null), continuation);
    }
}
