package xyz.netfly.player;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import xyz.stream.api.entity.CmsVideoSource;
import xyz.stream.utils.f0;

/* JADX INFO: loaded from: classes3.dex */
public final class r {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final boolean f35274a;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public ag.g f35277d;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ArrayList f35275b = new ArrayList();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f35276c = 0;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final List f35278e = Arrays.asList("4K", "2160P", "1440P", "CINEMAX", "CINEMA", "1080P HD", "1080P", "1080", "720P", "720", "SD", "480P", "480", "360P", "360", "240P", "240");

    public r(boolean z10) {
        this.f35274a = z10;
    }

    public static String a(List list) {
        if (list == null || list.isEmpty()) {
            return "";
        }
        String strQ = f0.o().q("sp_vod_bitrate", null);
        if (strQ == null || strQ.isEmpty()) {
            t4.d dVarG = t4.f.x(list).e(new fa.h(28)).g();
            Object obj = (CmsVideoSource) list.get(0);
            Object obj2 = dVarG.f32947a;
            if (obj2 != null) {
                obj = obj2;
            }
            return ((CmsVideoSource) list.get(list.indexOf(obj))).getVideoSource();
        }
        Object obj3 = t4.f.x(list).e(new com.google.firebase.messaging.m(strQ, 10)).g().f32947a;
        CmsVideoSource cmsVideoSource = (CmsVideoSource) (obj3 != null ? obj3 : null);
        if (cmsVideoSource != null) {
            return cmsVideoSource.getVideoSource();
        }
        t4.d dVarG2 = t4.f.x(list).e(new fa.h(27)).g();
        Object obj4 = (CmsVideoSource) list.get(0);
        Object obj5 = dVarG2.f32947a;
        if (obj5 != null) {
            obj4 = obj5;
        }
        return ((CmsVideoSource) list.get(list.indexOf(obj4))).getVideoSource();
    }

    public final String b(CmsVideoSource cmsVideoSource) {
        String sourceQuality = cmsVideoSource.getSourceQuality();
        if (sourceQuality != null && !sourceQuality.isEmpty()) {
            return sourceQuality;
        }
        return "Source - " + (this.f35275b.indexOf(cmsVideoSource) + 1);
    }

    public final String c() {
        int i10;
        ArrayList arrayList = this.f35275b;
        if (arrayList.isEmpty() || (i10 = this.f35276c) < 0 || i10 >= arrayList.size()) {
            return null;
        }
        return b((CmsVideoSource) arrayList.get(this.f35276c));
    }

    public final boolean d(int i10) {
        if (i10 < 0) {
            return false;
        }
        ArrayList arrayList = this.f35275b;
        if (i10 >= arrayList.size() || i10 == this.f35276c) {
            return false;
        }
        this.f35276c = i10;
        CmsVideoSource cmsVideoSource = (CmsVideoSource) arrayList.get(i10);
        String sourceQuality = cmsVideoSource.getSourceQuality();
        f0 f0VarO = f0.o();
        if (sourceQuality == null || sourceQuality.isEmpty()) {
            sourceQuality = "";
        }
        f0VarO.w("sp_vod_bitrate", sourceQuality);
        ag.g gVar = this.f35277d;
        if (gVar == null) {
            return true;
        }
        gVar.n(cmsVideoSource.getVideoSource());
        return true;
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x005d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void e(List list) {
        int iMax;
        ArrayList arrayList = this.f35275b;
        if (list == null || list.isEmpty()) {
            arrayList.clear();
            this.f35276c = 0;
            return;
        }
        arrayList.clear();
        arrayList.addAll(list);
        int i10 = 1;
        if (this.f35274a) {
            Collections.sort(arrayList, new com.google.android.material.button.c(this, i10));
        }
        if (arrayList.size() == 1) {
            this.f35276c = 0;
            return;
        }
        String strQ = f0.o().q("sp_vod_bitrate", null);
        if (strQ == null || strQ.isEmpty()) {
            t4.d dVarG = t4.f.x(arrayList).e(new fa.h(26)).g();
            Object obj = (CmsVideoSource) arrayList.get(0);
            Object obj2 = dVarG.f32947a;
            if (obj2 != null) {
                obj = obj2;
            }
            iMax = Math.max(arrayList.indexOf((CmsVideoSource) obj), 0);
        } else {
            Object obj3 = t4.f.x(arrayList).e(new com.google.firebase.messaging.m(strQ, 9)).g().f32947a;
            CmsVideoSource cmsVideoSource = (CmsVideoSource) (obj3 != null ? obj3 : null);
            if (cmsVideoSource != null) {
                iMax = arrayList.indexOf(cmsVideoSource);
            }
        }
        this.f35276c = iMax;
    }

    public final String f(List list) {
        ArrayList arrayList = this.f35275b;
        int i10 = arrayList.isEmpty() ? -1 : this.f35276c;
        e(list);
        if (arrayList.isEmpty()) {
            return "";
        }
        if (arrayList.size() > 1 && i10 >= 0) {
            this.f35276c = (i10 + 1) % arrayList.size();
        }
        String videoSource = ((CmsVideoSource) arrayList.get(this.f35276c)).getVideoSource();
        return videoSource == null ? "" : videoSource;
    }
}
