package com.strmr.ps.data.subtitle;

import android.content.Context;
import android.util.Log;
import androidx.credentials.exceptions.publickeycredential.DomExceptionUtils;
import androidx.media3.common.C;
import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.Tracks;
import androidx.media3.container.NalUnitUtil;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.exoplayer.upstream.CmcdConfiguration;
import androidx.media3.exoplayer.upstream.CmcdData;
import androidx.media3.extractor.text.ttml.TtmlNode;
import com.strmr.ps.data.local.entity.PlaybackProgress;
import com.strmr.ps.data.local.entity.PlayerSettings;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.model.addon.InstalledAddon;
import com.strmr.ps.data.remote.AddonSubtitleClient;
import com.strmr.ps.data.remote.api.StremioSubtitle;
import com.strmr.ps.data.repository.AddonRepository;
import com.strmr.ps.data.repository.PlayerSettingsRepository;
import com.strmr.ps.data.subtitle.t;
import com.strmr.ps.data.subtitle.u;
import dagger.hilt.android.qualifiers.ApplicationContext;
import defpackage.bk1;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.gb9;
import defpackage.hb9;
import defpackage.ib9;
import defpackage.ik2;
import defpackage.io6;
import defpackage.jb9;
import defpackage.kb9;
import defpackage.kp6;
import defpackage.lb9;
import defpackage.m02;
import defpackage.m12;
import defpackage.n41;
import defpackage.n89;
import defpackage.q07;
import defpackage.q38;
import defpackage.s38;
import defpackage.sb9;
import defpackage.sc2;
import defpackage.vx8;
import defpackage.wj0;
import defpackage.wo5;
import defpackage.y41;
import java.io.File;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Singleton;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.Boxing;
import kotlin.coroutines.jvm.internal.ContinuationImpl;

/* JADX INFO: loaded from: classes3.dex */
@Singleton
@Metadata(d1 = {"\u0000.\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0007\u0018\u00002\u00020\u0001:\u0001\u0010B;\b\u0007\u0012\u0006\u0010\u0003\u001a\u00020\u0002\u0012\u0006\u0010\u0005\u001a\u00020\u0004\u0012\u0006\u0010\u0007\u001a\u00020\u0006\u0012\u0006\u0010\t\u001a\u00020\b\u0012\u0006\u0010\u000b\u001a\u00020\n\u0012\b\b\u0001\u0010\r\u001a\u00020\f¢\u0006\u0004\b\u000e\u0010\u000f¨\u0006\u0011"}, d2 = {"Lcom/strmr/ps/data/subtitle/SubtitleManager;", "", "Lcom/strmr/ps/data/subtitle/StremioSubtitleProvider;", "stremioSubtitleProvider", "Lcom/strmr/ps/data/subtitle/OpenSubtitlesProvider;", "openSubtitlesProvider", "Lcom/strmr/ps/data/repository/AddonRepository;", "addonRepository", "Lcom/strmr/ps/data/remote/AddonSubtitleClient;", "addonSubtitleClient", "Lcom/strmr/ps/data/repository/PlayerSettingsRepository;", "playerSettingsRepository", "Landroid/content/Context;", "context", "<init>", "(Lcom/strmr/ps/data/subtitle/StremioSubtitleProvider;Lcom/strmr/ps/data/subtitle/OpenSubtitlesProvider;Lcom/strmr/ps/data/repository/AddonRepository;Lcom/strmr/ps/data/remote/AddonSubtitleClient;Lcom/strmr/ps/data/repository/PlayerSettingsRepository;Landroid/content/Context;)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 SubtitleManager {
    public static final Object g = wo5.j(new q07("en", "English"), new q07("eng", "English"), new q07("es", "Spanish"), new q07("spa", "Spanish"), new q07("fr", "French"), new q07("fra", "French"), new q07("fre", "French"), new q07("de", "German"), new q07("deu", "German"), new q07("ger", "German"), new q07("it", "Italian"), new q07("ita", "Italian"), new q07("pt", "Portuguese"), new q07("por", "Portuguese"), new q07("pt-br", "Portuguese (Brazilian)"), new q07("pb", "Portuguese (Brazilian)"), new q07("pob", "Portuguese (Brazilian)"), new q07("nl", "Dutch"), new q07("nld", "Dutch"), new q07("dut", "Dutch"), new q07("pl", "Polish"), new q07("pol", "Polish"), new q07("ru", "Russian"), new q07("rus", "Russian"), new q07("ja", "Japanese"), new q07("jpn", "Japanese"), new q07("ko", "Korean"), new q07("kor", "Korean"), new q07("zh", "Chinese"), new q07("zho", "Chinese"), new q07("chi", "Chinese"), new q07("ar", "Arabic"), new q07("ara", "Arabic"), new q07("he", "Hebrew"), new q07("heb", "Hebrew"), new q07("tr", "Turkish"), new q07("tur", "Turkish"), new q07("sv", "Swedish"), new q07("swe", "Swedish"), new q07("no", "Norwegian"), new q07(CmcdConfiguration.KEY_NEXT_OBJECT_REQUEST, "Norwegian"), new q07("nob", "Norwegian"), new q07("nno", "Norwegian"), new q07("da", "Danish"), new q07("dan", "Danish"), new q07("fi", "Finnish"), new q07("fin", "Finnish"), new q07("cs", "Czech"), new q07("ces", "Czech"), new q07("cze", "Czech"), new q07("hu", "Hungarian"), new q07("hun", "Hungarian"), new q07("ro", "Romanian"), new q07("ron", "Romanian"), new q07("rum", "Romanian"), new q07("uk", "Ukrainian"), new q07("ukr", "Ukrainian"), new q07("el", "Greek"), new q07("ell", "Greek"), new q07("gre", "Greek"), new q07("th", "Thai"), new q07("tha", "Thai"), new q07("vi", "Vietnamese"), new q07("vie", "Vietnamese"), new q07(TtmlNode.ATTR_ID, "Indonesian"), new q07("ind", "Indonesian"), new q07("hi", "Hindi"), new q07("hin", "Hindi"), new q07(C.LANGUAGE_UNDETERMINED, "Undetermined"));
    public static final Object h = wo5.j(new q07("eng", "en"), new q07("spa", "es"), new q07("fra", "fr"), new q07("fre", "fr"), new q07("deu", "de"), new q07("ger", "de"), new q07("ita", "it"), new q07("por", "pt"), new q07("pb", "pt-BR"), new q07("pob", "pt-BR"), new q07("nld", "nl"), new q07("dut", "nl"), new q07("pol", "pl"), new q07("rus", "ru"), new q07("jpn", "ja"), new q07("kor", "ko"), new q07("zho", "zh"), new q07("chi", "zh"), new q07("ara", "ar"), new q07("heb", "he"), new q07("tur", "tr"), new q07("swe", "sv"), new q07(CmcdConfiguration.KEY_NEXT_OBJECT_REQUEST, "no"), new q07("nob", "no"), new q07("nno", "no"), new q07("dan", "da"), new q07("fin", "fi"), new q07("ces", "cs"), new q07("cze", "cs"), new q07("hun", "hu"), new q07("ron", "ro"), new q07("rum", "ro"), new q07("ukr", "uk"), new q07("ell", "el"), new q07("gre", "el"), new q07("tha", "th"), new q07("vie", "vi"), new q07("ind", TtmlNode.ATTR_ID), new q07("hin", "hi"));
    public final StremioSubtitleProvider a;
    public final OpenSubtitlesProvider b;
    public final AddonRepository c;
    public final AddonSubtitleClient d;
    public final PlayerSettingsRepository e;
    public final Context f;

    @Metadata(d1 = {"\u0000 \n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0010$\n\u0002\b\u0004\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\u0006X\u0086T¢\u0006\u0006\n\u0004\b\u0005\u0010\u0004R\u0014\u0010\u0007\u001a\u00020\u00068\u0002X\u0082T¢\u0006\u0006\n\u0004\b\u0007\u0010\bR \u0010\n\u001a\u000e\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u00020\t8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\n\u0010\u000bR \u0010\f\u001a\u000e\u0012\u0004\u0012\u00020\u0002\u0012\u0004\u0012\u00020\u00020\t8\u0002X\u0082\u0004¢\u0006\u0006\n\u0004\b\f\u0010\u000b¨\u0006\r"}, d2 = {"Lcom/strmr/ps/data/subtitle/SubtitleManager$a;", "", "", "TAG", "Ljava/lang/String;", "EXTERNAL_SUBTITLE_PREFIX", "", "MAX_RESULTS_PER_LANGUAGE", "I", "", "LANGUAGE_NAMES", "Ljava/util/Map;", "LANGUAGE_CODE_NORMALIZE", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a {
        /* JADX WARN: Type inference failed for: r0v4, types: [java.lang.Object, java.util.Map] */
        public static String a(String str) {
            String str2;
            if (str == null || n89.ab(str)) {
                return "en";
            }
            String lowerCase = str.toLowerCase(Locale.ROOT);
            cr4.f(lowerCase, "toLowerCase(...)");
            String string = n89.bg(lowerCase).toString();
            return (string.length() == 2 || (str2 = (String) SubtitleManager.h.get(string)) == null) ? string : str2;
        }
    }

    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public /* synthetic */ class b {
        static {
            int[] iArr = new int[t.b.a.values().length];
            try {
                iArr[0] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                t.b.a aVar = t.b.a.a;
                iArr[1] = 2;
            } catch (NoSuchFieldError unused2) {
            }
        }
    }

    @Inject
    public SubtitleManager(@kp6 StremioSubtitleProvider stremioSubtitleProvider, @kp6 OpenSubtitlesProvider openSubtitlesProvider, @kp6 AddonRepository addonRepository, @kp6 AddonSubtitleClient addonSubtitleClient, @kp6 PlayerSettingsRepository playerSettingsRepository, @ApplicationContext @kp6 Context context) {
        cr4.g(stremioSubtitleProvider, "stremioSubtitleProvider");
        cr4.g(openSubtitlesProvider, "openSubtitlesProvider");
        cr4.g(addonRepository, "addonRepository");
        cr4.g(addonSubtitleClient, "addonSubtitleClient");
        cr4.g(playerSettingsRepository, "playerSettingsRepository");
        cr4.g(context, "context");
        this.a = stremioSubtitleProvider;
        this.b = openSubtitlesProvider;
        this.c = addonRepository;
        this.d = addonSubtitleClient;
        this.e = playerSettingsRepository;
        this.f = context;
    }

    /* JADX WARN: Code restructure failed: missing block: B:136:0x0332, code lost:
    
        if (r2 == r5) goto L148;
     */
    /* JADX WARN: Code restructure failed: missing block: B:147:0x0385, code lost:
    
        if (r3 != r5) goto L149;
     */
    /* JADX WARN: Code restructure failed: missing block: B:98:0x0278, code lost:
    
        if (r3 == r5) goto L148;
     */
    /* JADX WARN: Removed duplicated region for block: B:115:0x02ca  */
    /* JADX WARN: Removed duplicated region for block: B:146:0x0369 A[PHI: r0 r1
      0x0369: PHI (r0v10 java.util.List) = (r0v30 java.util.List), (r0v31 java.util.List) binds: [B:114:0x02c8, B:145:0x0366] A[DONT_GENERATE, DONT_INLINE]
      0x0369: PHI (r1v25 com.strmr.ps.data.subtitle.SubtitleManager) = (r1v23 com.strmr.ps.data.subtitle.SubtitleManager), (r1v27 com.strmr.ps.data.subtitle.SubtitleManager) binds: [B:114:0x02c8, B:145:0x0366] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:53:0x0197  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x01b8  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x01dd  */
    /* JADX WARN: Removed duplicated region for block: B:71:0x01f2  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x020c A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x001b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object a(SubtitleManager subtitleManager, ContentItem contentItem, Integer num, Integer num2, String str, String str2, ContinuationImpl continuationImpl) {
        p pVar;
        ContentItem contentItem2;
        SubtitleManager subtitleManager2;
        String str3;
        String str4;
        String str5;
        String str6;
        Integer num3;
        String str7;
        SubtitleManager subtitleManager3;
        Integer num4;
        String str8;
        List list;
        ContentItem contentItem3;
        Integer num5;
        Integer num6;
        Integer num7;
        ContentItem contentItem4;
        List list2;
        SubtitleManager subtitleManager4;
        List list3;
        Iterator it;
        boolean z;
        String str9;
        Object objD;
        List list4;
        List list5;
        ArrayList arrayList;
        List list6;
        SubtitleManager subtitleManager5;
        boolean zIsEmpty;
        Object objE;
        List list7;
        List list8;
        List list9;
        List list10;
        Integer num8 = num;
        if (continuationImpl instanceof p) {
            pVar = (p) continuationImpl;
            int i = pVar.n;
            if ((i & Integer.MIN_VALUE) != 0) {
                pVar.n = i - Integer.MIN_VALUE;
            } else {
                pVar = new p(subtitleManager, continuationImpl);
            }
        }
        Object settings = pVar.l;
        ck1 ck1Var = ck1.a;
        int i2 = pVar.n;
        Object obj = ik2.a;
        if (i2 == 0) {
            s38.b(settings);
            String imdbId = contentItem.getImdbId();
            if (imdbId == null || n89.ab(imdbId)) {
                Log.w("SubtitleManager", "searchExternalSubtitles: No IMDB ID on contentItem '" + contentItem.getTitle() + "' (tmdbId=" + contentItem.getTmdbId() + ") — skipping external subtitle search");
                return obj;
            }
            String str10 = (num8 == null || num8.intValue() <= 0) ? PlaybackProgress.TYPE_MOVIE : "series";
            String str11 = (num8 == null || num8.intValue() <= 0 || num2 == null || num2.intValue() <= 0) ? imdbId : imdbId + ":" + num8 + ":" + num2;
            AddonRepository addonRepository = subtitleManager.c;
            pVar.a = subtitleManager;
            contentItem2 = contentItem;
            pVar.b = contentItem2;
            pVar.c = num8;
            pVar.d = num2;
            pVar.e = str;
            pVar.f = str2;
            pVar.i = imdbId;
            pVar.j = str10;
            pVar.k = str11;
            pVar.n = 1;
            Object subtitleAddons = addonRepository.getSubtitleAddons(pVar);
            if (subtitleAddons != ck1Var) {
                subtitleManager2 = subtitleManager;
                str3 = str10;
                str4 = str11;
                str5 = str;
                str6 = str2;
                num3 = num2;
                str7 = imdbId;
                settings = subtitleAddons;
            }
            return ck1Var;
        }
        if (i2 == 1) {
            String str12 = pVar.k;
            String str13 = pVar.j;
            str7 = (String) pVar.i;
            String str14 = (String) pVar.f;
            String str15 = pVar.e;
            num3 = pVar.d;
            Integer num9 = pVar.c;
            ContentItem contentItem5 = (ContentItem) pVar.b;
            SubtitleManager subtitleManager6 = (SubtitleManager) pVar.a;
            s38.b(settings);
            str4 = str12;
            str3 = str13;
            str6 = str14;
            str5 = str15;
            num8 = num9;
            subtitleManager2 = subtitleManager6;
            contentItem2 = contentItem5;
        } else if (i2 == 2) {
            List list11 = (List) pVar.i;
            list = (List) pVar.f;
            str7 = pVar.e;
            num7 = pVar.d;
            num6 = pVar.c;
            contentItem4 = (ContentItem) pVar.b;
            subtitleManager3 = (SubtitleManager) pVar.a;
            s38.b(settings);
            list4 = list11;
            list5 = (List) settings;
            HashSet hashSet = new HashSet();
            arrayList = new ArrayList();
            for (Object obj2 : list5) {
                if (hashSet.add(((t.b) obj2).a.e)) {
                    arrayList.add(obj2);
                }
            }
            if (arrayList.size() < list5.size()) {
                list5.size();
                arrayList.size();
            }
            list4.addAll(arrayList);
            list4.size();
            str8 = str7;
            num5 = num7;
            num4 = num6;
            contentItem3 = contentItem4;
            list2 = list4;
            subtitleManager4 = subtitleManager3;
            list3 = list;
            if ((list3 instanceof Collection) || !list3.isEmpty()) {
                it = list3.iterator();
                while (it.hasNext()) {
                    if (n89.l(((InstalledAddon) it.next()).getEffectiveBaseUrl(), "opensubtitles", true)) {
                        z = true;
                        break;
                    }
                }
            }
            z = false;
            if (list2.isEmpty() || z) {
                str9 = str8;
                list6 = list2;
                String str16 = str9;
                subtitleManager5 = subtitleManager4;
                zIsEmpty = list6.isEmpty();
                list8 = list6;
                if (zIsEmpty) {
                }
                return ck1Var;
            }
            Integer numBoxInt = Boxing.boxInt(contentItem3.getTmdbId());
            String title = contentItem3.getTitle();
            String year = contentItem3.getYear();
            u uVar = new u(str8, numBoxInt, title, year != null ? n89.be(year) : null, (num4 == null || num4.intValue() <= 0) ? null : num4, (num5 == null || num5.intValue() <= 0) ? null : num5, (num4 == null || num4.intValue() <= 0) ? u.a.a : u.a.b);
            str9 = str8;
            StremioSubtitleProvider stremioSubtitleProvider = subtitleManager4.a;
            pVar.a = subtitleManager4;
            pVar.b = contentItem3;
            pVar.c = num4;
            pVar.d = num5;
            pVar.e = str9;
            pVar.f = list2;
            pVar.i = null;
            pVar.j = null;
            pVar.k = null;
            pVar.n = 3;
            objD = stremioSubtitleProvider.d(uVar, pVar);
            list7 = list2;
        } else {
            if (i2 == 3) {
                List list12 = (List) pVar.f;
                str9 = pVar.e;
                num5 = pVar.d;
                num4 = pVar.c;
                contentItem3 = (ContentItem) pVar.b;
                subtitleManager4 = (SubtitleManager) pVar.a;
                s38.b(settings);
                objD = ((q38) settings).a;
                list7 = list12;
                if (q38.a(objD) != null) {
                    objD = obj;
                }
                List list13 = (List) objD;
                list6 = list7;
                if (!list13.isEmpty()) {
                    list13.size();
                    List list14 = list13;
                    ArrayList arrayList2 = new ArrayList(y41.p(list14, 10));
                    Iterator it2 = list14.iterator();
                    while (it2.hasNext()) {
                        arrayList2.add(new t.b((sb9) it2.next(), t.b.a.a));
                    }
                    list7.addAll(arrayList2);
                    list6 = list7;
                }
                String str162 = str9;
                subtitleManager5 = subtitleManager4;
                zIsEmpty = list6.isEmpty();
                list8 = list6;
                if (zIsEmpty) {
                    PlayerSettingsRepository playerSettingsRepository = subtitleManager5.e;
                    pVar.a = list8;
                    pVar.b = null;
                    pVar.c = null;
                    pVar.d = null;
                    pVar.e = null;
                    pVar.f = null;
                    pVar.i = null;
                    pVar.j = null;
                    pVar.k = null;
                    pVar.n = 5;
                    settings = playerSettingsRepository.getSettings(pVar);
                    list10 = list8;
                } else {
                    Integer numBoxInt2 = Boxing.boxInt(contentItem3.getTmdbId());
                    String title2 = contentItem3.getTitle();
                    String year2 = contentItem3.getYear();
                    u uVar2 = new u(str162, numBoxInt2, title2, year2 != null ? n89.be(year2) : null, (num4 == null || num4.intValue() <= 0) ? null : num4, (num5 == null || num5.intValue() <= 0) ? null : num5, (num4 == null || num4.intValue() <= 0) ? u.a.a : u.a.b);
                    OpenSubtitlesProvider openSubtitlesProvider = subtitleManager5.b;
                    pVar.a = subtitleManager5;
                    pVar.b = list6;
                    pVar.c = null;
                    pVar.d = null;
                    pVar.e = null;
                    pVar.f = null;
                    pVar.i = null;
                    pVar.j = null;
                    pVar.k = null;
                    pVar.n = 4;
                    objE = openSubtitlesProvider.e(uVar2, pVar);
                    list9 = list6;
                }
                return ck1Var;
            }
            if (i2 != 4) {
                if (i2 != 5) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                List list15 = (List) pVar.a;
                s38.b(settings);
                list10 = list15;
                String strA = a.a(((PlayerSettings) settings).getDefaultSubtitleLanguage());
                List listBj = y41.bj(new kb9(new jb9(new gb9())), list10);
                LinkedHashMap linkedHashMap = new LinkedHashMap();
                for (Object obj3 : listBj) {
                    String strA2 = a.a(((t.b) obj3).a.d);
                    Object arrayList3 = linkedHashMap.get(strA2);
                    if (arrayList3 == null) {
                        arrayList3 = new ArrayList();
                        linkedHashMap.put(strA2, arrayList3);
                    }
                    ((List) arrayList3).add(obj3);
                }
                ArrayList arrayList4 = new ArrayList();
                Iterator it3 = linkedHashMap.entrySet().iterator();
                while (it3.hasNext()) {
                    y41.i(y41.bk((List) ((Map.Entry) it3.next()).getValue(), 8), arrayList4);
                }
                list10.size();
                arrayList4.size();
                return y41.bj(new lb9(new ib9(new hb9(strA))), arrayList4);
            }
            List list16 = (List) pVar.b;
            subtitleManager5 = (SubtitleManager) pVar.a;
            s38.b(settings);
            objE = ((q38) settings).a;
            list9 = list16;
            if (q38.a(objE) == null) {
                obj = objE;
            }
            List list17 = (List) obj;
            ArrayList arrayList5 = new ArrayList(y41.p(list17, 10));
            Iterator it4 = list17.iterator();
            while (it4.hasNext()) {
                arrayList5.add(new t.b((sb9) it4.next(), t.b.a.b));
            }
            list9.addAll(arrayList5);
            list8 = list9;
            PlayerSettingsRepository playerSettingsRepository2 = subtitleManager5.e;
            pVar.a = list8;
            pVar.b = null;
            pVar.c = null;
            pVar.d = null;
            pVar.e = null;
            pVar.f = null;
            pVar.i = null;
            pVar.j = null;
            pVar.k = null;
            pVar.n = 5;
            settings = playerSettingsRepository2.getSettings(pVar);
            list10 = list8;
        }
        List list18 = (List) settings;
        list18.size();
        ArrayList arrayList6 = new ArrayList();
        if (list18.isEmpty()) {
            subtitleManager3 = subtitleManager2;
            num4 = num8;
            str8 = str7;
            list = list18;
            contentItem3 = contentItem2;
            num5 = num3;
            list2 = arrayList6;
            subtitleManager4 = subtitleManager3;
            list3 = list;
            if (list3 instanceof Collection) {
            }
            it = list3.iterator();
            while (it.hasNext()) {
            }
            z = false;
            if (list2.isEmpty()) {
            }
            str9 = str8;
            list6 = list2;
            String str1622 = str9;
            subtitleManager5 = subtitleManager4;
            zIsEmpty = list6.isEmpty();
            list8 = list6;
            if (zIsEmpty) {
            }
            return ck1Var;
        }
        r rVar = new r(list18, subtitleManager2, str3, str4, str5, str6, null);
        subtitleManager3 = subtitleManager2;
        pVar.a = subtitleManager3;
        pVar.b = contentItem2;
        pVar.c = num8;
        pVar.d = num3;
        pVar.e = str7;
        pVar.f = list18;
        pVar.i = arrayList6;
        pVar.j = null;
        pVar.k = null;
        pVar.n = 2;
        Object objC = bk1.c(rVar, pVar);
        if (objC != ck1Var) {
            num6 = num8;
            list = list18;
            settings = objC;
            num7 = num3;
            contentItem4 = contentItem2;
            list4 = arrayList6;
            list5 = (List) settings;
            HashSet hashSet2 = new HashSet();
            arrayList = new ArrayList();
            while (r7.hasNext()) {
            }
            if (arrayList.size() < list5.size()) {
            }
            list4.addAll(arrayList);
            list4.size();
            str8 = str7;
            num5 = num7;
            num4 = num6;
            contentItem3 = contentItem4;
            list2 = list4;
            subtitleManager4 = subtitleManager3;
            list3 = list;
            if (list3 instanceof Collection) {
            }
            it = list3.iterator();
            while (it.hasNext()) {
            }
            z = false;
            if (list2.isEmpty()) {
            }
            str9 = str8;
            list6 = list2;
            String str16222 = str9;
            subtitleManager5 = subtitleManager4;
            zIsEmpty = list6.isEmpty();
            list8 = list6;
            if (zIsEmpty) {
            }
        }
        return ck1Var;
    }

    public static final sb9 b(SubtitleManager subtitleManager, StremioSubtitle stremioSubtitle, String str) {
        String lowerCase;
        subtitleManager.getClass();
        String url = stremioSubtitle.getUrl();
        if (url == null) {
            return null;
        }
        String id = stremioSubtitle.getId();
        if (id == null) {
            id = String.valueOf(url.hashCode());
        }
        String lowerCase2 = "srt";
        if (!n89.l(url, ".srt", true)) {
            if (n89.l(url, ".vtt", true)) {
                lowerCase2 = "vtt";
            } else if (n89.l(url, ".ass", true)) {
                lowerCase2 = "ass";
            } else if (n89.l(url, ".ssa", true)) {
                lowerCase2 = "ssa";
            } else {
                String subFormat = stremioSubtitle.getSubFormat();
                if (subFormat != null) {
                    lowerCase2 = subFormat.toLowerCase(Locale.ROOT);
                    cr4.f(lowerCase2, "toLowerCase(...)");
                }
            }
        }
        String str2 = lowerCase2;
        String subFileName = stremioSubtitle.getSubFileName();
        if (subFileName != null) {
            lowerCase = subFileName.toLowerCase(Locale.ROOT);
            cr4.f(lowerCase, "toLowerCase(...)");
        } else {
            lowerCase = "";
        }
        boolean z = n89.l(lowerCase, "forced", false) || n89.l(lowerCase, "foreign", false) || n89.l(lowerCase, "non-english", false) || n89.l(lowerCase, "non english", false);
        boolean z2 = n89.l(lowerCase, ".hi.", false) || n89.l(lowerCase, "[hi]", false) || n89.l(lowerCase, "(hi)", false) || n89.l(lowerCase, "sdh", false) || n89.l(lowerCase, "hearing", false);
        String subFileName2 = stremioSubtitle.getSubFileName();
        if (subFileName2 == null) {
            String strAz = n89.az(n89.ax(url, DomExceptionUtils.SEPARATOR), "?");
            subFileName2 = (!n89.l(strAz, ".", false) || strAz.length() <= 4) ? n41.n("Subtitle #", id) : URLDecoder.decode(strAz, "UTF-8");
        }
        cr4.d(subFileName2);
        Integer numBe = null;
        String displayLabel = stremioSubtitle.getDisplayLabel();
        String lang = stremioSubtitle.getLang();
        if (lang == null) {
            lang = "en";
        }
        String subRating = stremioSubtitle.getSubRating();
        Float fBd = subRating != null ? n89.bd(subRating) : null;
        String subDownloadsCnt = stremioSubtitle.getSubDownloadsCnt();
        if (subDownloadsCnt != null) {
            numBe = n89.be(n89.an(subDownloadsCnt, ",", ""));
        }
        return new sb9(id, subFileName2, displayLabel, lang, url, fBd, numBe, false, false, false, str2, null, z2, z, null, str);
    }

    public static String e(long j) {
        long j2 = 3600000;
        long j3 = j / j2;
        long j4 = ExoPlayer.DEFAULT_STUCK_PLAYING_NOT_ENDING_TIMEOUT_MS;
        long j5 = 1000;
        return String.format("%02d:%02d:%02d,%03d", Arrays.copyOf(new Object[]{Long.valueOf(j3), Long.valueOf((j % j2) / j4), Long.valueOf((j % j4) / j5), Long.valueOf(j % j5)}, 4));
    }

    public static String f(long j) {
        long j2 = 3600000;
        long j3 = j / j2;
        long j4 = ExoPlayer.DEFAULT_STUCK_PLAYING_NOT_ENDING_TIMEOUT_MS;
        long j5 = 1000;
        return String.format("%02d:%02d:%02d.%03d", Arrays.copyOf(new Object[]{Long.valueOf(j3), Long.valueOf((j % j2) / j4), Long.valueOf((j % j4) / j5), Long.valueOf(j % j5)}, 4));
    }

    /* JADX WARN: Type inference failed for: r2v1, types: [java.lang.Object, java.util.Map] */
    public static String h(String str) {
        if (str == null) {
            return "Unknown";
        }
        Locale locale = Locale.ROOT;
        String lowerCase = str.toLowerCase(locale);
        cr4.f(lowerCase, "toLowerCase(...)");
        String str2 = (String) g.get(lowerCase);
        if (str2 != null) {
            return str2;
        }
        String upperCase = str.toUpperCase(locale);
        cr4.f(upperCase, "toUpperCase(...)");
        return upperCase;
    }

    public static final boolean j(t.a aVar) {
        String lowerCase = aVar.d.toLowerCase(Locale.ROOT);
        cr4.f(lowerCase, "toLowerCase(...)");
        return n89.l(lowerCase, "sdh", false) || n89.l(lowerCase, "hearing", false);
    }

    public static final boolean k(String str, t.b bVar) {
        return a.a(bVar.a.d).equals(str);
    }

    /* JADX WARN: Type inference failed for: r3v1, types: [java.lang.Object, java.util.Map] */
    public static final boolean l(String str, t.a aVar) {
        String str2 = aVar.c;
        Locale locale = Locale.ROOT;
        String lowerCase = str2.toLowerCase(locale);
        cr4.f(lowerCase, "toLowerCase(...)");
        if (!n89.l(lowerCase, str, false)) {
            String str3 = (String) g.get(str);
            if (str3 != null) {
                String lowerCase2 = str3.toLowerCase(locale);
                cr4.f(lowerCase2, "toLowerCase(...)");
                if (n89.l(lowerCase, lowerCase2, false)) {
                }
            }
            return false;
        }
        return true;
    }

    public static boolean m(Format format) {
        String str = format.sampleMimeType;
        if (str == null) {
            return false;
        }
        return str.equals(MimeTypes.APPLICATION_PGS) || str.equals(MimeTypes.APPLICATION_VOBSUB) || str.equals(MimeTypes.APPLICATION_DVBSUBS) || n89.l(str, "pgs", true) || n89.l(str, "vobsub", true) || n89.l(str, "dvb", true);
    }

    public final Object c(File file, long j, Continuation continuation) {
        m12 m12Var = sc2.a;
        return wj0.f(m02.c, new l(j, file, this, null), continuation);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object d(sb9 sb9Var, t.b.a aVar, ContinuationImpl continuationImpl) {
        m mVar;
        if (continuationImpl instanceof m) {
            mVar = (m) continuationImpl;
            int i = mVar.c;
            if ((i & Integer.MIN_VALUE) != 0) {
                mVar.c = i - Integer.MIN_VALUE;
            } else {
                mVar = new m(this, continuationImpl);
            }
        }
        Object obj = mVar.a;
        ck1 ck1Var = ck1.a;
        int i2 = mVar.c;
        if (i2 != 0) {
            if (i2 != 1 && i2 != 2) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s38.b(obj);
            return ((q38) obj).a;
        }
        s38.b(obj);
        int iOrdinal = aVar.ordinal();
        if (iOrdinal == 0) {
            mVar.c = 1;
            Object objB = this.a.b(sb9Var, mVar);
            if (objB != ck1Var) {
                return objB;
            }
        } else {
            if (iOrdinal != 1) {
                throw new io6();
            }
            mVar.c = 2;
            Object objC = this.b.c(sb9Var, mVar);
            if (objC != ck1Var) {
                return objC;
            }
        }
        return ck1Var;
    }

    public final Object g(Tracks tracks, ContentItem contentItem, Integer num, Integer num2, String str, String str2, ContinuationImpl continuationImpl) {
        m12 m12Var = sc2.a;
        return wj0.f(m02.c, new n(this, tracks, contentItem, num, num2, str, str2, null), continuationImpl);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object i(List list, ContinuationImpl continuationImpl) {
        o oVar;
        Object next;
        Object next2;
        Object next3;
        Object next4;
        Object next5;
        if (continuationImpl instanceof o) {
            oVar = (o) continuationImpl;
            int i = oVar.d;
            if ((i & Integer.MIN_VALUE) != 0) {
                oVar.d = i - Integer.MIN_VALUE;
            } else {
                oVar = new o(this, continuationImpl);
            }
        }
        Object settings = oVar.b;
        ck1 ck1Var = ck1.a;
        int i2 = oVar.d;
        if (i2 == 0) {
            s38.b(settings);
            oVar.a = list;
            oVar.d = 1;
            settings = this.e.getSettings(oVar);
            if (settings == ck1Var) {
                return ck1Var;
            }
        } else {
            if (i2 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            list = oVar.a;
            s38.b(settings);
        }
        String defaultSubtitleLanguage = ((PlayerSettings) settings).getDefaultSubtitleLanguage();
        if (defaultSubtitleLanguage != null) {
            String lowerCase = defaultSubtitleLanguage.toLowerCase(Locale.ROOT);
            cr4.f(lowerCase, "toLowerCase(...)");
            String strA = a.a(lowerCase);
            List list2 = list;
            ArrayList arrayList = new ArrayList();
            for (Object obj : list2) {
                if (obj instanceof t.a) {
                    arrayList.add(obj);
                }
            }
            ArrayList arrayList2 = new ArrayList();
            for (Object obj2 : arrayList) {
                if (!((t.a) obj2).e) {
                    arrayList2.add(obj2);
                }
            }
            ArrayList arrayList3 = new ArrayList();
            for (Object obj3 : list2) {
                if (obj3 instanceof t.b) {
                    arrayList3.add(obj3);
                }
            }
            ArrayList arrayList4 = new ArrayList();
            for (Object obj4 : arrayList3) {
                if (!((t.b) obj4).a.n) {
                    arrayList4.add(obj4);
                }
            }
            Iterator it = arrayList2.iterator();
            while (true) {
                if (!it.hasNext()) {
                    next = null;
                    break;
                }
                next = it.next();
                t.a aVar = (t.a) next;
                if (j(aVar) && l(strA, aVar)) {
                    break;
                }
            }
            t.a aVar2 = (t.a) next;
            if (aVar2 != null) {
                return aVar2;
            }
            Iterator it2 = arrayList2.iterator();
            while (true) {
                if (!it2.hasNext()) {
                    next2 = null;
                    break;
                }
                next2 = it2.next();
                t.a aVar3 = (t.a) next2;
                if (!j(aVar3) && l(strA, aVar3)) {
                    break;
                }
            }
            t.a aVar4 = (t.a) next2;
            if (aVar4 != null) {
                return aVar4;
            }
            Iterator it3 = arrayList4.iterator();
            while (true) {
                if (!it3.hasNext()) {
                    next3 = null;
                    break;
                }
                next3 = it3.next();
                t.b bVar = (t.b) next3;
                sb9 sb9Var = bVar.a;
                if (sb9Var.m && sb9Var.h && k(strA, bVar)) {
                    break;
                }
            }
            t.b bVar2 = (t.b) next3;
            if (bVar2 != null) {
                return bVar2;
            }
            Iterator it4 = arrayList4.iterator();
            while (true) {
                if (!it4.hasNext()) {
                    next4 = null;
                    break;
                }
                next4 = it4.next();
                t.b bVar3 = (t.b) next4;
                sb9 sb9Var2 = bVar3.a;
                if (!sb9Var2.m && sb9Var2.h && k(strA, bVar3)) {
                    break;
                }
            }
            t.b bVar4 = (t.b) next4;
            if (bVar4 != null) {
                return bVar4;
            }
            Iterator it5 = arrayList4.iterator();
            while (true) {
                if (!it5.hasNext()) {
                    next5 = null;
                    break;
                }
                next5 = it5.next();
                t.b bVar5 = (t.b) next5;
                if (bVar5.a.m && k(strA, bVar5)) {
                    break;
                }
            }
            t.b bVar6 = (t.b) next5;
            if (bVar6 != null) {
                return bVar6;
            }
            for (Object obj5 : arrayList4) {
                t.b bVar7 = (t.b) obj5;
                if (!bVar7.a.m && k(strA, bVar7)) {
                    return obj5;
                }
            }
        }
        return null;
    }
}
