package tv.danmaku.ijk.media.player.ui.subtitleconverter.subtitleFile;

import androidx.media3.common.PlaybackException;
import com.google.android.gms.measurement.internal.u1;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;
import u.a;

/* JADX INFO: loaded from: classes3.dex */
public class FormatSCC implements TimedTextFileFormat {
    private String codeChar(char[] cArr) {
        String strJ = "";
        int i10 = 0;
        while (i10 < cArr.length) {
            char c6 = cArr[i10];
            switch (c6) {
                case ' ':
                    strJ = u1.j(strJ, "20");
                    break;
                case '!':
                    strJ = u1.j(strJ, "a1");
                    break;
                case '\"':
                    strJ = u1.j(strJ, "a2");
                    break;
                case '#':
                    strJ = u1.j(strJ, "23");
                    break;
                case '$':
                    strJ = u1.j(strJ, "a4");
                    break;
                case '%':
                    strJ = u1.j(strJ, "25");
                    break;
                case '&':
                    strJ = u1.j(strJ, "26");
                    break;
                case '\'':
                    strJ = u1.j(strJ, "a7");
                    break;
                case '(':
                    strJ = u1.j(strJ, "a8");
                    break;
                case ')':
                    strJ = u1.j(strJ, "29");
                    break;
                default:
                    switch (c6) {
                        case '+':
                            strJ = u1.j(strJ, "ab");
                            break;
                        case ',':
                            strJ = u1.j(strJ, "2c");
                            break;
                        case '-':
                            strJ = u1.j(strJ, "ad");
                            break;
                        case '.':
                            strJ = u1.j(strJ, "ae");
                            break;
                        case '/':
                            strJ = u1.j(strJ, "2f");
                            break;
                        case '0':
                            strJ = u1.j(strJ, "b0");
                            break;
                        case '1':
                            strJ = u1.j(strJ, "31");
                            break;
                        case '2':
                            strJ = u1.j(strJ, "32");
                            break;
                        case '3':
                            strJ = u1.j(strJ, "b3");
                            break;
                        case '4':
                            strJ = u1.j(strJ, "34");
                            break;
                        case '5':
                            strJ = u1.j(strJ, "b5");
                            break;
                        case '6':
                            strJ = u1.j(strJ, "b6");
                            break;
                        case '7':
                            strJ = u1.j(strJ, "37");
                            break;
                        case '8':
                            strJ = u1.j(strJ, "38");
                            break;
                        case '9':
                            strJ = u1.j(strJ, "b9");
                            break;
                        case ':':
                            strJ = u1.j(strJ, "ba");
                            break;
                        case ';':
                            strJ = u1.j(strJ, "3b");
                            break;
                        case '<':
                            strJ = u1.j(strJ, "bc");
                            break;
                        case '=':
                            strJ = u1.j(strJ, "3d");
                            break;
                        case '>':
                            strJ = u1.j(strJ, "3e");
                            break;
                        case '?':
                            strJ = u1.j(strJ, "bf");
                            break;
                        case '@':
                            strJ = u1.j(strJ, "40");
                            break;
                        case 'A':
                            strJ = u1.j(strJ, "c1");
                            break;
                        case 'B':
                            strJ = u1.j(strJ, "c2");
                            break;
                        case 'C':
                            strJ = u1.j(strJ, "43");
                            break;
                        case 'D':
                            strJ = u1.j(strJ, "c4");
                            break;
                        case 'E':
                            strJ = u1.j(strJ, "45");
                            break;
                        case 'F':
                            strJ = u1.j(strJ, "46");
                            break;
                        case 'G':
                            strJ = u1.j(strJ, "c7");
                            break;
                        case 'H':
                            strJ = u1.j(strJ, "c8");
                            break;
                        case 'I':
                            strJ = u1.j(strJ, "49");
                            break;
                        case 'J':
                            strJ = u1.j(strJ, "4a");
                            break;
                        case 'K':
                            strJ = u1.j(strJ, "cb");
                            break;
                        case 'L':
                            strJ = u1.j(strJ, "4c");
                            break;
                        case 'M':
                            strJ = u1.j(strJ, "cd");
                            break;
                        case 'N':
                            strJ = u1.j(strJ, "ce");
                            break;
                        case 'O':
                            strJ = u1.j(strJ, "4f");
                            break;
                        case 'P':
                            strJ = u1.j(strJ, "d0");
                            break;
                        case 'Q':
                            strJ = u1.j(strJ, "51");
                            break;
                        case 'R':
                            strJ = u1.j(strJ, "52");
                            break;
                        case 'S':
                            strJ = u1.j(strJ, "d3");
                            break;
                        case 'T':
                            strJ = u1.j(strJ, "54");
                            break;
                        case 'U':
                            strJ = u1.j(strJ, "d5");
                            break;
                        case 'V':
                            strJ = u1.j(strJ, "d6");
                            break;
                        case 'W':
                            strJ = u1.j(strJ, "57");
                            break;
                        case 'X':
                            strJ = u1.j(strJ, "58");
                            break;
                        case 'Y':
                            strJ = u1.j(strJ, "d9");
                            break;
                        case 'Z':
                            strJ = u1.j(strJ, "da");
                            break;
                        case '[':
                            strJ = u1.j(strJ, "5b");
                            break;
                        default:
                            switch (c6) {
                                case ']':
                                    strJ = u1.j(strJ, "5d");
                                    break;
                                case '|':
                                    strJ = u1.j(strJ, "7f");
                                    break;
                                case 209:
                                    strJ = u1.j(strJ, IjkMediaPlayer.OnNativeInvokeListener.ARG_FD);
                                    break;
                                case 225:
                                    strJ = u1.j(strJ, "2a");
                                    break;
                                case 231:
                                    strJ = u1.j(strJ, "fb");
                                    break;
                                case 233:
                                    strJ = u1.j(strJ, "dc");
                                    break;
                                case 237:
                                    strJ = u1.j(strJ, "5e");
                                    break;
                                case 241:
                                    strJ = u1.j(strJ, "fe");
                                    break;
                                case 243:
                                    strJ = u1.j(strJ, "df");
                                    break;
                                case 247:
                                    strJ = u1.j(strJ, "7c");
                                    break;
                                case 250:
                                    strJ = u1.j(strJ, "e0");
                                    break;
                                default:
                                    switch (c6) {
                                        case 'a':
                                            strJ = u1.j(strJ, "61");
                                            break;
                                        case 'b':
                                            strJ = u1.j(strJ, "62");
                                            break;
                                        case 'c':
                                            strJ = u1.j(strJ, "e3");
                                            break;
                                        case 'd':
                                            strJ = u1.j(strJ, "64");
                                            break;
                                        case 'e':
                                            strJ = u1.j(strJ, "e5");
                                            break;
                                        case 'f':
                                            strJ = u1.j(strJ, "e6");
                                            break;
                                        case 'g':
                                            strJ = u1.j(strJ, "67");
                                            break;
                                        case 'h':
                                            strJ = u1.j(strJ, "68");
                                            break;
                                        case 'i':
                                            strJ = u1.j(strJ, "e9");
                                            break;
                                        case 'j':
                                            strJ = u1.j(strJ, "ea");
                                            break;
                                        case 'k':
                                            strJ = u1.j(strJ, "6b");
                                            break;
                                        case 'l':
                                            strJ = u1.j(strJ, "ec");
                                            break;
                                        case 'm':
                                            strJ = u1.j(strJ, "6d");
                                            break;
                                        case 'n':
                                            strJ = u1.j(strJ, "6e");
                                            break;
                                        case 'o':
                                            strJ = u1.j(strJ, "ef");
                                            break;
                                        case 'p':
                                            strJ = u1.j(strJ, "70");
                                            break;
                                        case 'q':
                                            strJ = u1.j(strJ, "f1");
                                            break;
                                        case 'r':
                                            strJ = u1.j(strJ, "f2");
                                            break;
                                        case 's':
                                            strJ = u1.j(strJ, "73");
                                            break;
                                        case 't':
                                            strJ = u1.j(strJ, "f4");
                                            break;
                                        case 'u':
                                            strJ = u1.j(strJ, "75");
                                            break;
                                        case 'v':
                                            strJ = u1.j(strJ, "76");
                                            break;
                                        case 'w':
                                            strJ = u1.j(strJ, "f7");
                                            break;
                                        case 'x':
                                            strJ = u1.j(strJ, "f8");
                                            break;
                                        case 'y':
                                            strJ = u1.j(strJ, "79");
                                            break;
                                        case 'z':
                                            strJ = u1.j(strJ, "7a");
                                            break;
                                        default:
                                            strJ = u1.j(strJ, "7f");
                                            break;
                                    }
                                    break;
                            }
                            break;
                    }
                    break;
            }
            if (i10 % 2 == 1) {
                strJ = u1.j(strJ, " ");
            }
            i10++;
        }
        return i10 % 2 == 1 ? u1.j(strJ, "80 ") : strJ;
    }

    private String codeText(Caption caption) {
        String[] strArrSplit = caption.content.split("<br />");
        if (strArrSplit[0].length() > 32) {
            strArrSplit[0] = strArrSplit[0].substring(0, 32);
        }
        int length = ((32 - strArrSplit[0].length()) / 2) % 4;
        String str = "1340 1340 " + codeChar(strArrSplit[0].toCharArray());
        if (strArrSplit.length <= 1) {
            return str;
        }
        if (strArrSplit[1].length() > 32) {
            strArrSplit[1] = strArrSplit[1].substring(0, 32);
        }
        int length2 = (32 - strArrSplit[1].length()) / 2;
        int i10 = length2 % 4;
        String str2 = u1.j(str, "13e0 13e0 ") + codeChar(strArrSplit[1].toCharArray());
        if (strArrSplit.length <= 2) {
            return str2;
        }
        if (strArrSplit[2].length() > 32) {
            strArrSplit[2] = strArrSplit[2].substring(0, 32);
        }
        int length3 = (32 - strArrSplit[2].length()) / 2;
        int i11 = length3 % 4;
        String str3 = u1.j(str2, "9440 9440 ") + codeChar(strArrSplit[2].toCharArray());
        if (strArrSplit.length <= 3) {
            return str3;
        }
        if (strArrSplit[3].length() > 32) {
            strArrSplit[3] = strArrSplit[3].substring(0, 32);
        }
        int length4 = (32 - strArrSplit[3].length()) / 2;
        int i12 = length4 % 4;
        return u1.j(str3, "94e0 94e0 ") + codeChar(strArrSplit[3].toCharArray());
    }

    private void createSCCStyles(TimedTextObject timedTextObject) {
        Style style = new Style("white");
        Style styleS = u1.s(timedTextObject.styling, style.iD, style, "whiteU", style);
        styleS.underline = true;
        Style styleS2 = u1.s(timedTextObject.styling, styleS.iD, styleS, "whiteUI", styleS);
        styleS2.italic = true;
        Style styleS3 = u1.s(timedTextObject.styling, styleS2.iD, styleS2, "whiteI", styleS2);
        styleS3.underline = false;
        timedTextObject.styling.put(styleS3.iD, styleS3);
        Style style2 = new Style("green");
        style2.color = Style.getRGBValue("name", "green");
        Style styleS4 = u1.s(timedTextObject.styling, style2.iD, style2, "greenU", style2);
        styleS4.underline = true;
        Style styleS5 = u1.s(timedTextObject.styling, styleS4.iD, styleS4, "greenUI", styleS4);
        styleS5.italic = true;
        Style styleS6 = u1.s(timedTextObject.styling, styleS5.iD, styleS5, "greenI", styleS5);
        styleS6.underline = false;
        timedTextObject.styling.put(styleS6.iD, styleS6);
        Style style3 = new Style("blue");
        style3.color = Style.getRGBValue("name", "blue");
        Style styleS7 = u1.s(timedTextObject.styling, style3.iD, style3, "blueU", style3);
        styleS7.underline = true;
        Style styleS8 = u1.s(timedTextObject.styling, styleS7.iD, styleS7, "blueUI", styleS7);
        styleS8.italic = true;
        Style styleS9 = u1.s(timedTextObject.styling, styleS8.iD, styleS8, "blueI", styleS8);
        styleS9.underline = false;
        timedTextObject.styling.put(styleS9.iD, styleS9);
        Style style4 = new Style("cyan");
        style4.color = Style.getRGBValue("name", "cyan");
        Style styleS10 = u1.s(timedTextObject.styling, style4.iD, style4, "cyanU", style4);
        styleS10.underline = true;
        Style styleS11 = u1.s(timedTextObject.styling, styleS10.iD, styleS10, "cyanUI", styleS10);
        styleS11.italic = true;
        Style styleS12 = u1.s(timedTextObject.styling, styleS11.iD, styleS11, "cyanI", styleS11);
        styleS12.underline = false;
        timedTextObject.styling.put(styleS12.iD, styleS12);
        Style style5 = new Style("red");
        style5.color = Style.getRGBValue("name", "red");
        Style styleS13 = u1.s(timedTextObject.styling, style5.iD, style5, "redU", style5);
        styleS13.underline = true;
        Style styleS14 = u1.s(timedTextObject.styling, styleS13.iD, styleS13, "redUI", styleS13);
        styleS14.italic = true;
        Style styleS15 = u1.s(timedTextObject.styling, styleS14.iD, styleS14, "redI", styleS14);
        styleS15.underline = false;
        timedTextObject.styling.put(styleS15.iD, styleS15);
        Style style6 = new Style("yellow");
        style6.color = Style.getRGBValue("name", "yellow");
        Style styleS16 = u1.s(timedTextObject.styling, style6.iD, style6, "yellowU", style6);
        styleS16.underline = true;
        Style styleS17 = u1.s(timedTextObject.styling, styleS16.iD, styleS16, "yellowUI", styleS16);
        styleS17.italic = true;
        Style styleS18 = u1.s(timedTextObject.styling, styleS17.iD, styleS17, "yellowI", styleS17);
        styleS18.underline = false;
        timedTextObject.styling.put(styleS18.iD, styleS18);
        Style style7 = new Style("magenta");
        style7.color = Style.getRGBValue("name", "magenta");
        Style styleS19 = u1.s(timedTextObject.styling, style7.iD, style7, "magentaU", style7);
        styleS19.underline = true;
        Style styleS20 = u1.s(timedTextObject.styling, styleS19.iD, styleS19, "magentaUI", styleS19);
        styleS20.italic = true;
        Style styleS21 = u1.s(timedTextObject.styling, styleS20.iD, styleS20, "magentaI", styleS20);
        styleS21.underline = false;
        timedTextObject.styling.put(styleS21.iD, styleS21);
    }

    private String decodeChar(byte b10) {
        if (b10 == 0) {
            return "";
        }
        if (b10 == 42) {
            return "�";
        }
        if (b10 == 92) {
            return "é";
        }
        switch (b10) {
            case 94:
                return "í";
            case 95:
                return "ó";
            case 96:
                return "ú";
            default:
                switch (b10) {
                    case 123:
                        return "ç";
                    case 124:
                        return "�";
                    case 125:
                        return "Ñ";
                    case 126:
                        return "ñ";
                    case 127:
                        return "|";
                    default:
                        return Character.toString((char) b10);
                }
        }
    }

    private String decodeSpecialChar(int i10) {
        switch (i10) {
        }
        return "�";
    }

    private void decodeXtChar(String str, int i10) {
    }

    @Override // tv.danmaku.ijk.media.player.ui.subtitleconverter.subtitleFile.TimedTextFileFormat
    public TimedTextObject parseFile(String str, InputStream inputStream) throws FatalParsingException, IOException {
        return parseFile(str, inputStream, Charset.defaultCharset());
    }

    /* JADX WARN: Failed to find 'out' block for switch in B:111:0x02a0. Please report as an issue. */
    /* JADX WARN: Failed to find 'out' block for switch in B:130:0x0307. Please report as an issue. */
    /* JADX WARN: Removed duplicated region for block: B:112:0x02a3 A[PHI: r0 r13
      0x02a3: PHI (r0v36 boolean) = (r0v27 boolean), (r0v40 boolean) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]
      0x02a3: PHI (r13v13 java.lang.String) = (r13v3 java.lang.String), (r13v14 java.lang.String) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:115:0x02b7 A[PHI: r0 r13
      0x02b7: PHI (r0v34 boolean) = (r0v27 boolean), (r0v40 boolean) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]
      0x02b7: PHI (r13v11 java.lang.String) = (r13v3 java.lang.String), (r13v14 java.lang.String) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:116:0x02c1 A[PHI: r0 r13
      0x02c1: PHI (r0v33 boolean) = (r0v27 boolean), (r0v40 boolean) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]
      0x02c1: PHI (r13v10 java.lang.String) = (r13v3 java.lang.String), (r13v14 java.lang.String) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:117:0x02cb A[PHI: r0 r13
      0x02cb: PHI (r0v32 boolean) = (r0v27 boolean), (r0v40 boolean) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]
      0x02cb: PHI (r13v9 java.lang.String) = (r13v3 java.lang.String), (r13v14 java.lang.String) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:118:0x02d5 A[PHI: r0 r13
      0x02d5: PHI (r0v31 boolean) = (r0v27 boolean), (r0v40 boolean) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]
      0x02d5: PHI (r13v8 java.lang.String) = (r13v3 java.lang.String), (r13v14 java.lang.String) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:119:0x02df A[PHI: r0 r13
      0x02df: PHI (r0v30 boolean) = (r0v27 boolean), (r0v40 boolean) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]
      0x02df: PHI (r13v7 java.lang.String) = (r13v3 java.lang.String), (r13v14 java.lang.String) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:121:0x02e6 A[PHI: r0 r13
      0x02e6: PHI (r0v29 boolean) = (r0v27 boolean), (r0v40 boolean) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]
      0x02e6: PHI (r13v5 java.lang.String) = (r13v3 java.lang.String), (r13v14 java.lang.String) binds: [B:130:0x0307, B:111:0x02a0] A[DONT_GENERATE, DONT_INLINE]] */
    @Override // tv.danmaku.ijk.media.player.ui.subtitleconverter.subtitleFile.TimedTextFileFormat
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public TimedTextObject parseFile(String str, InputStream inputStream, Charset charset) throws FatalParsingException, IOException {
        int i10;
        BufferedReader bufferedReader;
        int i11;
        boolean z10;
        boolean z11;
        String[] strArr;
        boolean z12;
        int i12;
        Caption caption;
        TimedTextObject timedTextObject = new TimedTextObject();
        BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(inputStream, charset));
        timedTextObject.fileName = str;
        timedTextObject.title = str;
        try {
            try {
            } catch (NullPointerException unused) {
                i10 = 1;
            }
            if (!bufferedReader2.readLine().trim().equalsIgnoreCase("Scenarist_SCC V1.0")) {
                throw new FatalParsingException("The fist line should define the file type: \"Scenarist_SCC V1.0\"");
            }
            createSCCStyles(timedTextObject);
            timedTextObject.warnings += "Only data from CC channel 1 will be extracted.\n\n";
            String line = bufferedReader2.readLine();
            Caption caption2 = null;
            String str2 = null;
            String str3 = "";
            i10 = 1;
            boolean z13 = false;
            boolean z14 = true;
            boolean z15 = false;
            boolean z16 = false;
            while (line != null) {
                try {
                    String strTrim = line.trim();
                    i10++;
                    try {
                        if (strTrim.isEmpty()) {
                            bufferedReader = bufferedReader2;
                            i11 = i10;
                        } else {
                            String[] strArrSplit = strTrim.split("\t");
                            Time time = new Time("h:m:s:f/fps", strArrSplit[0] + "/29.97");
                            String[] strArrSplit2 = strArrSplit[1].split(" ");
                            str2 = str2;
                            int i13 = 0;
                            while (i13 < strArrSplit2.length) {
                                int i14 = i10;
                                try {
                                    int i15 = Integer.parseInt(strArrSplit2[i13], 16);
                                    int i16 = i15 & 32639;
                                    BufferedReader bufferedReader3 = bufferedReader2;
                                    if ((i15 & 24576) == 0) {
                                        z10 = z14;
                                        if (i16 == 0) {
                                            z11 = z13;
                                            time.mseconds = (int) (((double) time.mseconds) + 33.366700033366705d);
                                        } else {
                                            z11 = z13;
                                            int i17 = i13 + 1;
                                            if (i17 < strArrSplit2.length && strArrSplit2[i13].equals(strArrSplit2[i17])) {
                                                i13 = i17;
                                            }
                                            if ((i15 & 2048) != 0) {
                                                strArr = strArrSplit2;
                                                z13 = false;
                                                z14 = z10;
                                            } else if ((i15 & 5744) == 5152) {
                                                if ((i15 & 256) == 0) {
                                                    int i18 = i15 & 15;
                                                    if (i18 != 0) {
                                                        if (i18 != 9) {
                                                            if (i18 == 12) {
                                                                if (caption2 != null) {
                                                                    caption2.end = time;
                                                                    Time time2 = caption2.start;
                                                                    if (time2 != null) {
                                                                        for (int i19 = time2.mseconds; timedTextObject.captions.containsKey(Integer.valueOf(i19)); i19++) {
                                                                        }
                                                                        timedTextObject.captions.put(Integer.valueOf(caption2.start.mseconds), caption2);
                                                                        caption = new Caption();
                                                                        strArr = strArrSplit2;
                                                                        caption2 = caption;
                                                                    }
                                                                }
                                                                strArr = strArrSplit2;
                                                            } else if (i18 == 5 || i18 == 6 || i18 == 7) {
                                                                if (caption2 != null) {
                                                                    caption2.end = time;
                                                                    String str4 = "" + str2;
                                                                    if (z15) {
                                                                        str4 = str4 + "U";
                                                                    }
                                                                    if (z16) {
                                                                        str4 = str4 + "I";
                                                                    }
                                                                    caption2.style = timedTextObject.styling.get(str4);
                                                                    timedTextObject.captions.put(Integer.valueOf(caption2.start.mseconds), caption2);
                                                                }
                                                                Caption caption3 = new Caption();
                                                                caption3.start = time;
                                                                strArr = strArrSplit2;
                                                                caption2 = caption3;
                                                                str3 = "";
                                                            } else if (i18 == 14) {
                                                                strArr = strArrSplit2;
                                                                str3 = "";
                                                            } else if (i18 != 15) {
                                                                strArr = strArrSplit2;
                                                            } else {
                                                                caption = new Caption();
                                                                caption.start = time;
                                                                caption.content += str3;
                                                                strArr = strArrSplit2;
                                                                caption2 = caption;
                                                            }
                                                            z14 = z10;
                                                            i12 = 1;
                                                            z13 = true;
                                                        } else {
                                                            Caption caption4 = new Caption();
                                                            caption4.start = time;
                                                            strArr = strArrSplit2;
                                                            caption2 = caption4;
                                                        }
                                                        z14 = false;
                                                        i12 = 1;
                                                        z13 = true;
                                                    } else {
                                                        strArr = strArrSplit2;
                                                        str3 = "";
                                                        i12 = 1;
                                                        z13 = true;
                                                        z14 = true;
                                                    }
                                                }
                                                strArr = strArrSplit2;
                                                z13 = false;
                                                z14 = z10;
                                            } else {
                                                if (z11) {
                                                    strArr = strArrSplit2;
                                                    if ((i15 & 4160) == 4160) {
                                                        if (z10 && !str3.isEmpty()) {
                                                            str3 = str3 + "<br />";
                                                        }
                                                        if (!z10 && !caption2.content.isEmpty()) {
                                                            caption2.content += "<br />";
                                                        }
                                                        z12 = (i15 & 1) == 1;
                                                        if ((i15 & 16) != 16) {
                                                            switch ((short) ((i15 & 14) >> 1)) {
                                                                case 0:
                                                                default:
                                                                    z15 = z12;
                                                                    z13 = z11;
                                                                    z16 = false;
                                                                    z14 = z10;
                                                                    str2 = "white";
                                                                    break;
                                                                case 1:
                                                                    z15 = z12;
                                                                    str2 = "green";
                                                                    z13 = z11;
                                                                    z16 = false;
                                                                    z14 = z10;
                                                                    break;
                                                                case 2:
                                                                    z15 = z12;
                                                                    str2 = "blue";
                                                                    z13 = z11;
                                                                    z16 = false;
                                                                    z14 = z10;
                                                                    break;
                                                                case 3:
                                                                    z15 = z12;
                                                                    z13 = z11;
                                                                    z16 = false;
                                                                    z14 = z10;
                                                                    str2 = "cyan";
                                                                    break;
                                                                case 4:
                                                                    z15 = z12;
                                                                    z13 = z11;
                                                                    z16 = false;
                                                                    z14 = z10;
                                                                    str2 = "red";
                                                                    break;
                                                                case 5:
                                                                    z15 = z12;
                                                                    z13 = z11;
                                                                    z16 = false;
                                                                    z14 = z10;
                                                                    str2 = "yellow";
                                                                    break;
                                                                case 6:
                                                                    z15 = z12;
                                                                    z13 = z11;
                                                                    z16 = false;
                                                                    z14 = z10;
                                                                    str2 = "magenta";
                                                                    break;
                                                                case 7:
                                                                    z15 = z12;
                                                                    z13 = z11;
                                                                    z14 = z10;
                                                                    str2 = "white";
                                                                    i12 = 1;
                                                                    z16 = true;
                                                                    break;
                                                            }
                                                        } else {
                                                            z15 = z12;
                                                            i12 = 1;
                                                            z13 = z11;
                                                            z16 = false;
                                                            z14 = z10;
                                                            str2 = "white";
                                                        }
                                                    } else {
                                                        int i20 = i15 & PlaybackException.ERROR_CODE_DRM_UNSPECIFIED;
                                                        if (i20 == 4384) {
                                                            z12 = (i15 & 1) == 1;
                                                            switch ((short) ((i15 & 14) >> 1)) {
                                                                case 0:
                                                                    break;
                                                                case 1:
                                                                    break;
                                                                case 2:
                                                                    break;
                                                                case 3:
                                                                    break;
                                                                case 4:
                                                                    break;
                                                                case 5:
                                                                    break;
                                                                case 6:
                                                                    break;
                                                                case 7:
                                                                    z15 = z12;
                                                                    z13 = z11;
                                                                    z14 = z10;
                                                                    i12 = 1;
                                                                    z16 = true;
                                                                    break;
                                                                default:
                                                                    z15 = z12;
                                                                    break;
                                                            }
                                                        } else if ((i15 & 6012) != 5920) {
                                                            if (i20 == 4400) {
                                                                int i21 = i15 & 15;
                                                                if (z10) {
                                                                    str3 = str3 + decodeSpecialChar(i21);
                                                                } else {
                                                                    caption2.content += decodeSpecialChar(i21);
                                                                }
                                                            } else if ((i15 & 5728) == 4640) {
                                                                int i22 = i15 & 287;
                                                                if (z10) {
                                                                    decodeXtChar(str3, i22);
                                                                } else {
                                                                    decodeXtChar(caption2.content, i22);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                z13 = z11;
                                                z14 = z10;
                                            }
                                            i13 += i12;
                                            i10 = i14;
                                            bufferedReader2 = bufferedReader3;
                                            strArrSplit2 = strArr;
                                        }
                                        strArr = strArrSplit2;
                                        z13 = z11;
                                        z14 = z10;
                                    } else if (z13) {
                                        byte b10 = (byte) ((i15 & 32512) >>> 8);
                                        byte b11 = (byte) (i15 & 127);
                                        if (z14) {
                                            str3 = (str3 + decodeChar(b10)) + decodeChar(b11);
                                            z10 = z14;
                                        } else {
                                            StringBuilder sb = new StringBuilder();
                                            z10 = z14;
                                            sb.append(caption2.content);
                                            sb.append(decodeChar(b10));
                                            caption2.content = sb.toString();
                                            caption2.content += decodeChar(b11);
                                        }
                                        strArr = strArrSplit2;
                                        z14 = z10;
                                    } else {
                                        z10 = z14;
                                        z11 = z13;
                                        strArr = strArrSplit2;
                                        z13 = z11;
                                        z14 = z10;
                                    }
                                    i12 = 1;
                                    i13 += i12;
                                    i10 = i14;
                                    bufferedReader2 = bufferedReader3;
                                    strArrSplit2 = strArr;
                                } catch (NullPointerException unused2) {
                                    i10 = i14;
                                    timedTextObject.warnings += "unexpected end of file at line " + i10 + ", maybe last caption is not complete.\n\n";
                                    inputStream.close();
                                    timedTextObject.built = true;
                                    return timedTextObject;
                                }
                            }
                            bufferedReader = bufferedReader2;
                            i11 = i10;
                            z14 = z14;
                        }
                        line = bufferedReader.readLine();
                        i10 = i11;
                        bufferedReader2 = bufferedReader;
                    } catch (NullPointerException unused3) {
                    }
                } catch (NullPointerException unused4) {
                }
            }
            if (caption2 != null) {
                caption2.end = new Time("h:m:s:f/fps", "99:59:59:29/29.97");
            }
            Time time3 = caption2.start;
            if (time3 != null) {
                for (int i23 = time3.mseconds; timedTextObject.captions.containsKey(Integer.valueOf(i23)); i23++) {
                }
                timedTextObject.captions.put(Integer.valueOf(caption2.start.mseconds), caption2);
            }
            timedTextObject.cleanUnusedStyles();
            inputStream.close();
            timedTextObject.built = true;
            return timedTextObject;
        } catch (Throwable th) {
            inputStream.close();
            throw th;
        }
    }

    @Override // tv.danmaku.ijk.media.player.ui.subtitleconverter.subtitleFile.TimedTextFileFormat
    public String[] toFile(TimedTextObject timedTextObject) {
        String string;
        if (!timedTextObject.built) {
            return null;
        }
        ArrayList arrayList = new ArrayList((timedTextObject.captions.size() * 2) + 20);
        arrayList.add(0, "Scenarist_SCC V1.0\n");
        Caption caption = new Caption();
        caption.content = "";
        caption.end = new Time("h:mm:ss.cs", "0:00:00.00");
        int i10 = 1;
        for (Caption caption2 : timedTextObject.captions.values()) {
            int i11 = caption.end.mseconds;
            Time time = caption2.start;
            int i12 = time.mseconds;
            if (i11 > i12) {
                caption2.content += "<br />" + caption.content;
                Time time2 = caption2.start;
                time2.mseconds = (int) (((double) time2.mseconds) - 33.366700033366705d);
                String str = "" + caption2.start.getTime("hh:mm:ss:ff/29.97") + "\t942c 942c ";
                Time time3 = caption2.start;
                time3.mseconds = (int) (((double) time3.mseconds) + 33.366700033366705d);
                string = u1.j(str, "94ae 94ae 9420 9420 ");
            } else if (i11 < i12) {
                String str2 = "" + caption.end.getTime("hh:mm:ss:ff/29.97") + "\t942c 942c\n\n";
                Time time4 = caption2.start;
                time4.mseconds = (int) (((double) time4.mseconds) - 33.366700033366705d);
                StringBuilder sbC = a.c(str2);
                sbC.append(caption2.start.getTime("hh:mm:ss:ff/29.97"));
                sbC.append("\t94ae 94ae 9420 9420 ");
                string = sbC.toString();
                Time time5 = caption2.start;
                time5.mseconds = (int) (((double) time5.mseconds) + 33.366700033366705d);
            } else {
                time.mseconds = (int) (((double) i12) - 33.366700033366705d);
                string = "" + caption2.start.getTime("hh:mm:ss:ff/29.97") + "\t942c 942c 94ae 94ae 9420 9420 ";
                Time time6 = caption2.start;
                time6.mseconds = (int) (((double) time6.mseconds) + 33.366700033366705d);
            }
            StringBuilder sbC2 = a.c(string);
            sbC2.append(codeText(caption2));
            arrayList.add(i10, u1.j(sbC2.toString(), "8080 8080 942f 942f\n"));
            caption = caption2;
            i10++;
        }
        arrayList.add(i10, "");
        int size = arrayList.size();
        String[] strArr = new String[size];
        for (int i13 = 0; i13 < size; i13++) {
            strArr[i13] = (String) arrayList.get(i13);
        }
        return strArr;
    }
}
