package g1;

import c1.C0576a;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import n4.u0;
import s7.d;
import u0.D;

/* JADX INFO: renamed from: g1.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0970a extends u0 {

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public static final Pattern f12874x = Pattern.compile("(.+?)='(.*?)';", 32);

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public final CharsetDecoder f12875v = StandardCharsets.UTF_8.newDecoder();

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public final CharsetDecoder f12876w = StandardCharsets.ISO_8859_1.newDecoder();

    @Override // n4.u0
    public final D q(C0576a c0576a, ByteBuffer byteBuffer) {
        String string;
        CharsetDecoder charsetDecoder = this.f12876w;
        CharsetDecoder charsetDecoder2 = this.f12875v;
        String str = null;
        try {
            string = charsetDecoder2.decode(byteBuffer).toString();
        } catch (CharacterCodingException unused) {
            try {
                String string2 = charsetDecoder.decode(byteBuffer).toString();
                charsetDecoder.reset();
                byteBuffer.rewind();
                string = string2;
            } catch (CharacterCodingException unused2) {
                charsetDecoder.reset();
                byteBuffer.rewind();
                string = null;
            } catch (Throwable th) {
                charsetDecoder.reset();
                byteBuffer.rewind();
                throw th;
            }
        } finally {
            charsetDecoder2.reset();
            byteBuffer.rewind();
        }
        byte[] bArr = new byte[byteBuffer.limit()];
        byteBuffer.get(bArr);
        if (string == null) {
            return new D(new C0972c(null, null, bArr));
        }
        Matcher matcher = f12874x.matcher(string);
        String str2 = null;
        for (int iEnd = 0; matcher.find(iEnd); iEnd = matcher.end()) {
            String strGroup = matcher.group(1);
            String strGroup2 = matcher.group(2);
            if (strGroup != null) {
                String strF = d.F(strGroup);
                strF.getClass();
                if (strF.equals("streamurl")) {
                    str2 = strGroup2;
                } else if (strF.equals("streamtitle")) {
                    str = strGroup2;
                }
            }
        }
        return new D(new C0972c(str, str2, bArr));
    }
}
