521 lines
27 KiB
Java
521 lines
27 KiB
Java
package c.i.a.c.e2.q;
|
||
|
||
import android.graphics.PointF;
|
||
import android.text.Layout;
|
||
import android.text.SpannableString;
|
||
import android.text.TextUtils;
|
||
import android.text.style.ForegroundColorSpan;
|
||
import android.text.style.StyleSpan;
|
||
import android.util.Log;
|
||
import androidx.annotation.Nullable;
|
||
import c.i.a.c.e2.c;
|
||
import c.i.a.c.e2.d;
|
||
import c.i.a.c.e2.f;
|
||
import c.i.a.c.e2.q.c;
|
||
import c.i.a.c.i2.f0;
|
||
import c.i.a.c.i2.p;
|
||
import c.i.a.c.i2.w;
|
||
import com.airbnb.lottie.parser.AnimatableValueParser;
|
||
import java.util.ArrayList;
|
||
import java.util.LinkedHashMap;
|
||
import java.util.List;
|
||
import java.util.Map;
|
||
import java.util.Objects;
|
||
import java.util.regex.Matcher;
|
||
import java.util.regex.Pattern;
|
||
/* compiled from: SsaDecoder */
|
||
public final class a extends d {
|
||
public static final Pattern n = Pattern.compile("(?:(\\d+):)?(\\d+):(\\d+)[:.](\\d+)");
|
||
public final boolean o;
|
||
@Nullable
|
||
public final b p;
|
||
public Map<String, c> q;
|
||
public float r = -3.4028235E38f;
|
||
|
||
/* renamed from: s reason: collision with root package name */
|
||
public float f841s = -3.4028235E38f;
|
||
|
||
public a(@Nullable List<byte[]> list) {
|
||
super("SsaDecoder");
|
||
if (list == null || list.isEmpty()) {
|
||
this.o = false;
|
||
this.p = null;
|
||
return;
|
||
}
|
||
this.o = true;
|
||
String l = f0.l(list.get(0));
|
||
AnimatableValueParser.k(l.startsWith("Format:"));
|
||
b a = b.a(l);
|
||
Objects.requireNonNull(a);
|
||
this.p = a;
|
||
m(new w(list.get(1)));
|
||
}
|
||
|
||
public static int k(long j, List<Long> list, List<List<c>> list2) {
|
||
int i;
|
||
int size = list.size() - 1;
|
||
while (true) {
|
||
if (size < 0) {
|
||
i = 0;
|
||
break;
|
||
} else if (list.get(size).longValue() == j) {
|
||
return size;
|
||
} else {
|
||
if (list.get(size).longValue() < j) {
|
||
i = size + 1;
|
||
break;
|
||
}
|
||
size--;
|
||
}
|
||
}
|
||
list.add(i, Long.valueOf(j));
|
||
list2.add(i, i == 0 ? new ArrayList() : new ArrayList(list2.get(i - 1)));
|
||
return i;
|
||
}
|
||
|
||
public static float l(int i) {
|
||
if (i == 0) {
|
||
return 0.05f;
|
||
}
|
||
if (i != 1) {
|
||
return i != 2 ? -3.4028235E38f : 0.95f;
|
||
}
|
||
return 0.5f;
|
||
}
|
||
|
||
public static long n(String str) {
|
||
Matcher matcher = n.matcher(str.trim());
|
||
if (!matcher.matches()) {
|
||
return -9223372036854775807L;
|
||
}
|
||
String group = matcher.group(1);
|
||
int i = f0.a;
|
||
long parseLong = (Long.parseLong(matcher.group(2)) * 60 * 1000000) + (Long.parseLong(group) * 60 * 60 * 1000000);
|
||
return (Long.parseLong(matcher.group(4)) * 10000) + (Long.parseLong(matcher.group(3)) * 1000000) + parseLong;
|
||
}
|
||
|
||
@Override // c.i.a.c.e2.d
|
||
public f j(byte[] bArr, int i, boolean z2) {
|
||
w wVar;
|
||
b bVar;
|
||
long j;
|
||
float f;
|
||
int i2;
|
||
int i3;
|
||
Layout.Alignment alignment;
|
||
int i4;
|
||
int i5;
|
||
float f2;
|
||
float f3;
|
||
int i6;
|
||
float f4;
|
||
float f5;
|
||
int i7;
|
||
int i8;
|
||
a aVar = this;
|
||
ArrayList arrayList = new ArrayList();
|
||
ArrayList arrayList2 = new ArrayList();
|
||
w wVar2 = new w(bArr, i);
|
||
if (!aVar.o) {
|
||
aVar.m(wVar2);
|
||
}
|
||
b bVar2 = aVar.o ? aVar.p : null;
|
||
while (true) {
|
||
String g = wVar2.g();
|
||
if (g == null) {
|
||
return new d(arrayList, arrayList2);
|
||
}
|
||
if (g.startsWith("Format:")) {
|
||
bVar2 = b.a(g);
|
||
} else {
|
||
if (g.startsWith("Dialogue:")) {
|
||
if (bVar2 == null) {
|
||
c.d.b.a.a.g0("Skipping dialogue line before complete format: ", g, "SsaDecoder");
|
||
} else {
|
||
AnimatableValueParser.k(g.startsWith("Dialogue:"));
|
||
String[] split = g.substring(9).split(",", bVar2.e);
|
||
if (split.length != bVar2.e) {
|
||
c.d.b.a.a.g0("Skipping dialogue line with fewer columns than format: ", g, "SsaDecoder");
|
||
} else {
|
||
long n2 = n(split[bVar2.a]);
|
||
if (n2 == -9223372036854775807L) {
|
||
c.d.b.a.a.g0("Skipping invalid timing: ", g, "SsaDecoder");
|
||
} else {
|
||
long n3 = n(split[bVar2.b]);
|
||
if (n3 == -9223372036854775807L) {
|
||
c.d.b.a.a.g0("Skipping invalid timing: ", g, "SsaDecoder");
|
||
} else {
|
||
Map<String, c> map = aVar.q;
|
||
c cVar = (map == null || (i8 = bVar2.f842c) == -1) ? null : map.get(split[i8].trim());
|
||
String str = split[bVar2.d];
|
||
Matcher matcher = c.b.a.matcher(str);
|
||
PointF pointF = null;
|
||
int i9 = -1;
|
||
while (true) {
|
||
wVar = wVar2;
|
||
if (matcher.find()) {
|
||
String group = matcher.group(1);
|
||
Objects.requireNonNull(group);
|
||
try {
|
||
PointF a = c.b.a(group);
|
||
if (a != null) {
|
||
pointF = a;
|
||
}
|
||
} catch (RuntimeException unused) {
|
||
}
|
||
try {
|
||
Matcher matcher2 = c.b.d.matcher(group);
|
||
if (matcher2.find()) {
|
||
String group2 = matcher2.group(1);
|
||
Objects.requireNonNull(group2);
|
||
i7 = c.a(group2);
|
||
} else {
|
||
i7 = -1;
|
||
}
|
||
if (i7 != -1) {
|
||
i9 = i7;
|
||
}
|
||
} catch (RuntimeException unused2) {
|
||
}
|
||
wVar2 = wVar;
|
||
} else {
|
||
String replace = c.b.a.matcher(str).replaceAll("").replace("\\N", "\n").replace("\\n", "\n").replace("\\h", " ");
|
||
float f6 = aVar.r;
|
||
float f7 = aVar.f841s;
|
||
SpannableString spannableString = new SpannableString(replace);
|
||
if (cVar != null) {
|
||
if (cVar.f843c != null) {
|
||
bVar = bVar2;
|
||
j = n3;
|
||
spannableString.setSpan(new ForegroundColorSpan(cVar.f843c.intValue()), 0, spannableString.length(), 33);
|
||
} else {
|
||
bVar = bVar2;
|
||
j = n3;
|
||
}
|
||
float f8 = cVar.d;
|
||
if (f8 == -3.4028235E38f || f7 == -3.4028235E38f) {
|
||
f4 = -3.4028235E38f;
|
||
i6 = Integer.MIN_VALUE;
|
||
} else {
|
||
f4 = f8 / f7;
|
||
i6 = 1;
|
||
}
|
||
boolean z3 = cVar.e;
|
||
if (!z3 || !cVar.f) {
|
||
f5 = f4;
|
||
if (z3) {
|
||
spannableString.setSpan(new StyleSpan(1), 0, spannableString.length(), 33);
|
||
} else if (cVar.f) {
|
||
spannableString.setSpan(new StyleSpan(2), 0, spannableString.length(), 33);
|
||
}
|
||
} else {
|
||
f5 = f4;
|
||
spannableString.setSpan(new StyleSpan(3), 0, spannableString.length(), 33);
|
||
}
|
||
i3 = -1;
|
||
i2 = i6;
|
||
f = f5;
|
||
} else {
|
||
bVar = bVar2;
|
||
j = n3;
|
||
i3 = -1;
|
||
i2 = Integer.MIN_VALUE;
|
||
f = -3.4028235E38f;
|
||
}
|
||
if (i9 == i3) {
|
||
i9 = cVar != null ? cVar.b : i3;
|
||
}
|
||
switch (i9) {
|
||
case 0:
|
||
default:
|
||
Log.w("SsaDecoder", c.d.b.a.a.j("Unknown alignment: ", i9));
|
||
case -1:
|
||
alignment = null;
|
||
break;
|
||
case 1:
|
||
case 4:
|
||
case 7:
|
||
alignment = Layout.Alignment.ALIGN_NORMAL;
|
||
break;
|
||
case 2:
|
||
case 5:
|
||
case 8:
|
||
alignment = Layout.Alignment.ALIGN_CENTER;
|
||
break;
|
||
case 3:
|
||
case 6:
|
||
case 9:
|
||
alignment = Layout.Alignment.ALIGN_OPPOSITE;
|
||
break;
|
||
}
|
||
switch (i9) {
|
||
case 0:
|
||
default:
|
||
Log.w("SsaDecoder", c.d.b.a.a.j("Unknown alignment: ", i9));
|
||
case -1:
|
||
i4 = Integer.MIN_VALUE;
|
||
break;
|
||
case 1:
|
||
case 4:
|
||
case 7:
|
||
i4 = 0;
|
||
break;
|
||
case 2:
|
||
case 5:
|
||
case 8:
|
||
i4 = 1;
|
||
break;
|
||
case 3:
|
||
case 6:
|
||
case 9:
|
||
i4 = 2;
|
||
break;
|
||
}
|
||
switch (i9) {
|
||
case 0:
|
||
default:
|
||
Log.w("SsaDecoder", c.d.b.a.a.j("Unknown alignment: ", i9));
|
||
case -1:
|
||
i5 = Integer.MIN_VALUE;
|
||
break;
|
||
case 1:
|
||
case 2:
|
||
case 3:
|
||
i5 = 2;
|
||
break;
|
||
case 4:
|
||
case 5:
|
||
case 6:
|
||
i5 = 1;
|
||
break;
|
||
case 7:
|
||
case 8:
|
||
case 9:
|
||
i5 = 0;
|
||
break;
|
||
}
|
||
if (pointF == null || f7 == -3.4028235E38f || f6 == -3.4028235E38f) {
|
||
f3 = l(i4);
|
||
f2 = l(i5);
|
||
} else {
|
||
f3 = pointF.x / f6;
|
||
f2 = pointF.y / f7;
|
||
}
|
||
c.i.a.c.e2.c cVar2 = new c.i.a.c.e2.c(spannableString, alignment, null, f2, 0, i5, f3, i4, i2, f, -3.4028235E38f, -3.4028235E38f, false, -16777216, Integer.MIN_VALUE, 0.0f, null);
|
||
int k = k(j, arrayList2, arrayList);
|
||
for (int k2 = k(n2, arrayList2, arrayList); k2 < k; k2++) {
|
||
((List) arrayList.get(k2)).add(cVar2);
|
||
}
|
||
aVar = this;
|
||
bVar2 = bVar;
|
||
wVar2 = wVar;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
wVar = wVar2;
|
||
bVar = bVar2;
|
||
aVar = this;
|
||
bVar2 = bVar;
|
||
wVar2 = wVar;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* JADX INFO: Can't fix incorrect switch cases order, some code will duplicate */
|
||
/* JADX WARNING: Removed duplicated region for block: B:100:0x01ee */
|
||
/* JADX WARNING: Removed duplicated region for block: B:101:0x01fb */
|
||
/* JADX WARNING: Removed duplicated region for block: B:104:0x0202 */
|
||
/* JADX WARNING: Removed duplicated region for block: B:105:0x020f */
|
||
/* JADX WARNING: Removed duplicated region for block: B:111:0x0233 */
|
||
public final void m(w wVar) {
|
||
char c2;
|
||
c cVar;
|
||
float f;
|
||
while (true) {
|
||
String g = wVar.g();
|
||
if (g != null) {
|
||
int i = 91;
|
||
char c3 = 2;
|
||
char c4 = 1;
|
||
if ("[Script Info]".equalsIgnoreCase(g)) {
|
||
while (true) {
|
||
String g2 = wVar.g();
|
||
if (g2 != null && (wVar.a() == 0 || wVar.c() != 91)) {
|
||
String[] split = g2.split(":");
|
||
if (split.length == 2) {
|
||
String K = f0.K(split[0].trim());
|
||
K.hashCode();
|
||
if (K.equals("playresx")) {
|
||
this.r = Float.parseFloat(split[1].trim());
|
||
} else if (K.equals("playresy")) {
|
||
try {
|
||
this.f841s = Float.parseFloat(split[1].trim());
|
||
} catch (NumberFormatException unused) {
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
} else if ("[V4+ Styles]".equalsIgnoreCase(g)) {
|
||
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
||
while (true) {
|
||
c.a aVar = null;
|
||
while (true) {
|
||
String g3 = wVar.g();
|
||
if (g3 != null && (wVar.a() == 0 || wVar.c() != i)) {
|
||
if (g3.startsWith("Format:")) {
|
||
String[] split2 = TextUtils.split(g3.substring(7), ",");
|
||
int i2 = -1;
|
||
int i3 = -1;
|
||
int i4 = -1;
|
||
int i5 = -1;
|
||
int i6 = -1;
|
||
int i7 = -1;
|
||
for (int i8 = 0; i8 < split2.length; i8++) {
|
||
String K2 = f0.K(split2[i8].trim());
|
||
K2.hashCode();
|
||
switch (K2.hashCode()) {
|
||
case -1178781136:
|
||
if (K2.equals("italic")) {
|
||
c2 = 0;
|
||
break;
|
||
}
|
||
c2 = 65535;
|
||
break;
|
||
case -70925746:
|
||
if (K2.equals("primarycolour")) {
|
||
c2 = 1;
|
||
break;
|
||
}
|
||
c2 = 65535;
|
||
break;
|
||
case 3029637:
|
||
if (K2.equals("bold")) {
|
||
c2 = 2;
|
||
break;
|
||
}
|
||
c2 = 65535;
|
||
break;
|
||
case 3373707:
|
||
if (K2.equals("name")) {
|
||
c2 = 3;
|
||
break;
|
||
}
|
||
c2 = 65535;
|
||
break;
|
||
case 366554320:
|
||
if (K2.equals("fontsize")) {
|
||
c2 = 4;
|
||
break;
|
||
}
|
||
c2 = 65535;
|
||
break;
|
||
case 1767875043:
|
||
if (K2.equals("alignment")) {
|
||
c2 = 5;
|
||
break;
|
||
}
|
||
c2 = 65535;
|
||
break;
|
||
default:
|
||
c2 = 65535;
|
||
break;
|
||
}
|
||
if (c2 == 0) {
|
||
i7 = i8;
|
||
} else if (c2 == c4) {
|
||
i4 = i8;
|
||
} else if (c2 == c3) {
|
||
i6 = i8;
|
||
} else if (c2 == 3) {
|
||
i2 = i8;
|
||
} else if (c2 == 4) {
|
||
i5 = i8;
|
||
} else if (c2 == 5) {
|
||
i3 = i8;
|
||
}
|
||
}
|
||
if (i2 != -1) {
|
||
aVar = new c.a(i2, i3, i4, i5, i6, i7, split2.length);
|
||
i = 91;
|
||
} else {
|
||
i = 91;
|
||
}
|
||
} else {
|
||
if (g3.startsWith("Style:")) {
|
||
if (aVar == null) {
|
||
c.d.b.a.a.g0("Skipping 'Style:' line before 'Format:' line: ", g3, "SsaDecoder");
|
||
} else {
|
||
AnimatableValueParser.k(g3.startsWith("Style:"));
|
||
String[] split3 = TextUtils.split(g3.substring(6), ",");
|
||
int length = split3.length;
|
||
int i9 = aVar.g;
|
||
if (length != i9) {
|
||
Object[] objArr = new Object[3];
|
||
objArr[0] = Integer.valueOf(i9);
|
||
objArr[c4] = Integer.valueOf(split3.length);
|
||
objArr[c3] = g3;
|
||
Log.w("SsaStyle", f0.k("Skipping malformed 'Style:' line (expected %s values, found %s): '%s'", objArr));
|
||
} else {
|
||
try {
|
||
String trim = split3[aVar.a].trim();
|
||
int i10 = aVar.b;
|
||
int a = i10 != -1 ? c.a(split3[i10].trim()) : -1;
|
||
int i11 = aVar.f844c;
|
||
Integer c5 = i11 != -1 ? c.c(split3[i11].trim()) : null;
|
||
int i12 = aVar.d;
|
||
if (i12 != -1) {
|
||
String trim2 = split3[i12].trim();
|
||
try {
|
||
f = Float.parseFloat(trim2);
|
||
} catch (NumberFormatException e) {
|
||
p.c("SsaStyle", "Failed to parse font size: '" + trim2 + "'", e);
|
||
}
|
||
int i13 = aVar.e;
|
||
boolean b = i13 == -1 ? c.b(split3[i13].trim()) : false;
|
||
int i14 = aVar.f;
|
||
cVar = new c(trim, a, c5, f, b, i14 == -1 ? c.b(split3[i14].trim()) : false);
|
||
if (cVar != null) {
|
||
linkedHashMap.put(cVar.a, cVar);
|
||
}
|
||
}
|
||
f = -3.4028235E38f;
|
||
int i13 = aVar.e;
|
||
if (i13 == -1) {
|
||
}
|
||
int i14 = aVar.f;
|
||
cVar = new c(trim, a, c5, f, b, i14 == -1 ? c.b(split3[i14].trim()) : false);
|
||
} catch (RuntimeException e2) {
|
||
p.c("SsaStyle", "Skipping malformed 'Style:' line: '" + g3 + "'", e2);
|
||
}
|
||
if (cVar != null) {
|
||
}
|
||
}
|
||
cVar = null;
|
||
if (cVar != null) {
|
||
}
|
||
}
|
||
}
|
||
i = 91;
|
||
c3 = 2;
|
||
c4 = 1;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
this.q = linkedHashMap;
|
||
} else if ("[V4 Styles]".equalsIgnoreCase(g)) {
|
||
Log.i("SsaDecoder", "[V4 Styles] are not supported");
|
||
} else if ("[Events]".equalsIgnoreCase(g)) {
|
||
return;
|
||
}
|
||
} else {
|
||
return;
|
||
}
|
||
}
|
||
}
|
||
}
|