package p138.p176.p177.p190.p217.p222.p223;

import android.net.Uri;
import android.text.TextUtils;
import android.util.Base64;
import com.google.android.exoplayer2.ParserException;
import com.google.android.exoplayer2.source.UnrecognizedInputFormatException;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.checkerframework.checker.nullness.qual.EnsuresNonNullIf;
import p000.p001.p002.p003.p004.C0567;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p190.C3414;
import p138.p176.p177.p190.C3431;
import p138.p176.p177.p190.p194.C3526;
import p138.p176.p177.p190.p210.C3710;
import p138.p176.p177.p190.p217.p222.C3915;
import p138.p176.p177.p190.p217.p222.p223.C3926;
import p138.p176.p177.p190.p217.p222.p223.C3929;
import p138.p176.p177.p190.p238.C4112;
import p138.p176.p177.p190.p239.C4134;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໞ.ޟ.ސ.ޅ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C3932 implements C4112.InterfaceC4113<AbstractC3931> {

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static final Pattern f12276 = Pattern.compile("AVERAGE-BANDWIDTH=(\\d+)\\b");

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public static final Pattern f12277 = Pattern.compile("VIDEO=\"(.+?)\"");

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public static final Pattern f12278 = Pattern.compile("AUDIO=\"(.+?)\"");

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public static final Pattern f12279 = Pattern.compile("SUBTITLES=\"(.+?)\"");

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public static final Pattern f12280 = Pattern.compile("CLOSED-CAPTIONS=\"(.+?)\"");

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public static final Pattern f12281 = Pattern.compile("[^-]BANDWIDTH=(\\d+)\\b");

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public static final Pattern f12282 = Pattern.compile("CHANNELS=\"(.+?)\"");

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public static final Pattern f12283 = Pattern.compile("CODECS=\"(.+?)\"");

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public static final Pattern f12284 = Pattern.compile("RESOLUTION=(\\d+x\\d+)");

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public static final Pattern f12285 = Pattern.compile("FRAME-RATE=([\\d\\.]+)\\b");

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public static final Pattern f12286 = Pattern.compile("#EXT-X-TARGETDURATION:(\\d+)\\b");

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public static final Pattern f12287 = Pattern.compile("#EXT-X-VERSION:(\\d+)\\b");

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public static final Pattern f12288 = Pattern.compile("#EXT-X-PLAYLIST-TYPE:(.+)\\b");

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public static final Pattern f12289 = Pattern.compile("#EXT-X-MEDIA-SEQUENCE:(\\d+)\\b");

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public static final Pattern f12290 = Pattern.compile("#EXTINF:\\s*([\\d\\.]+)\\b");

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public static final Pattern f12291 = Pattern.compile("#EXTINF:[\\d\\.]+\\b,(.+)");

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public static final Pattern f12292 = Pattern.compile("TIME-OFFSET=(-?[\\d\\.]+)\\b");

    /* JADX INFO: renamed from: ސ, reason: contains not printable characters */
    public static final Pattern f12293 = Pattern.compile("#EXT-X-BYTERANGE:(\\d+(?:@\\d+)?)\\b");

    /* JADX INFO: renamed from: ޑ, reason: contains not printable characters */
    public static final Pattern f12294 = Pattern.compile("BYTERANGE=\"(\\d+(?:@\\d+)?)\\b\"");

    /* JADX INFO: renamed from: ޒ, reason: contains not printable characters */
    public static final Pattern f12295 = Pattern.compile("METHOD=(NONE|AES-128|SAMPLE-AES|SAMPLE-AES-CENC|SAMPLE-AES-CTR)\\s*(?:,|$)");

    /* JADX INFO: renamed from: ޓ, reason: contains not printable characters */
    public static final Pattern f12296 = Pattern.compile("KEYFORMAT=\"(.+?)\"");

    /* JADX INFO: renamed from: ޔ, reason: contains not printable characters */
    public static final Pattern f12297 = Pattern.compile("KEYFORMATVERSIONS=\"(.+?)\"");

    /* JADX INFO: renamed from: ޕ, reason: contains not printable characters */
    public static final Pattern f12298 = Pattern.compile("URI=\"(.+?)\"");

    /* JADX INFO: renamed from: ޖ, reason: contains not printable characters */
    public static final Pattern f12299 = Pattern.compile("IV=([^,.*]+)");

    /* JADX INFO: renamed from: ޗ, reason: contains not printable characters */
    public static final Pattern f12300 = Pattern.compile("TYPE=(AUDIO|VIDEO|SUBTITLES|CLOSED-CAPTIONS)");

    /* JADX INFO: renamed from: ޘ, reason: contains not printable characters */
    public static final Pattern f12301 = Pattern.compile("LANGUAGE=\"(.+?)\"");

    /* JADX INFO: renamed from: ޙ, reason: contains not printable characters */
    public static final Pattern f12302 = Pattern.compile("NAME=\"(.+?)\"");

    /* JADX INFO: renamed from: ޚ, reason: contains not printable characters */
    public static final Pattern f12303 = Pattern.compile("GROUP-ID=\"(.+?)\"");

    /* JADX INFO: renamed from: ޛ, reason: contains not printable characters */
    public static final Pattern f12304 = Pattern.compile("CHARACTERISTICS=\"(.+?)\"");

    /* JADX INFO: renamed from: ޜ, reason: contains not printable characters */
    public static final Pattern f12305 = Pattern.compile("INSTREAM-ID=\"((?:CC|SERVICE)\\d+)\"");

    /* JADX INFO: renamed from: ޝ, reason: contains not printable characters */
    public static final Pattern f12306 = m6356("AUTOSELECT");

    /* JADX INFO: renamed from: ޞ, reason: contains not printable characters */
    public static final Pattern f12307 = m6356("DEFAULT");

    /* JADX INFO: renamed from: ޟ, reason: contains not printable characters */
    public static final Pattern f12308 = m6356("FORCED");

    /* JADX INFO: renamed from: ޠ, reason: contains not printable characters */
    public static final Pattern f12309 = Pattern.compile("VALUE=\"(.+?)\"");

    /* JADX INFO: renamed from: ޡ, reason: contains not printable characters */
    public static final Pattern f12310 = Pattern.compile("IMPORT=\"(.+?)\"");

    /* JADX INFO: renamed from: ޢ, reason: contains not printable characters */
    public static final Pattern f12311 = Pattern.compile("\\{\\$([a-zA-Z0-9\\-_]+)\\}");

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C3926 f12312;

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ໞ.ޟ.ސ.ޅ$֏, reason: contains not printable characters */
    public static class C3933 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final BufferedReader f12313;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final Queue<String> f12314;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public String f12315;

        public C3933(Queue<String> queue, BufferedReader bufferedReader) {
            this.f12314 = queue;
            this.f12313 = bufferedReader;
        }

        @EnsuresNonNullIf(expression = {"next"}, result = true)
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public boolean m6363() throws IOException {
            String strTrim;
            if (this.f12315 != null) {
                return true;
            }
            if (!this.f12314.isEmpty()) {
                String strPoll = this.f12314.poll();
                C0567.m1856(strPoll);
                this.f12315 = strPoll;
                return true;
            }
            do {
                String line = this.f12313.readLine();
                this.f12315 = line;
                if (line == null) {
                    return false;
                }
                strTrim = line.trim();
                this.f12315 = strTrim;
            } while (strTrim.isEmpty());
            return true;
        }

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public String m6364() {
            if (!m6363()) {
                throw new NoSuchElementException();
            }
            String str = this.f12315;
            this.f12315 = null;
            return str;
        }
    }

    public C3932() {
        this.f12312 = C3926.f12231;
    }

    public C3932(C3926 c3926) {
        this.f12312 = c3926;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static int m6351(BufferedReader bufferedReader, boolean z, int i) throws IOException {
        while (i != -1 && Character.isWhitespace(i) && (z || !C4150.m6806(i))) {
            i = bufferedReader.read();
        }
        return i;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static int m6352(String str, Pattern pattern) {
        return Integer.parseInt(m6362(str, pattern, Collections.emptyMap()));
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static String m6353(String str, Map<String, String> map) {
        Matcher matcher = f12311.matcher(str);
        StringBuffer stringBuffer = new StringBuffer();
        while (matcher.find()) {
            String strGroup = matcher.group(1);
            if (map.containsKey(strGroup)) {
                matcher.appendReplacement(stringBuffer, Matcher.quoteReplacement(map.get(strGroup)));
            }
        }
        matcher.appendTail(stringBuffer);
        return stringBuffer.toString();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static String m6354(String str, Pattern pattern, String str2, Map<String, String> map) {
        Matcher matcher = pattern.matcher(str);
        if (matcher.find()) {
            str2 = matcher.group(1);
        }
        return (map.isEmpty() || str2 == null) ? str2 : m6353(str2, map);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static String m6355(String str, Pattern pattern, Map<String, String> map) {
        return m6354(str, pattern, null, map);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static Pattern m6356(String str) {
        return Pattern.compile(str + "=(NO|YES)");
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static C3526.C3528 m6357(String str, String str2, Map<String, String> map) throws ParserException {
        String strM6354 = m6354(str, f12297, "1", map);
        if ("urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed".equals(str2)) {
            String strM6362 = m6362(str, f12298, map);
            return new C3526.C3528(C3414.f9975, null, "video/mp4", Base64.decode(strM6362.substring(strM6362.indexOf(44)), 0));
        }
        if ("com.widevine".equals(str2)) {
            return new C3526.C3528(C3414.f9975, null, "hls", C4150.m6799(str));
        }
        if (!"com.microsoft.playready".equals(str2) || !"1".equals(strM6354)) {
            return null;
        }
        String strM63622 = m6362(str, f12298, map);
        return new C3526.C3528(C3414.f9976, null, "video/mp4", C0567.m1904(C3414.f9976, Base64.decode(strM63622.substring(strM63622.indexOf(44)), 0)));
    }

    /* 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: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:111:0x0347  */
    /* JADX WARN: Type inference failed for: r1v28 */
    /* JADX WARN: Type inference failed for: r1v29 */
    /* JADX WARN: Type inference failed for: r1v30 */
    /* JADX WARN: Type inference failed for: r1v31 */
    /* JADX WARN: Type inference failed for: r1v6 */
    /* JADX WARN: Type inference failed for: r1v7 */
    /* JADX WARN: Type inference failed for: r31v0 */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static C3926 m6358(C3933 c3933, String str) throws ParserException {
        ArrayList arrayList;
        int i;
        byte b;
        C3926.C3928 c3928;
        String str2;
        int i2;
        int i3;
        float f;
        C3926.C3928 c39282;
        String str3;
        int i4;
        C3926.C3928 c39283;
        String strM6653;
        String strM6757;
        int i5;
        String str4;
        HashMap map;
        HashSet hashSet;
        ArrayList arrayList2;
        ArrayList arrayList3;
        boolean z;
        int i6;
        int i7;
        String str5 = str;
        HashMap map2 = new HashMap();
        HashMap map3 = new HashMap();
        ArrayList arrayList4 = new ArrayList();
        ArrayList arrayList5 = new ArrayList();
        ArrayList arrayList6 = new ArrayList();
        ArrayList arrayList7 = new ArrayList();
        ArrayList arrayList8 = new ArrayList();
        ArrayList arrayList9 = new ArrayList();
        ArrayList arrayList10 = new ArrayList();
        ArrayList arrayList11 = new ArrayList();
        boolean z2 = false;
        boolean z3 = false;
        while (true) {
            int i8 = -1;
            if (!c3933.m6363()) {
                ArrayList arrayList12 = arrayList8;
                ArrayList arrayList13 = arrayList11;
                boolean z4 = z3;
                ArrayList arrayList14 = arrayList10;
                ArrayList arrayList15 = new ArrayList();
                HashSet hashSet2 = new HashSet();
                int i9 = 0;
                HashMap map4 = map2;
                while (true) {
                    arrayList = null;
                    if (i9 >= arrayList4.size()) {
                        break;
                    }
                    C3926.C3928 c39284 = (C3926.C3928) arrayList4.get(i9);
                    if (hashSet2.add(c39284.f12243)) {
                        C0567.m1932(c39284.f12244.f10088 == null);
                        Object obj = map4.get(c39284.f12243);
                        C0567.m1856(obj);
                        C3915 c3915 = new C3915(null, null, (List) obj);
                        C3431 c3431 = c39284.f12244;
                        map = map4;
                        hashSet = hashSet2;
                        arrayList15.add(new C3926.C3928(c39284.f12243, c3431.m5601(c3431.f10093, new C3710(c3915)), c39284.f12245, c39284.f12246, c39284.f12247, c39284.f12248));
                    } else {
                        map = map4;
                        hashSet = hashSet2;
                    }
                    i9++;
                    hashSet2 = hashSet;
                    map4 = map;
                }
                int i10 = 0;
                C3431 c34312 = null;
                while (i10 < arrayList9.size()) {
                    String str6 = (String) arrayList9.get(i10);
                    String strM6362 = m6362(str6, f12303, map3);
                    String strM63622 = m6362(str6, f12302, map3);
                    String strM6355 = m6355(str6, f12298, map3);
                    Uri uriM1934 = strM6355 == null ? null : C0567.m1934(str5, strM6355);
                    String strM63552 = m6355(str6, f12301, map3);
                    ArrayList arrayList16 = arrayList9;
                    boolean zM6360 = m6360(str6, f12307, false);
                    C3431 c34313 = c34312;
                    ?? r1 = zM6360;
                    if (m6360(str6, f12308, false)) {
                        r1 = (zM6360 ? 1 : 0) | 2;
                    }
                    ?? r12 = r1;
                    if (m6360(str6, f12306, false)) {
                        r12 = (r1 == true ? 1 : 0) | 4;
                    }
                    ?? r31 = r12;
                    String strM63553 = m6355(str6, f12304, map3);
                    if (TextUtils.isEmpty(strM63553)) {
                        i = 0;
                    } else {
                        String[] strArrM6781 = C4150.m6781(strM63553, ",");
                        int i11 = C4150.m6771((Object[]) strArrM6781, (Object) "public.accessibility.describes-video") ? 512 : 0;
                        if (C4150.m6771((Object[]) strArrM6781, (Object) "public.accessibility.transcribes-spoken-dialog")) {
                            i11 |= 4096;
                        }
                        if (C4150.m6771((Object[]) strArrM6781, (Object) "public.accessibility.describes-music-and-sound")) {
                            i11 |= 1024;
                        }
                        i = C4150.m6771((Object[]) strArrM6781, (Object) "public.easy-to-read") ? i11 | 8192 : i11;
                    }
                    String strM4880 = C2803.m4880(strM6362, ":", strM63622);
                    ArrayList arrayList17 = arrayList15;
                    boolean z5 = z2;
                    C3710 c3710 = new C3710(new C3915(strM6362, strM63622, Collections.emptyList()));
                    String strM63623 = m6362(str6, f12300, map3);
                    switch (strM63623.hashCode()) {
                        case -959297733:
                            b = !strM63623.equals("SUBTITLES") ? (byte) -1 : (byte) 2;
                            break;
                        case -333210994:
                            if (strM63623.equals("CLOSED-CAPTIONS")) {
                                b = 3;
                                break;
                            }
                            break;
                        case 62628790:
                            if (strM63623.equals("AUDIO")) {
                                b = 1;
                                break;
                            }
                            break;
                        case 81665115:
                            if (strM63623.equals("VIDEO")) {
                                b = 0;
                                break;
                            }
                            break;
                    }
                    if (b == 0) {
                        int i12 = 0;
                        while (true) {
                            if (i12 < arrayList4.size()) {
                                c3928 = (C3926.C3928) arrayList4.get(i12);
                                if (!strM6362.equals(c3928.f12245)) {
                                    i12++;
                                }
                            } else {
                                c3928 = null;
                            }
                        }
                        if (c3928 != null) {
                            C3431 c34314 = c3928.f12244;
                            String strM67572 = C4150.m6757(c34314.f10087, 2);
                            int i13 = c34314.f10095;
                            int i14 = c34314.f10096;
                            f = c34314.f10097;
                            str2 = strM67572;
                            i2 = i13;
                            i3 = i14;
                        } else {
                            str2 = null;
                            i2 = -1;
                            i3 = -1;
                            f = -1.0f;
                        }
                        C3431 c3431M5592 = C3431.m5592(strM4880, strM63622, "application/x-mpegURL", str2 != null ? C4134.m6653(str2) : null, str2, (C3710) null, -1, i2, i3, f, (List<byte[]>) null, r31 == true ? 1 : 0, i);
                        C3431 c3431M5601 = c3431M5592.m5601(c3431M5592.f10093, c3710);
                        if (uriM1934 != null) {
                            arrayList5.add(new C3926.C3927(uriM1934, c3431M5601, strM6362, strM63622));
                        }
                    } else if (b == 1) {
                        int i15 = 0;
                        while (true) {
                            if (i15 < arrayList4.size()) {
                                c39282 = (C3926.C3928) arrayList4.get(i15);
                                if (!strM6362.equals(c39282.f12246)) {
                                    i15++;
                                }
                            } else {
                                c39282 = null;
                            }
                        }
                        String strM67573 = c39282 != null ? C4150.m6757(c39282.f12244.f10087, 1) : null;
                        String strM66532 = strM67573 != null ? C4134.m6653(strM67573) : null;
                        String strM63554 = m6355(str6, f12282, map3);
                        if (strM63554 != null) {
                            int i16 = Integer.parseInt(C4150.m6795(strM63554, "/")[0]);
                            if ("audio/eac3".equals(strM66532) && strM63554.endsWith("/JOC")) {
                                strM66532 = "audio/eac3-joc";
                            }
                            str3 = strM66532;
                            i4 = i16;
                        } else {
                            str3 = strM66532;
                            i4 = -1;
                        }
                        C3431 c3431M5593 = C3431.m5593(strM4880, strM63622, "application/x-mpegURL", str3, strM67573, (C3710) null, -1, i4, -1, (List<byte[]>) null, r31 == true ? 1 : 0, i, strM63552);
                        if (uriM1934 == null) {
                            c34312 = c3431M5593;
                            i10++;
                            str5 = str;
                            arrayList9 = arrayList16;
                            arrayList15 = arrayList17;
                            z2 = z5;
                        } else {
                            arrayList6.add(new C3926.C3927(uriM1934, c3431M5593.m5601(c3431M5593.f10093, c3710), strM6362, strM63622));
                        }
                    } else if (b == 2) {
                        int i17 = 0;
                        while (true) {
                            if (i17 < arrayList4.size()) {
                                c39283 = (C3926.C3928) arrayList4.get(i17);
                                if (!strM6362.equals(c39283.f12247)) {
                                    i17++;
                                }
                            } else {
                                c39283 = null;
                            }
                        }
                        if (c39283 != null) {
                            strM6757 = C4150.m6757(c39283.f12244.f10087, 3);
                            strM6653 = C4134.m6653(strM6757);
                        } else {
                            strM6653 = null;
                            strM6757 = null;
                        }
                        C3431 c3431M5594 = C3431.m5594(strM4880, strM63622, "application/x-mpegURL", strM6653 == null ? "text/vtt" : strM6653, strM6757, -1, r31 == true ? 1 : 0, i, strM63552);
                        arrayList7.add(new C3926.C3927(uriM1934, c3431M5594.m5601(c3431M5594.f10093, c3710), strM6362, strM63622));
                    } else if (b == 3) {
                        String strM63624 = m6362(str6, f12305, map3);
                        if (strM63624.startsWith("CC")) {
                            i5 = Integer.parseInt(strM63624.substring(2));
                            str4 = "application/cea-608";
                        } else {
                            i5 = Integer.parseInt(strM63624.substring(7));
                            str4 = "application/cea-708";
                        }
                        int i18 = i5;
                        String str7 = str4;
                        if (arrayList == null) {
                            arrayList = new ArrayList();
                        }
                        arrayList.add(C3431.m5591(strM4880, strM63622, (String) null, str7, (String) null, -1, r31 == true ? 1 : 0, i, strM63552, i18));
                    }
                    c34312 = c34313;
                    i10++;
                    str5 = str;
                    arrayList9 = arrayList16;
                    arrayList15 = arrayList17;
                    z2 = z5;
                }
                return new C3926(str, arrayList13, arrayList15, arrayList5, arrayList6, arrayList7, arrayList12, c34312, z2 ? Collections.emptyList() : arrayList, z4, map3, arrayList14);
            }
            String strM6364 = c3933.m6364();
            if (strM6364.startsWith("#EXT")) {
                arrayList11.add(strM6364);
            }
            if (strM6364.startsWith("#EXT-X-DEFINE")) {
                map3.put(m6362(strM6364, f12302, map3), m6362(strM6364, f12309, map3));
            } else if (strM6364.equals("#EXT-X-INDEPENDENT-SEGMENTS")) {
                z3 = true;
            } else if (strM6364.startsWith("#EXT-X-MEDIA")) {
                arrayList9.add(strM6364);
            } else {
                if (strM6364.startsWith("#EXT-X-SESSION-KEY")) {
                    C3526.C3528 c3528M6357 = m6357(strM6364, m6354(strM6364, f12296, "identity", map3), map3);
                    if (c3528M6357 != null) {
                        z = z3;
                        arrayList2 = arrayList8;
                        arrayList10.add(new C3526(m6361(m6362(strM6364, f12295, map3)), true, c3528M6357));
                    } else {
                        arrayList2 = arrayList8;
                        z = z3;
                    }
                } else {
                    arrayList2 = arrayList8;
                    z = z3;
                    if (strM6364.startsWith("#EXT-X-STREAM-INF")) {
                        boolean zContains = z2 | strM6364.contains("CLOSED-CAPTIONS=NONE");
                        int iM6352 = m6352(strM6364, f12281);
                        Matcher matcher = f12276.matcher(strM6364);
                        if (matcher.find()) {
                            Integer.parseInt(matcher.group(1));
                        }
                        String strM63555 = m6355(strM6364, f12283, map3);
                        String strM63556 = m6355(strM6364, f12284, map3);
                        if (strM63556 != null) {
                            String[] strArrSplit = strM63556.split("x");
                            int i19 = Integer.parseInt(strArrSplit[0]);
                            int i20 = Integer.parseInt(strArrSplit[1]);
                            if (i19 <= 0 || i20 <= 0) {
                                i19 = -1;
                            } else {
                                i8 = i20;
                            }
                            i7 = i8;
                            i6 = i19;
                        } else {
                            i6 = -1;
                            i7 = -1;
                        }
                        String strM63557 = m6355(strM6364, f12285, map3);
                        float f2 = strM63557 != null ? Float.parseFloat(strM63557) : -1.0f;
                        String strM63558 = m6355(strM6364, f12277, map3);
                        String strM63559 = m6355(strM6364, f12278, map3);
                        String strM635510 = m6355(strM6364, f12279, map3);
                        String strM635511 = m6355(strM6364, f12280, map3);
                        if (!c3933.m6363()) {
                            throw new ParserException("#EXT-X-STREAM-INF tag must be followed by another line");
                        }
                        Uri uriM19342 = C0567.m1934(str5, m6353(c3933.m6364(), map3));
                        ArrayList arrayList18 = arrayList10;
                        arrayList4.add(new C3926.C3928(uriM19342, C3431.m5592(Integer.toString(arrayList4.size()), (String) null, "application/x-mpegURL", (String) null, strM63555, (C3710) null, iM6352, i6, i7, f2, (List<byte[]>) null, 0, 0), strM63558, strM63559, strM635510, strM635511));
                        ArrayList arrayList19 = (ArrayList) map2.get(uriM19342);
                        if (arrayList19 == null) {
                            arrayList19 = new ArrayList();
                            map2.put(uriM19342, arrayList19);
                        }
                        arrayList19.add(new C3915.C3917(iM6352, strM63558, strM63559, strM635510, strM635511));
                        z3 = z;
                        arrayList8 = arrayList2;
                        arrayList10 = arrayList18;
                        arrayList11 = arrayList11;
                        z2 = zContains;
                    }
                }
                arrayList3 = arrayList11;
                z3 = z;
                arrayList8 = arrayList2;
                arrayList10 = arrayList10;
                arrayList11 = arrayList3;
            }
            arrayList2 = arrayList8;
            arrayList3 = arrayList11;
            z = z3;
            z3 = z;
            arrayList8 = arrayList2;
            arrayList10 = arrayList10;
            arrayList11 = arrayList3;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static C3929 m6359(C3926 c3926, C3933 c3933, String str) throws ParserException {
        long j;
        long j2;
        String strM6355;
        long j3;
        TreeMap treeMap;
        String str2;
        long j4;
        C3526 c3526;
        C3526 c35262;
        C3926 c39262 = c3926;
        boolean z = c39262.f12275;
        HashMap map = new HashMap();
        ArrayList arrayList = new ArrayList();
        ArrayList arrayList2 = new ArrayList();
        TreeMap treeMap2 = new TreeMap();
        long j5 = -9223372036854775807L;
        long j6 = -9223372036854775807L;
        boolean z2 = false;
        int i = 0;
        String str3 = null;
        String str4 = null;
        long j7 = 0;
        C3526 c35263 = null;
        int i2 = 0;
        long j8 = 0;
        int i3 = 1;
        boolean z3 = false;
        long j9 = 0;
        String str5 = null;
        int i4 = 0;
        long j10 = 0;
        C3526 c35264 = null;
        C3929.C3930 c3930 = null;
        long j11 = 0;
        while (true) {
            String strM6361 = str4;
            String str6 = str5;
            C3929.C3930 c39302 = c3930;
            long j12 = -1;
            boolean z4 = false;
            long j13 = 0;
            String strM6354 = "";
            long j14 = j9;
            boolean z5 = z3;
            int iM6352 = i3;
            long j15 = j8;
            long j16 = j6;
            int i5 = i;
            String strM6362 = str3;
            long jM6352 = j16;
            int i6 = i2;
            long jM5458 = j7;
            while (c3933.m6363()) {
                String strM6364 = c3933.m6364();
                if (strM6364.startsWith("#EXT")) {
                    arrayList2.add(strM6364);
                }
                if (strM6364.startsWith("#EXT-X-PLAYLIST-TYPE")) {
                    String strM63622 = m6362(strM6364, f12288, map);
                    if ("VOD".equals(strM63622)) {
                        i5 = 1;
                    } else if ("EVENT".equals(strM63622)) {
                        i5 = 2;
                    }
                } else if (strM6364.startsWith("#EXT-X-START")) {
                    j5 = (long) (Double.parseDouble(m6362(strM6364, f12292, Collections.emptyMap())) * 1000000.0d);
                } else {
                    boolean z6 = z;
                    if (strM6364.startsWith("#EXT-X-MAP")) {
                        String strM63623 = m6362(strM6364, f12298, map);
                        boolean z7 = z2;
                        String strM63552 = m6355(strM6364, f12294, map);
                        if (strM63552 != null) {
                            String[] strArrSplit = strM63552.split("@");
                            long j17 = Long.parseLong(strArrSplit[0]);
                            if (strArrSplit.length > 1) {
                                j14 = Long.parseLong(strArrSplit[1]);
                            }
                            j = j14;
                            j2 = j17;
                        } else {
                            j = j14;
                            j2 = j12;
                        }
                        if (strM6362 != null && str6 == null) {
                            throw new ParserException("The encryption IV attribute must be present when an initialization segment is encrypted with METHOD=AES-128.");
                        }
                        c39302 = new C3929.C3930(strM63623, null, "", 0L, -1, -9223372036854775807L, null, strM6362, str6, j, j2, false);
                        j12 = -1;
                        z = z6;
                        z2 = z7;
                        j14 = 0;
                    } else {
                        boolean z8 = z2;
                        if (strM6364.startsWith("#EXT-X-TARGETDURATION")) {
                            jM6352 = 1000000 * ((long) m6352(strM6364, f12286));
                        } else if (strM6364.startsWith("#EXT-X-MEDIA-SEQUENCE")) {
                            j15 = Long.parseLong(m6362(strM6364, f12289, Collections.emptyMap()));
                            j10 = j15;
                        } else if (strM6364.startsWith("#EXT-X-VERSION")) {
                            iM6352 = m6352(strM6364, f12287);
                        } else {
                            if (strM6364.startsWith("#EXT-X-DEFINE")) {
                                String strM63553 = m6355(strM6364, f12310, map);
                                if (strM63553 != null) {
                                    String str7 = c39262.f12238.get(strM63553);
                                    if (str7 != null) {
                                        map.put(strM63553, str7);
                                    }
                                } else {
                                    map.put(m6362(strM6364, f12302, map), m6362(strM6364, f12309, map));
                                }
                            } else if (strM6364.startsWith("#EXTINF")) {
                                long j18 = (long) (Double.parseDouble(m6362(strM6364, f12290, Collections.emptyMap())) * 1000000.0d);
                                strM6354 = m6354(strM6364, f12291, "", map);
                                j13 = j18;
                            } else if (strM6364.startsWith("#EXT-X-KEY")) {
                                String strM63624 = m6362(strM6364, f12295, map);
                                String strM63542 = m6354(strM6364, f12296, "identity", map);
                                if ("NONE".equals(strM63624)) {
                                    treeMap2.clear();
                                    strM6355 = null;
                                } else {
                                    strM6355 = m6355(strM6364, f12299, map);
                                    if (!"identity".equals(strM63542)) {
                                        if (strM6361 == null) {
                                            strM6361 = m6361(strM63624);
                                        }
                                        C3526.C3528 c3528M6357 = m6357(strM6364, strM63542, map);
                                        if (c3528M6357 != null) {
                                            treeMap2.put(strM63542, c3528M6357);
                                        }
                                    } else if ("AES-128".equals(strM63624)) {
                                        strM6362 = m6362(strM6364, f12298, map);
                                        str6 = strM6355;
                                    }
                                    str6 = strM6355;
                                    z2 = z8;
                                    strM6362 = null;
                                    c39262 = c3926;
                                    z = z6;
                                }
                                str6 = strM6355;
                                z2 = z8;
                                strM6362 = null;
                                c35264 = null;
                                c39262 = c3926;
                                z = z6;
                            } else if (strM6364.startsWith("#EXT-X-BYTERANGE")) {
                                String[] strArrSplit2 = m6362(strM6364, f12293, map).split("@");
                                j12 = Long.parseLong(strArrSplit2[0]);
                                if (strArrSplit2.length > 1) {
                                    j14 = Long.parseLong(strArrSplit2[1]);
                                }
                            } else if (strM6364.startsWith("#EXT-X-DISCONTINUITY-SEQUENCE")) {
                                i6 = Integer.parseInt(strM6364.substring(strM6364.indexOf(58) + 1));
                                z2 = true;
                                c39262 = c3926;
                                z = z6;
                            } else if (strM6364.equals("#EXT-X-DISCONTINUITY")) {
                                i4++;
                            } else if (strM6364.startsWith("#EXT-X-PROGRAM-DATE-TIME")) {
                                if (jM5458 == 0) {
                                    jM5458 = C3414.m5458(C4150.m6805(strM6364.substring(strM6364.indexOf(58) + 1))) - j11;
                                }
                            } else if (strM6364.equals("#EXT-X-GAP")) {
                                c39262 = c3926;
                                z = z6;
                                z2 = z8;
                                z4 = true;
                            } else if (strM6364.equals("#EXT-X-INDEPENDENT-SEGMENTS")) {
                                z = true;
                                c39262 = c3926;
                                z2 = z8;
                            } else if (strM6364.equals("#EXT-X-ENDLIST")) {
                                c39262 = c3926;
                                z = z6;
                                z2 = z8;
                                z5 = true;
                            } else if (!strM6364.startsWith("#")) {
                                String hexString = strM6362 == null ? null : str6 != null ? str6 : Long.toHexString(j10);
                                long j19 = j10 + 1;
                                if (j12 == -1) {
                                    j14 = 0;
                                }
                                if (c35264 != null || treeMap2.isEmpty()) {
                                    j3 = j19;
                                    treeMap = treeMap2;
                                    str2 = str6;
                                    j4 = j5;
                                    c3526 = c35264;
                                } else {
                                    j3 = j19;
                                    int i7 = 0;
                                    C3526.C3528[] c3528Arr = (C3526.C3528[]) treeMap2.values().toArray(new C3526.C3528[0]);
                                    C3526 c35265 = new C3526(strM6361, true, c3528Arr);
                                    if (c35263 == null) {
                                        C3526.C3528[] c3528Arr2 = new C3526.C3528[c3528Arr.length];
                                        c35262 = c35265;
                                        while (i7 < c3528Arr.length) {
                                            C3526.C3528 c3528 = c3528Arr[i7];
                                            c3528Arr2[i7] = new C3526.C3528(c3528.f10499, c3528.f10500, c3528.f10501, null);
                                            i7++;
                                            c3528Arr = c3528Arr;
                                            treeMap2 = treeMap2;
                                            str6 = str6;
                                            j5 = j5;
                                        }
                                        treeMap = treeMap2;
                                        str2 = str6;
                                        j4 = j5;
                                        c35263 = new C3526(strM6361, true, c3528Arr2);
                                    } else {
                                        c35262 = c35265;
                                        treeMap = treeMap2;
                                        str2 = str6;
                                        j4 = j5;
                                    }
                                    c3526 = c35262;
                                }
                                arrayList.add(new C3929.C3930(m6353(strM6364, map), c39302, strM6354, j13, i4, j11, c3526, strM6362, hexString, j14, j12, z4));
                                j11 += j13;
                                if (j12 != -1) {
                                    j14 += j12;
                                }
                                c35264 = c3526;
                                str4 = strM6361;
                                c3930 = c39302;
                                j10 = j3;
                                treeMap2 = treeMap;
                                j5 = j4;
                                z = z6;
                                z2 = z8;
                                c39262 = c3926;
                                long j20 = jM6352;
                                i = i5;
                                str3 = strM6362;
                                j6 = j20;
                                long j21 = jM5458;
                                i2 = i6;
                                j7 = j21;
                                j8 = j15;
                                i3 = iM6352;
                                z3 = z5;
                                j9 = j14;
                                str5 = str2;
                            }
                            c39262 = c3926;
                            treeMap2 = treeMap2;
                            str6 = str6;
                            j5 = j5;
                            z = z6;
                            z2 = z8;
                        }
                        z2 = z8;
                        c39262 = c3926;
                        z = z6;
                    }
                }
            }
            return new C3929(i5, str, arrayList2, j5, jM5458, z2, i6, j15, iM6352, jM6352, z, z5, jM5458 != 0, c35263, arrayList);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static boolean m6360(String str, Pattern pattern, boolean z) {
        Matcher matcher = pattern.matcher(str);
        return matcher.find() ? matcher.group(1).equals("YES") : z;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static String m6361(String str) {
        return ("SAMPLE-AES-CENC".equals(str) || "SAMPLE-AES-CTR".equals(str)) ? "cenc" : "cbcs";
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public static String m6362(String str, Pattern pattern, Map<String, String> map) throws ParserException {
        String strM6355 = m6355(str, pattern, map);
        if (strM6355 != null) {
            return strM6355;
        }
        StringBuilder sbM4889 = C2803.m4889("Couldn't match ");
        sbM4889.append(pattern.pattern());
        sbM4889.append(" in ");
        sbM4889.append(str);
        throw new ParserException(sbM4889.toString());
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0036 A[Catch: all -> 0x00e8, TryCatch #0 {all -> 0x00e8, blocks: (B:3:0x000f, B:5:0x0018, B:7:0x0020, B:10:0x0029, B:19:0x0050, B:21:0x0056, B:24:0x0061, B:26:0x0069, B:27:0x007a, B:29:0x0082, B:31:0x008a, B:33:0x0092, B:35:0x009a, B:37:0x00a2, B:39:0x00aa, B:41:0x00b2, B:44:0x00bb, B:45:0x00bf, B:50:0x00e0, B:51:0x00e7, B:11:0x002d, B:13:0x0036, B:16:0x003f, B:17:0x0046), top: B:55:0x000f }] */
    /* JADX WARN: Removed duplicated region for block: B:71:0x0046 A[SYNTHETIC] */
    @Override // p138.p176.p177.p190.p238.C4112.InterfaceC4113
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public AbstractC3931 mo1229(Uri uri, InputStream inputStream) throws ParserException {
        int iM6351;
        int i;
        String strTrim;
        AbstractC3931 abstractC3931M6358;
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        ArrayDeque arrayDeque = new ArrayDeque();
        try {
            int i2 = bufferedReader.read();
            boolean zM6806 = false;
            if (i2 != 239) {
                iM6351 = m6351(bufferedReader, true, i2);
                i = 0;
                while (true) {
                    if (i < 7) {
                        zM6806 = C4150.m6806(m6351(bufferedReader, false, iM6351));
                        break;
                    }
                    if (iM6351 != "#EXTM3U".charAt(i)) {
                        break;
                    }
                    iM6351 = bufferedReader.read();
                    i++;
                }
            } else if (bufferedReader.read() == 187 && bufferedReader.read() == 191) {
                i2 = bufferedReader.read();
                iM6351 = m6351(bufferedReader, true, i2);
                i = 0;
                while (true) {
                    if (i < 7) {
                    }
                    iM6351 = bufferedReader.read();
                    i++;
                }
            }
            if (!zM6806) {
                throw new UnrecognizedInputFormatException("Input does not start with the #EXTM3U header.", uri);
            }
            while (true) {
                String line = bufferedReader.readLine();
                if (line == null) {
                    C4150.m6764((Closeable) bufferedReader);
                    throw new ParserException("Failed to parse the playlist, could not identify any tags.");
                }
                strTrim = line.trim();
                if (!strTrim.isEmpty()) {
                    if (!strTrim.startsWith("#EXT-X-STREAM-INF")) {
                        if (strTrim.startsWith("#EXT-X-TARGETDURATION") || strTrim.startsWith("#EXT-X-MEDIA-SEQUENCE") || strTrim.startsWith("#EXTINF") || strTrim.startsWith("#EXT-X-KEY") || strTrim.startsWith("#EXT-X-BYTERANGE") || strTrim.equals("#EXT-X-DISCONTINUITY") || strTrim.equals("#EXT-X-DISCONTINUITY-SEQUENCE") || strTrim.equals("#EXT-X-ENDLIST")) {
                            break;
                        }
                        arrayDeque.add(strTrim);
                    } else {
                        arrayDeque.add(strTrim);
                        abstractC3931M6358 = m6358(new C3933(arrayDeque, bufferedReader), uri.toString());
                        break;
                    }
                }
            }
            arrayDeque.add(strTrim);
            abstractC3931M6358 = m6359(this.f12312, new C3933(arrayDeque, bufferedReader), uri.toString());
            return abstractC3931M6358;
        } finally {
            C4150.m6764((Closeable) bufferedReader);
        }
    }
}
