package com.strmr.ps.data.subtitle;

import androidx.media3.common.Format;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.Tracks;
import com.strmr.ps.data.model.ContentItem;
import com.strmr.ps.data.subtitle.t;
import defpackage.ak1;
import defpackage.bb9;
import defpackage.cb9;
import defpackage.ck1;
import defpackage.cr4;
import defpackage.db9;
import defpackage.e6a;
import defpackage.eb9;
import defpackage.gr3;
import defpackage.n89;
import defpackage.s38;
import defpackage.tb9;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* 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\u00020\u0001*\u00020\u0000H\n¢\u0006\u0004\b\u0002\u0010\u0003"}, d2 = {"Lak1;", "Ltb9;", "<anonymous>", "(Lak1;)Ltb9;"}, k = 3, mv = {2, 0, 0})
@DebugMetadata(c = "com.strmr.ps.data.subtitle.SubtitleManager$getAvailableSubtitlesWithInfo$2", f = "SubtitleManager.kt", i = {0, 0}, l = {261}, m = "invokeSuspend", n = {"results", "unsupportedCount"}, s = {"L$0", "I$0"})
final class n extends SuspendLambda implements gr3<ak1, Continuation<? super tb9>, Object> {
    public ArrayList a;
    public int b;
    public int c;
    public final /* synthetic */ SubtitleManager d;
    public final /* synthetic */ Tracks e;
    public final /* synthetic */ ContentItem f;
    public final /* synthetic */ Integer i;
    public final /* synthetic */ Integer j;
    public final /* synthetic */ String k;
    public final /* synthetic */ String l;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public n(SubtitleManager subtitleManager, Tracks tracks, ContentItem contentItem, Integer num, Integer num2, String str, String str2, Continuation continuation) {
        super(2, continuation);
        this.d = subtitleManager;
        this.e = tracks;
        this.f = contentItem;
        this.i = num;
        this.j = num2;
        this.k = str;
        this.l = str2;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        return new n(this.d, this.e, this.f, this.i, this.j, this.k, this.l, continuation);
    }

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

    /* JADX WARN: Removed duplicated region for block: B:52:0x00ec  */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00f8  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x00fb  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x0101  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0108  */
    /* JADX WARN: Removed duplicated region for block: B:75:0x0175  */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        ArrayList arrayList;
        int iIntValue;
        boolean z;
        Object objA;
        ArrayList arrayList2;
        Iterator<Tracks.Group> it;
        String strH;
        ck1 ck1Var = ck1.a;
        int i = this.c;
        if (i == 0) {
            s38.b(obj);
            arrayList = new ArrayList();
            arrayList.add(t.c.a);
            Object obj2 = SubtitleManager.g;
            ArrayList arrayList3 = new ArrayList();
            Iterator<Tracks.Group> it2 = this.e.getGroups().iterator();
            int i2 = 0;
            int i3 = 0;
            while (it2.hasNext()) {
                int i4 = i3 + 1;
                Tracks.Group next = it2.next();
                if (next.getType() == 3) {
                    int i5 = next.length;
                    int i6 = 0;
                    while (i6 < i5) {
                        Format trackFormat = next.getTrackFormat(i6);
                        cr4.f(trackFormat, "getTrackFormat(...)");
                        String str = trackFormat.sampleMimeType;
                        if (SubtitleManager.m(trackFormat)) {
                            i2++;
                        }
                        String str2 = trackFormat.sampleMimeType;
                        if (str2 == null) {
                            it = it2;
                        } else {
                            if (n89.ar(str2, "text/", false) || n89.ar(str2, MimeTypes.APPLICATION_SUBRIP, false)) {
                                it = it2;
                            } else {
                                it = it2;
                                if (n89.ar(str2, "application/ttml", false) || str2.equals(MimeTypes.APPLICATION_SUBRIP) || str2.equals(MimeTypes.APPLICATION_TTML) || str2.equals(MimeTypes.TEXT_VTT) || str2.equals(MimeTypes.APPLICATION_MP4VTT) || str2.equals(MimeTypes.APPLICATION_CEA608) || str2.equals(MimeTypes.APPLICATION_CEA708) || str2.equals(MimeTypes.APPLICATION_TX3G) || n89.l(str2, "tx3g", true) || n89.l(str2, "quicktime", true)) {
                                }
                                i6++;
                                it2 = it;
                            }
                            String strH2 = SubtitleManager.h(trackFormat.language);
                            strH = trackFormat.label;
                            if (strH == null) {
                                strH = SubtitleManager.h(trackFormat.language);
                            }
                            int i7 = trackFormat.selectionFlags;
                            arrayList3.add(new t.a(i6, i3, strH2, strH, (i7 & 2) == 0, (i7 & 1) == 0, str));
                            i6++;
                            it2 = it;
                        }
                        if (SubtitleManager.m(trackFormat)) {
                            String strH22 = SubtitleManager.h(trackFormat.language);
                            strH = trackFormat.label;
                            if (strH == null) {
                            }
                            int i72 = trackFormat.selectionFlags;
                            arrayList3.add(new t.a(i6, i3, strH22, strH, (i72 & 2) == 0, (i72 & 1) == 0, str));
                        }
                        i6++;
                        it2 = it;
                    }
                }
                i3 = i4;
            }
            List listBj = y41.bj(new db9(new cb9(new eb9(new bb9()))), arrayList3);
            iIntValue = Integer.valueOf(i2).intValue();
            arrayList.addAll(listBj);
            listBj.size();
            ContentItem contentItem = this.f;
            if (contentItem == null) {
                z = true;
                return new tb9(iIntValue, arrayList, iIntValue > 0 ? z : false);
            }
            this.a = arrayList;
            this.b = iIntValue;
            z = true;
            this.c = 1;
            objA = SubtitleManager.a(this.d, contentItem, this.i, this.j, this.k, this.l, this);
            if (objA == ck1Var) {
                return ck1Var;
            }
            arrayList2 = arrayList;
        } else {
            if (i != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            int i8 = this.b;
            arrayList2 = this.a;
            s38.b(obj);
            z = true;
            iIntValue = i8;
            objA = obj;
        }
        List list = (List) objA;
        arrayList2.addAll(list);
        list.size();
        arrayList = arrayList2;
        return new tb9(iIntValue, arrayList, iIntValue > 0 ? z : false);
    }
}
