59 lines
2.1 KiB
Java
59 lines
2.1 KiB
Java
package com.baidu.cloud.videocache;
|
|
|
|
import android.net.Uri;
|
|
import android.text.TextUtils;
|
|
import java.util.Scanner;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class c {
|
|
private static final Logger a = LoggerFactory.getLogger("HlsPlaylistUtil");
|
|
|
|
private static String a(String str, String str2, String str3) {
|
|
if (str3 == null || str3.isEmpty()) {
|
|
return str3;
|
|
}
|
|
Uri a2 = ac.a(str, str2);
|
|
return TextUtils.isEmpty(a2.toString()) ? str3 : str3.replace(str2, z.b(a2.toString()));
|
|
}
|
|
|
|
private static boolean a(Scanner scanner) {
|
|
return scanner != null && scanner.hasNextLine() && "#EXTM3U".equals(scanner.nextLine());
|
|
}
|
|
|
|
public static byte[] a(byte[] bArr, String str) {
|
|
if (bArr == null || bArr.length == 0) {
|
|
return null;
|
|
}
|
|
String trim = new String(bArr).trim();
|
|
Scanner scanner = new Scanner(trim);
|
|
if (!a(scanner)) {
|
|
a.debug("Input does not start with the #EXTM3U.url :" + str);
|
|
return null;
|
|
}
|
|
char c = 65535;
|
|
while (scanner.hasNextLine()) {
|
|
String trim2 = scanner.nextLine().trim();
|
|
if (c == 65535) {
|
|
if (trim2.startsWith("#EXT-X-STREAM-INF")) {
|
|
c = 1;
|
|
} else if (trim2.startsWith("#EXT-X-TARGETDURATION") || trim2.startsWith("#EXT-X-MEDIA-SEQUENCE") || trim2.startsWith("#EXTINF") || trim2.startsWith("#EXT-X-KEY") || trim2.startsWith("#EXT-X-BYTERANGE") || trim2.equals("#EXT-X-DISCONTINUITY") || trim2.equals("#EXT-X-DISCONTINUITY-SEQUENCE") || trim2.equals("#EXT-X-ENDLIST")) {
|
|
c = 2;
|
|
}
|
|
}
|
|
if (c == 1) {
|
|
if (trim2.startsWith("#EXT-X-STREAM-INF")) {
|
|
trim2 = scanner.nextLine();
|
|
trim = a(str, trim2, trim);
|
|
}
|
|
} else if (c == 2 && !trim2.startsWith("#")) {
|
|
trim = a(str, trim2, trim);
|
|
}
|
|
}
|
|
scanner.close();
|
|
a.debug("Convert completed:\n" + trim);
|
|
return trim.getBytes();
|
|
}
|
|
}
|