package com.google.android.gms.internal.ads;

import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes2.dex */
public final class c9 implements j8 {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final Pattern f9812d = Pattern.compile("\\s*((?:(\\d+):)?(\\d+):(\\d+)(?:,(\\d{3}))?)\\s*-->\\s*((?:(\\d+):)?(\\d+):(\\d+)(?:,(\\d{3}))?)\\s*");

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final Pattern f9813e = Pattern.compile("\\{\\\\.*?\\}");

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final StringBuilder f9814a = new StringBuilder();

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final p01 f9816c = new p01();

    public static long a(Matcher matcher, int i10) {
        String strGroup = matcher.group(i10 + 1);
        long j10 = strGroup != null ? Long.parseLong(strGroup) * 3600000 : 0L;
        String strGroup2 = matcher.group(i10 + 2);
        strGroup2.getClass();
        long j11 = (Long.parseLong(strGroup2) * 60000) + j10;
        String strGroup3 = matcher.group(i10 + 3);
        strGroup3.getClass();
        long j12 = (Long.parseLong(strGroup3) * 1000) + j11;
        String strGroup4 = matcher.group(i10 + 4);
        if (strGroup4 != null) {
            j12 += Long.parseLong(strGroup4);
        }
        return j12 * 1000;
    }

    @Override // com.google.android.gms.internal.ads.j8
    public final void b(byte[] bArr, int i10, int i11, g7.h hVar) {
        String str;
        float f10;
        ad0 ad0VarC;
        p01 p01Var = this.f9816c;
        p01Var.w(i10 + i11, bArr);
        p01Var.C(i10);
        Charset charsetZzR = p01Var.zzR();
        if (charsetZzR == null) {
            charsetZzR = StandardCharsets.UTF_8;
        }
        while (true) {
            String strZzN = p01Var.zzN(charsetZzR);
            if (strZzN == null) {
                return;
            }
            if (!strZzN.isEmpty()) {
                try {
                    Integer.parseInt(strZzN);
                    String strZzN2 = p01Var.zzN(charsetZzR);
                    if (strZzN2 == null) {
                        vt0.c("Unexpected end");
                        return;
                    }
                    Matcher matcher = f9812d.matcher(strZzN2);
                    if (matcher.matches()) {
                        long jA = a(matcher, 1);
                        long jA2 = a(matcher, 6);
                        StringBuilder sb = this.f9814a;
                        int i12 = 0;
                        sb.setLength(0);
                        ArrayList arrayList = this.f9815b;
                        arrayList.clear();
                        String strZzN3 = p01Var.zzN(charsetZzR);
                        while (!TextUtils.isEmpty(strZzN3)) {
                            if (sb.length() > 0) {
                                sb.append("<br>");
                            }
                            String strTrim = strZzN3.trim();
                            StringBuilder sb2 = new StringBuilder(strTrim);
                            Matcher matcher2 = f9813e.matcher(strTrim);
                            int i13 = i12;
                            while (matcher2.find()) {
                                String strGroup = matcher2.group();
                                arrayList.add(strGroup);
                                int iStart = matcher2.start() - i13;
                                int length = strGroup.length();
                                sb2.replace(iStart, iStart + length, "");
                                i13 += length;
                            }
                            sb.append(sb2.toString());
                            strZzN3 = p01Var.zzN(charsetZzR);
                            i12 = 0;
                        }
                        Spanned spannedFromHtml = Html.fromHtml(sb.toString());
                        int i14 = 0;
                        while (true) {
                            if (i14 < arrayList.size()) {
                                str = (String) arrayList.get(i14);
                                if (!str.matches("\\{\\\\an[1-9]\\}")) {
                                    i14++;
                                }
                            } else {
                                str = null;
                            }
                        }
                        gc0 gc0Var = new gc0();
                        gc0Var.a(spannedFromHtml);
                        if (str == null) {
                            ad0VarC = gc0Var.c();
                        } else {
                            switch (str) {
                                case "{\an1}":
                                case "{\an4}":
                                case "{\an7}":
                                    gc0Var.f11709e = 0;
                                    break;
                                case "{\an3}":
                                case "{\an6}":
                                case "{\an9}":
                                    gc0Var.f11709e = 2;
                                    break;
                                default:
                                    gc0Var.f11709e = 1;
                                    break;
                            }
                            switch (str) {
                                case "{\an1}":
                                case "{\an2}":
                                case "{\an3}":
                                    gc0Var.f11707c = 2;
                                    break;
                                case "{\an7}":
                                case "{\an8}":
                                case "{\an9}":
                                    gc0Var.f11707c = 0;
                                    break;
                                default:
                                    gc0Var.f11707c = 1;
                                    break;
                            }
                            int i15 = gc0Var.f11709e;
                            float f11 = 0.08f;
                            if (i15 == 0) {
                                f10 = 0.08f;
                            } else if (i15 == 1) {
                                f10 = 0.5f;
                            } else {
                                if (i15 != 2) {
                                    throw new IllegalArgumentException();
                                }
                                f10 = 0.92f;
                            }
                            gc0Var.f11708d = f10;
                            int i16 = gc0Var.f11707c;
                            if (i16 != 0) {
                                if (i16 == 1) {
                                    f11 = 0.5f;
                                } else {
                                    if (i16 != 2) {
                                        throw new IllegalArgumentException();
                                    }
                                    f11 = 0.92f;
                                }
                            }
                            gc0Var.f11705a = f11;
                            gc0Var.f11706b = 0;
                            ad0VarC = gc0Var.c();
                        }
                        hVar.mo2zza(new f8(zzguf.o(ad0VarC), jA, jA2 - jA));
                    } else {
                        vt0.c("Skipping invalid timing: ".concat(strZzN2));
                    }
                } catch (NumberFormatException unused) {
                    vt0.c("Skipping invalid index: ".concat(strZzN));
                }
            }
        }
    }
}
