package Y;

import I.i;
import android.graphics.Bitmap;
import android.util.Log;
import b0.o;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes.dex */
public class d implements i, I.e {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private static final Pattern f1865e = Pattern.compile("(\\d+)x(\\d+)");

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private static final Pattern f1866f = Pattern.compile("^size: (\\d+)x(\\d+)$");

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private static final Pattern f1867g = Pattern.compile("[0-9a-fA-F]{6}");

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private static final Pattern f1868h = Pattern.compile("^palette:( [0-9a-fA-F]{6},){15} [0-9a-fA-F]{6}");

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private static final Pattern f1869i = Pattern.compile("^id: (.*?), index: \\d+$");

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private static final Pattern f1870j = Pattern.compile("\\d{2}:[0-5]\\d:[0-5]\\d:\\d{3}");

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private static final Pattern f1871k = Pattern.compile("[0-9a-fA-F]{9}");

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private static final Pattern f1872l = Pattern.compile("^timestamp: \\d{2}:[0-5]\\d:[0-5]\\d:\\d{3}, filepos: [0-9a-fA-F]{9}$");

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private String f1874b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private String f1875c;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private BufferedInputStream f1873a = null;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private int f1876d = 0;

    public class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        public long f1877a;

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public long f1878b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        public long f1879c;

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        public int f1880d;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public int[] f1881e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        public int[] f1882f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public int f1883g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        private c f1884h;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        private Bitmap f1885i;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        private boolean f1886j = false;

        public a(long j2, int i2, int[] iArr, int[] iArr2, int i3) {
            this.f1879c = j2;
            this.f1880d = i2;
            this.f1881e = iArr;
            this.f1882f = iArr2;
            this.f1883g = i3;
            b();
        }

        /* JADX WARN: Code restructure failed: missing block: B:124:0x023c, code lost:
        
            continue;
         */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        private void b() {
            /*
                Method dump skipped, instruction units count: 680
                To view this dump add '--comments-level debug' option
            */
            throw new UnsupportedOperationException("Method not decompiled: Y.d.a.b():void");
        }

        public Bitmap a() {
            Bitmap bitmap = this.f1885i;
            if (bitmap != null) {
                return bitmap;
            }
            c cVar = this.f1884h;
            if (cVar == null) {
                return null;
            }
            this.f1885i = cVar.b();
            if (this.f1886j) {
                o.d("VobSubParser", " bm = " + this.f1885i, 16);
            }
            return this.f1885i;
        }
    }

    public d(String str) {
        this.f1874b = str;
        g();
    }

    private void g() {
        String str;
        String str2 = this.f1874b;
        File file = null;
        if (str2 == null || str2.length() <= 0) {
            str = null;
        } else {
            int iLastIndexOf = this.f1874b.lastIndexOf(".");
            if (iLastIndexOf == -1) {
                Log.e("VobSubParser", "file name error.");
                return;
            }
            str = this.f1874b.substring(0, iLastIndexOf) + ".sub";
            o.c("VobSubParser", 16, "sub filePath=", str);
        }
        if (str == null) {
            if (file != null) {
                BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file));
                this.f1873a = bufferedInputStream;
                bufferedInputStream.mark(Integer.MAX_VALUE);
            }
            Log.e("VobSubParser", "file not exist.");
            return;
        }
        try {
            file = new File(str);
            if (file != null && file.exists()) {
                BufferedInputStream bufferedInputStream2 = new BufferedInputStream(new FileInputStream(file));
                this.f1873a = bufferedInputStream2;
                bufferedInputStream2.mark(Integer.MAX_VALUE);
            }
            Log.e("VobSubParser", "file not exist.");
            return;
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        o.d("VobSubParser", "initSubFileStream filePath = " + str, 16);
    }

    private int[] h(String str) {
        Matcher matcher = f1865e.matcher(str);
        int[] iArr = new int[2];
        if (matcher.find()) {
            try {
                int i2 = 0;
                for (String str2 : matcher.group().split("x")) {
                    iArr[i2] = Integer.parseInt(str2);
                    o.c("VobSubParser", 16, "parseBaseRect index = ", Integer.valueOf(i2), " val = ", Integer.valueOf(iArr[i2]));
                    i2++;
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return iArr;
    }

    private int[] i(String str) {
        int[] iArr = new int[16];
        Matcher matcher = f1867g.matcher(str);
        int i2 = 0;
        while (matcher.find()) {
            iArr[i2] = Integer.parseInt(matcher.group(), 16);
            o.c("VobSubParser", 16, "parsePalette index = ", Integer.valueOf(i2), " val = ", Integer.toHexString(iArr[i2]));
            i2++;
        }
        return iArr;
    }

    private static int j(String str) {
        o.c("VobSubParser", 16, "parsePosition line = ", str);
        Matcher matcher = f1871k.matcher(str);
        if (!matcher.find()) {
            throw new NumberFormatException("has invalid format");
        }
        int i2 = Integer.parseInt(matcher.group(), 16);
        o.c("VobSubParser", 16, "parsePosition value = ", Integer.valueOf(i2));
        return i2;
    }

    private static long k(String str) {
        o.c("VobSubParser", 16, "parseTimestampUs line = ", str);
        Matcher matcher = f1870j.matcher(str);
        if (!matcher.find()) {
            throw new NumberFormatException("has invalid format");
        }
        String[] strArrSplit = matcher.group().split(":", 4);
        long j2 = ((((((Long.parseLong(strArrSplit[0]) * 60) + Long.parseLong(strArrSplit[1])) * 60) + Long.parseLong(strArrSplit[2])) * 1000) + Long.parseLong(strArrSplit[3])) * 1000;
        o.c("VobSubParser", 16, "parseTimestampUs value = ", Long.valueOf(j2));
        return j2;
    }

    @Override // I.i
    public boolean a(String str) {
        boolean zEquals = "text/ext/vobsub".equals(str);
        o.c("VobSubParser", 16, "canParse  type = ", str, " can = ", Boolean.valueOf(zEquals));
        return zEquals;
    }

    /* JADX WARN: Code restructure failed: missing block: B:47:0x0187, code lost:
    
        r3 = new long[r12.size() * 2];
        r0 = 0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:49:0x0195, code lost:
    
        if (r0 >= r12.size()) goto L103;
     */
    /* JADX WARN: Code restructure failed: missing block: B:50:0x0197, code lost:
    
        r1 = r0 * 2;
        r2 = (Y.d.a) r12.get(r0);
        r3[r1] = r2.f1877a;
        r3[r1 + 1] = r2.f1878b;
        r0 = r0 + 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:51:0x01ac, code lost:
    
        r7 = new Y.e(0, r3, r13, r18, r12);
     */
    /* JADX WARN: Code restructure failed: missing block: B:52:0x01b8, code lost:
    
        r10.close();
        r11.close();
     */
    /* JADX WARN: Removed duplicated region for block: B:44:0x0173  */
    @Override // I.i
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public I.g b(byte[] r23, int r24, int r25) {
        /*
            Method dump skipped, instruction units count: 579
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: Y.d.b(byte[], int, int):I.g");
    }

    @Override // I.e
    public void d(String str) {
        this.f1875c = str;
    }

    public void f(int i2) {
        this.f1876d = i2;
        Log.d("VobSubParser", "enableSubtitleIndex , mCurrentSubtitleIndex== " + this.f1876d);
    }

    public final void finalize() throws Throwable {
        BufferedInputStream bufferedInputStream = this.f1873a;
        if (bufferedInputStream != null) {
            bufferedInputStream.close();
            this.f1873a = null;
            Log.d("VobSubParser", "finalize data.close()");
        }
        super.finalize();
    }
}
