Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
package com.baidu.cloud.media.download;
import java.util.Observable;
import java.util.Observer;
/* loaded from: classes.dex */
public abstract class DownloadObserver implements Observer {
public abstract void update(DownloadableVideoItem downloadableVideoItem);
@Override // java.util.Observer
public void update(Observable observable, Object obj) {
if (observable instanceof DownloadableVideoItem) {
update((DownloadableVideoItem) observable);
}
}
}

View File

@@ -0,0 +1,108 @@
package com.baidu.cloud.media.download;
import com.ijm.dataencryption.de.DataDecryptTool;
import com.ubt.jimu.base.entities.Course;
import java.util.Observable;
/* loaded from: classes.dex */
public abstract class DownloadableVideoItem extends Observable {
public static final int ERROR_CODE_INVALID_URL = 1;
public static final int ERROR_CODE_M3U8_DRM_INVALID = 6;
public static final int ERROR_CODE_M3U8_INVALID_FORMAT = 4;
public static final int ERROR_CODE_M3U8_SAVE_FAILED = 5;
public static final int ERROR_CODE_NETWORK_FAILED = 2;
public static final int ERROR_CODE_NO_ERROR = 0;
public static final int ERROR_CODE_SDCARD_UNMOUNTED = 3;
public static final int ERROR_CODE_TS_SAVE_FAILED = 7;
public static final String[] a = {"ERROR_CODE_NO_ERROR", "ERROR_CODE_INVALID_URL", "ERROR_CODE_NETWORK_FAILED", "ERROR_CODE_SDCARD_UNMOUNTED", "ERROR_CODE_M3U8_INVALID_FORMAT", "ERROR_CODE_M3U8_SAVE_FAILED", "ERROR_CODE_M3U8_DRM_INVALID", "ERROR_CODE_TS_SAVE_FAILED"};
protected String b;
protected String c;
protected String d;
protected volatile int e;
protected volatile int f;
protected volatile int g;
protected volatile DownloadStatus h = DownloadStatus.NONE;
protected String i;
protected volatile int j;
public enum DownloadStatus {
NONE(0, "first add"),
DOWNLOADING(1, "downloading videos"),
PAUSED(2, "paused"),
COMPLETED(3, Course.STATUS_COMPLETED),
ERROR(4, "failed to download"),
DELETED(5, "delete manually"),
PENDING(6, "pending, will start automatically(blocked by Parallel Strategy)");
private int code;
private String msg;
DownloadStatus(int i, String str) {
this.code = i;
this.msg = str;
}
public int getCode() {
return this.code;
}
public String getMessage() {
return this.msg;
}
}
public int getErrorCode() {
return this.j;
}
public String getFailReason() {
return this.i;
}
public String getLocalAbsolutePath() {
String str = this.d;
if (str == null || str.equals("")) {
return this.c;
}
String str2 = this.c;
if (str2 == null || str2.equals("")) {
return null;
}
return this.c + "/" + this.d;
}
public float getProgress() {
return this.e / 100.0f;
}
public String getSpeed() {
StringBuilder sb;
String str;
if (this.h != DownloadStatus.DOWNLOADING) {
return "0KB/s";
}
if (this.f < 1024) {
sb = new StringBuilder();
sb.append(this.f);
str = "KB/s";
} else {
sb = new StringBuilder();
sb.append(this.f / DataDecryptTool.DECRYPT_SP_FILE);
str = "MB/s";
}
sb.append(str);
return sb.toString();
}
public DownloadStatus getStatus() {
return this.h;
}
public int getTotalSize() {
return this.g;
}
public String getUrl() {
return this.b;
}
}

View File

@@ -0,0 +1,47 @@
package com.baidu.cloud.media.download;
import android.content.Context;
/* loaded from: classes.dex */
public class LocalHlsSec {
static {
System.loadLibrary("hls-download");
}
public static String bytes2HexStr(byte[] bArr) {
if (bArr == null || bArr.length == 0) {
return null;
}
StringBuffer stringBuffer = new StringBuffer();
for (int i = 0; i < bArr.length; i++) {
if ((bArr[i] & 255) < 16) {
stringBuffer.append("0");
}
stringBuffer.append(Long.toHexString(bArr[i] & 255));
}
return stringBuffer.toString();
}
public static String decryptStr(Context context, String str) {
return bytes2HexStr(new LocalHlsSec().crypt(context, hexStr2Bytes(str), 1));
}
public static byte[] hexStr2Bytes(String str) {
if (str.length() < 1) {
return null;
}
byte[] bArr = new byte[str.length() / 2];
for (int i = 0; i < str.length() / 2; i++) {
int i2 = i * 2;
int i3 = i2 + 1;
bArr[i] = (byte) ((Integer.parseInt(str.substring(i2, i3), 16) * 16) + Integer.parseInt(str.substring(i3, i2 + 2), 16));
}
return bArr;
}
public native byte[] crypt(Context context, byte[] bArr, int i);
public String getMD5(String str) {
return a.b(str);
}
}

View File

@@ -0,0 +1,238 @@
package com.baidu.cloud.media.download;
import android.content.Context;
import android.util.Log;
import com.baidu.cloud.media.download.DownloadableVideoItem;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONObject;
/* loaded from: classes.dex */
public class VideoDownloadManager {
private static int c = 5;
private static volatile VideoDownloadManager i;
private static volatile String j;
private String a;
private String b;
private Context f;
private String g;
private volatile int d = 0;
private Queue<String> e = new LinkedList();
private ConcurrentHashMap<String, b> h = new ConcurrentHashMap<>();
private VideoDownloadManager(Context context, String str) {
this.a = "_unk@nown_##$ default $##_unk@nown_";
this.b = "4f0fecb0c26217433bafbf2a0d595c4e";
this.f = context.getApplicationContext();
this.a = str;
this.b = a.b(str);
f();
}
protected static VideoDownloadManager b() {
return i;
}
private void f() {
this.h.clear();
try {
for (Map.Entry entry : ((HashMap) this.f.getSharedPreferences(e(), 0).getAll()).entrySet()) {
try {
String str = (String) entry.getKey();
JSONObject jSONObject = new JSONObject((String) entry.getValue());
jSONObject.put("urle", str);
this.h.put(jSONObject.getString("url"), b.a(this.f, e(), jSONObject));
} catch (Exception e) {
Log.d("VideoDownloadManager", "" + e.getMessage());
}
}
} catch (Exception e2) {
Log.d("VideoDownloadManager", "" + e2.getMessage());
}
}
public static synchronized VideoDownloadManager getInstance(Context context, String str) {
synchronized (VideoDownloadManager.class) {
if (str != null) {
if (!str.equals("")) {
if (!str.equals(j)) {
j = str;
if (i != null) {
i.stopAll();
i = null;
}
}
if (i == null) {
i = new VideoDownloadManager(context, str);
}
return i;
}
}
Log.e("VideoDownloadManager", "getInstance failed, userName is null or empty.");
return null;
}
}
protected String a() {
return this.g;
}
protected boolean a(String str) {
boolean z;
synchronized (this.e) {
z = false;
if (!this.e.contains(str)) {
if (this.d >= c) {
this.e.offer(str);
} else {
this.d++;
z = true;
}
}
}
return z;
}
protected void b(String str) {
synchronized (this.e) {
this.e.remove(str);
}
}
protected void c() {
int i2;
synchronized (this.e) {
if (!this.e.isEmpty()) {
b bVar = this.h.get(this.e.poll());
if (bVar.getStatus() == DownloadableVideoItem.DownloadStatus.PENDING) {
bVar.a();
} else if (this.d > 0) {
i2 = this.d;
this.d = i2 - 1;
}
} else if (this.d > 0) {
i2 = this.d;
this.d = i2 - 1;
}
}
}
public void changeMaxDownloadingItems(int i2) {
if (i2 <= 0 || i2 > 10) {
Log.e("VideoDownloadManager", "changeMaxDownloadingItems, maxItems should be 0<x<100");
} else {
c = i2;
}
}
protected String d() {
return this.b;
}
public void deleteDownloader(String str) {
b bVar = this.h.get(str);
if (bVar == null) {
Log.e("VideoDownloadManager", "deleteDownloader but there is no downloader for url=" + str);
return;
}
if (bVar.getStatus() == DownloadableVideoItem.DownloadStatus.PENDING) {
b(str);
}
bVar.c();
this.h.remove(str);
}
protected String e() {
return "__cyberplayer_dl_" + d();
}
public HashMap<String, DownloadableVideoItem> getAllDownloadableVideoItems() {
HashMap<String, DownloadableVideoItem> hashMap = new HashMap<>();
hashMap.putAll(this.h);
return hashMap;
}
public String getDownloadRootForCurrentUser() {
File externalFilesDir = this.f.getExternalFilesDir(null);
if (externalFilesDir == null) {
return null;
}
return externalFilesDir.getAbsolutePath() + "/cyberplayer_download_videos/" + d() + "/";
}
public DownloadableVideoItem getDownloadableVideoItemByUrl(String str) {
return this.h.get(str);
}
public String getUserName() {
return this.a;
}
public void pauseDownloader(String str) {
b bVar = this.h.get(str);
if (bVar != null) {
if (bVar.getStatus() == DownloadableVideoItem.DownloadStatus.PENDING) {
b(str);
}
bVar.b();
} else {
Log.e("VideoDownloadManager", "pauseDownloader but there is no downloader for url=" + str);
}
}
public void setCustomizedPlayerId(String str) {
this.g = str;
}
public void startOrResumeDownloader(String str, DownloadObserver downloadObserver) {
startOrResumeDownloaderWithToken(str, null, downloadObserver);
}
public void startOrResumeDownloaderWithToken(String str, String str2, DownloadObserver downloadObserver) {
String str3;
if (str == null) {
Log.e("VideoDownloadManager", "url is null");
return;
}
b bVar = this.h.get(str);
if (bVar == null) {
String b = a.b(str);
String downloadRootForCurrentUser = getDownloadRootForCurrentUser();
if (downloadRootForCurrentUser != null) {
str3 = downloadRootForCurrentUser + b + "/";
} else {
str3 = null;
}
bVar = new b(this.f, str, b, str3, b + ".m3u8", e());
this.h.put(str, bVar);
}
if (downloadObserver != null) {
bVar.addObserver(downloadObserver);
}
if (str2 != null && !str2.equals("")) {
bVar.a(str2);
}
if (a(str)) {
bVar.a();
} else {
bVar.a(DownloadableVideoItem.DownloadStatus.PENDING);
Log.w("VideoDownloadManager", "startOrResumeDownloader: too many tasks are downloading , this task is suspending now(will download automatically after other task down)");
}
}
public void stopAll() {
try {
Iterator<Map.Entry<String, b>> it = this.h.entrySet().iterator();
while (it.hasNext()) {
it.next().getValue().b();
}
} catch (Exception e) {
Log.d("VideoDownloadManager", "" + e.getMessage());
}
}
}

View File

@@ -0,0 +1,255 @@
package com.baidu.cloud.media.download;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/* loaded from: classes.dex */
final class a {
/* JADX WARN: Can't wrap try/catch for region: R(22:28|29|(1:31)|32|(1:34)|35|(1:37)|38|39|40|41|(2:42|(1:44)(1:45))|46|(2:48|(10:50|(1:52)|53|54|55|56|57|58|(2:61|62)|60)(1:70))(1:72)|71|54|55|56|57|58|(0)|60) */
/* JADX WARN: Multi-variable type inference failed */
/* JADX WARN: Removed duplicated region for block: B:105:0x015d A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:109:0x0156 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:113:0x014f A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:117:0x0129 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:125:0x0172 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:131:? A[SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:132:0x016b A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:136:0x0164 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:61:0x00eb A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:88:0x0147 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:92:0x0140 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:96:0x0139 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Type inference failed for: r11v10 */
/* JADX WARN: Type inference failed for: r11v11 */
/* JADX WARN: Type inference failed for: r11v2, types: [java.io.File] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public static com.baidu.cloud.media.download.c.b a(java.lang.String r16, java.lang.String r17) {
/*
Method dump skipped, instructions count: 374
To view this dump change 'Code comments level' option to 'DEBUG'
*/
throw new UnsupportedOperationException("Method not decompiled: com.baidu.cloud.media.download.a.a(java.lang.String, java.lang.String):com.baidu.cloud.media.download.c$b");
}
/* JADX WARN: Code restructure failed: missing block: B:63:0x006a, code lost:
r5.disconnect();
*/
/* JADX WARN: Removed duplicated region for block: B:48:0x0098 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:54:? A[SYNTHETIC] */
/* JADX WARN: Removed duplicated region for block: B:55:0x0091 A[EXC_TOP_SPLITTER, SYNTHETIC] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct code enable 'Show inconsistent code' option in preferences
*/
public static java.lang.String a(java.lang.String r5) {
/*
java.lang.StringBuilder r0 = new java.lang.StringBuilder
r0.<init>()
r1 = 0
java.net.URL r2 = new java.net.URL // Catch: java.lang.Throwable -> L73 java.lang.Exception -> L76
r2.<init>(r5) // Catch: java.lang.Throwable -> L73 java.lang.Exception -> L76
java.net.URLConnection r5 = r2.openConnection() // Catch: java.lang.Throwable -> L73 java.lang.Exception -> L76
java.net.HttpURLConnection r5 = (java.net.HttpURLConnection) r5 // Catch: java.lang.Throwable -> L73 java.lang.Exception -> L76
r2 = 30000(0x7530, float:4.2039E-41)
r5.setConnectTimeout(r2) // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
r5.setReadTimeout(r2) // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
r5.connect() // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
int r2 = r5.getResponseCode() // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
int r2 = r2 / 100
r3 = 2
if (r2 != r3) goto L68
int r2 = r5.getContentLength() // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
r3 = 5242880(0x500000, float:7.34684E-39)
if (r2 <= r3) goto L2e
goto L68
L2e:
java.io.BufferedReader r2 = new java.io.BufferedReader // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
java.io.InputStreamReader r3 = new java.io.InputStreamReader // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
java.io.InputStream r4 = r5.getInputStream() // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
r3.<init>(r4) // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
r2.<init>(r3) // Catch: java.lang.Throwable -> L6e java.lang.Exception -> L70
L3c:
java.lang.String r3 = r2.readLine() // Catch: java.lang.Exception -> L66 java.lang.Throwable -> L8d
if (r3 == 0) goto L57
java.lang.StringBuilder r4 = new java.lang.StringBuilder // Catch: java.lang.Exception -> L66 java.lang.Throwable -> L8d
r4.<init>() // Catch: java.lang.Exception -> L66 java.lang.Throwable -> L8d
r4.append(r3) // Catch: java.lang.Exception -> L66 java.lang.Throwable -> L8d
java.lang.String r3 = "\n"
r4.append(r3) // Catch: java.lang.Exception -> L66 java.lang.Throwable -> L8d
java.lang.String r3 = r4.toString() // Catch: java.lang.Exception -> L66 java.lang.Throwable -> L8d
r0.append(r3) // Catch: java.lang.Exception -> L66 java.lang.Throwable -> L8d
goto L3c
L57:
java.lang.String r0 = r0.toString() // Catch: java.lang.Exception -> L66 java.lang.Throwable -> L8d
r2.close() // Catch: java.lang.Exception -> L5f
goto L60
L5f:
L60:
if (r5 == 0) goto L65
r5.disconnect() // Catch: java.lang.Exception -> L65
L65:
return r0
L66:
r0 = move-exception
goto L79
L68:
if (r5 == 0) goto L6d
r5.disconnect() // Catch: java.lang.Exception -> L6d
L6d:
return r1
L6e:
r0 = move-exception
goto L8f
L70:
r0 = move-exception
r2 = r1
goto L79
L73:
r0 = move-exception
r5 = r1
goto L8f
L76:
r0 = move-exception
r5 = r1
r2 = r5
L79:
java.lang.String r3 = "DownloadUtils"
java.lang.String r4 = ""
android.util.Log.d(r3, r4, r0) // Catch: java.lang.Throwable -> L8d
if (r2 == 0) goto L87
r2.close() // Catch: java.lang.Exception -> L86
goto L87
L86:
L87:
if (r5 == 0) goto L8c
r5.disconnect() // Catch: java.lang.Exception -> L8c
L8c:
return r1
L8d:
r0 = move-exception
r1 = r2
L8f:
if (r1 == 0) goto L96
r1.close() // Catch: java.lang.Exception -> L95
goto L96
L95:
L96:
if (r5 == 0) goto L9b
r5.disconnect() // Catch: java.lang.Exception -> L9b
L9b:
throw r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.baidu.cloud.media.download.a.a(java.lang.String):java.lang.String");
}
public static boolean a(Context context) {
NetworkInfo[] allNetworkInfo;
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
if (connectivityManager != null && (allNetworkInfo = connectivityManager.getAllNetworkInfo()) != null && allNetworkInfo.length > 0) {
for (NetworkInfo networkInfo : allNetworkInfo) {
if (networkInfo.getState() == NetworkInfo.State.CONNECTED) {
return true;
}
}
}
return false;
}
public static boolean a(byte[] bArr, String str) {
File file;
FileOutputStream fileOutputStream = null;
try {
try {
file = new File(str);
try {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
if (file.exists()) {
file.delete();
}
file.createNewFile();
FileOutputStream fileOutputStream2 = new FileOutputStream(file);
try {
fileOutputStream2.write(bArr);
fileOutputStream2.flush();
fileOutputStream2.close();
try {
fileOutputStream2.close();
} catch (IOException e) {
Log.d("DownloadUtils", "" + e.getMessage());
}
return true;
} catch (Exception e2) {
e = e2;
fileOutputStream = fileOutputStream2;
Log.d("DownloadUtils", "" + Log.getStackTraceString(e));
if (file != null && file.exists()) {
file.delete();
}
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e3) {
Log.d("DownloadUtils", "" + e3.getMessage());
}
}
return false;
} catch (Throwable th) {
th = th;
fileOutputStream = fileOutputStream2;
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e4) {
Log.d("DownloadUtils", "" + e4.getMessage());
}
}
throw th;
}
} catch (Exception e5) {
e = e5;
}
} catch (Throwable th2) {
th = th2;
}
} catch (Exception e6) {
e = e6;
file = null;
}
}
public static String b(String str) {
byte[] bytes = str.getBytes();
char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(bytes);
byte[] digest = messageDigest.digest();
char[] cArr2 = new char[32];
int i = 0;
for (int i2 = 0; i2 < 16; i2++) {
byte b = digest[i2];
int i3 = i + 1;
cArr2[i] = cArr[(b >>> 4) & 15];
i = i3 + 1;
cArr2[i3] = cArr[b & 15];
}
return new String(cArr2);
} catch (NoSuchAlgorithmException e) {
Log.e("DownloadUtils", "", e);
return null;
}
}
}

View File

@@ -0,0 +1,464 @@
package com.baidu.cloud.media.download;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.util.Log;
import com.baidu.cloud.media.download.DownloadableVideoItem;
import com.baidu.cloud.media.download.c;
import com.baidu.cloud.media.download.d;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.json.JSONObject;
/* loaded from: classes.dex */
class b extends DownloadableVideoItem {
private volatile boolean m;
private ArrayList<String> n;
private String o;
private String p;
private Context q;
private ExecutorService k = null;
private volatile int l = 0;
private String r = null;
public b(Context context, String str, String str2, String str3, String str4, String str5) {
this.o = "";
this.p = "";
this.q = context;
this.b = str;
this.o = str2;
this.c = str3;
this.d = str4;
this.p = str5;
}
public static b a(Context context, String str, JSONObject jSONObject) {
b bVar;
try {
String string = jSONObject.getString("url");
String string2 = jSONObject.getString("urle");
String optString = jSONObject.optString("fold", null);
String string3 = jSONObject.getString("file");
int i = jSONObject.getInt("st");
int i2 = jSONObject.getInt("prgr");
int i3 = jSONObject.getInt("tsdl");
bVar = new b(context, string, string2, optString, string3, str);
try {
bVar.a(i, i2, i3);
} catch (Exception e) {
e = e;
Log.e("HLSVideoDownloader", "" + Log.getStackTraceString(e));
return bVar;
}
} catch (Exception e2) {
e = e2;
bVar = null;
}
return bVar;
}
/* JADX INFO: Access modifiers changed from: private */
public void a(c.a aVar) {
if (this.l >= this.n.size()) {
i();
return;
}
c cVar = new c(this.n.get(this.l), this.c + "/" + (this.l + 1) + ".ts", aVar);
ExecutorService executorService = this.k;
if (executorService == null || executorService.isShutdown()) {
Log.d("HLSVideoDownloader", "new executor is created now");
this.k = Executors.newSingleThreadExecutor();
}
this.k.execute(cVar);
}
private void d() {
try {
if (!new URL(this.b).getPath().endsWith(".m3u8")) {
this.i = "only download m3u8 video";
this.j = 1;
a(DownloadableVideoItem.DownloadStatus.ERROR);
return;
}
String str = this.c;
if (str == null || str.equals("")) {
String downloadRootForCurrentUser = VideoDownloadManager.b().getDownloadRootForCurrentUser();
if (downloadRootForCurrentUser == null) {
this.i = "sdcard is unmounted";
this.j = 3;
a(DownloadableVideoItem.DownloadStatus.ERROR);
return;
} else {
this.c = downloadRootForCurrentUser + this.o + "/";
}
}
if (!this.m) {
if (!g()) {
if (!e()) {
a(DownloadableVideoItem.DownloadStatus.ERROR);
return;
}
Runnable runnable = new Runnable() { // from class: com.baidu.cloud.media.download.b.1
@Override // java.lang.Runnable
public void run() {
d.a aVar = new d.a() { // from class: com.baidu.cloud.media.download.b.1.1
@Override // com.baidu.cloud.media.download.d.a
public void a(int i) {
if (b.this.h == DownloadableVideoItem.DownloadStatus.DOWNLOADING) {
Log.d("HLSVideoDownloader", "Parse failed: error code is " + i);
b.this.i = "parse M3U8 failed, reason = " + DownloadableVideoItem.a[i];
b bVar = b.this;
bVar.j = i;
bVar.a(DownloadableVideoItem.DownloadStatus.ERROR);
}
}
@Override // com.baidu.cloud.media.download.d.a
public void a(List<String> list) {
if (b.this.h == DownloadableVideoItem.DownloadStatus.DOWNLOADING) {
b.this.n = (ArrayList) list;
b.this.f();
b.this.m = true;
b.this.h();
}
}
};
d dVar = new d(b.this.q, b.this.c + "/" + b.this.d);
b bVar = b.this;
dVar.a(bVar.b, bVar.r, aVar);
}
};
ExecutorService executorService = this.k;
if (executorService == null || executorService.isShutdown()) {
Log.d("HLSVideoDownloader", "new executor is created now to download m3u8 file");
this.k = Executors.newSingleThreadExecutor();
}
this.k.execute(runnable);
return;
}
this.m = true;
}
h();
} catch (Exception e) {
Log.d("HLSVideoDownloader", "" + e.getMessage());
this.i = "url format is invalid";
this.j = 1;
a(DownloadableVideoItem.DownloadStatus.ERROR);
}
}
static /* synthetic */ int e(b bVar) {
int i = bVar.l;
bVar.l = i + 1;
return i;
}
private boolean e() {
boolean z = true;
try {
if (!"mounted".equals(Environment.getExternalStorageState())) {
this.i = "save file failed, sdcard unmounted";
this.j = 3;
z = false;
}
if (a.a(this.q)) {
return z;
}
this.i = "network is not available";
this.j = 2;
return false;
} catch (Exception e) {
Log.d("HLSVideoDownloader", "checkEnvironment " + e.getMessage());
return z;
}
}
/* JADX INFO: Access modifiers changed from: private */
/* JADX WARN: Multi-variable type inference failed */
public void f() {
ArrayList<String> arrayList = this.n;
if (arrayList == null || arrayList.size() <= 0) {
return;
}
FileOutputStream fileOutputStream = null;
fileOutputStream = null;
try {
try {
try {
FileOutputStream fileOutputStream2 = new FileOutputStream(this.c + "/tsdl.data");
try {
ObjectOutputStream objectOutputStream = new ObjectOutputStream(fileOutputStream2);
objectOutputStream.writeObject(this.n);
fileOutputStream2.close();
fileOutputStream = objectOutputStream;
} catch (Exception e) {
e = e;
fileOutputStream = fileOutputStream2;
Log.d("HLSVideoDownloader", "" + e.getMessage());
if (fileOutputStream != null) {
fileOutputStream.close();
fileOutputStream = fileOutputStream;
}
} catch (Throwable th) {
th = th;
fileOutputStream = fileOutputStream2;
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException unused) {
}
}
throw th;
}
} catch (Exception e2) {
e = e2;
}
} catch (IOException unused2) {
}
} catch (Throwable th2) {
th = th2;
}
}
private boolean g() {
if (!new File(this.c + "/" + this.d).exists()) {
return false;
}
if (this.n != null) {
return true;
}
FileInputStream fileInputStream = null;
try {
try {
FileInputStream fileInputStream2 = new FileInputStream(this.c + "/tsdl.data");
try {
this.n = (ArrayList) new ObjectInputStream(fileInputStream2).readObject();
try {
fileInputStream2.close();
return true;
} catch (IOException unused) {
return true;
}
} catch (Exception e) {
e = e;
fileInputStream = fileInputStream2;
Log.d("HLSVideoDownloader", "" + e.getMessage());
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException unused2) {
}
}
return false;
} catch (Throwable th) {
th = th;
fileInputStream = fileInputStream2;
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException unused3) {
}
}
throw th;
}
} catch (Throwable th2) {
th = th2;
}
} catch (Exception e2) {
e = e2;
}
}
/* JADX INFO: Access modifiers changed from: private */
public void h() {
ArrayList<String> arrayList = this.n;
if (arrayList == null || arrayList.size() == 0) {
this.i = "tsList.size == 0";
this.j = 4;
a(DownloadableVideoItem.DownloadStatus.ERROR);
} else if (e()) {
a(new c.a() { // from class: com.baidu.cloud.media.download.b.2
@Override // com.baidu.cloud.media.download.c.a
public void a(int i, int i2, int i3) {
b bVar;
int i4;
if (i == 1) {
if (b.this.h == DownloadableVideoItem.DownloadStatus.PAUSED || b.this.h == DownloadableVideoItem.DownloadStatus.DELETED) {
return;
}
b.e(b.this);
b.this.a(i2, i3);
b.this.a(this);
return;
}
if (b.this.h == DownloadableVideoItem.DownloadStatus.PAUSED || b.this.h == DownloadableVideoItem.DownloadStatus.DELETED) {
return;
}
if (i == -2) {
bVar = b.this;
bVar.i = "network has problem";
i4 = 2;
} else {
b.this.i = "save the " + b.this.l + "th ts file - interrupted";
bVar = b.this;
i4 = 7;
}
bVar.j = i4;
b.this.a(DownloadableVideoItem.DownloadStatus.ERROR);
}
});
} else {
a(DownloadableVideoItem.DownloadStatus.ERROR);
}
}
private void i() {
a(DownloadableVideoItem.DownloadStatus.COMPLETED);
}
private void j() {
String k;
if (this.h == DownloadableVideoItem.DownloadStatus.DELETED || (k = k()) == null) {
return;
}
SharedPreferences.Editor edit = this.q.getSharedPreferences(this.p, 0).edit();
edit.putString(this.o, k);
if (Build.VERSION.SDK_INT >= 9) {
edit.apply();
} else {
edit.commit();
}
}
private String k() {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("url", this.b);
jSONObject.put("fold", this.c);
jSONObject.put("file", this.d);
jSONObject.put("st", this.h.getCode());
jSONObject.put("prgr", this.e);
jSONObject.put("tsdl", this.l);
return jSONObject.toString();
} catch (Exception e) {
Log.e("HLSVideoDownloader", "" + e.getMessage());
return null;
}
}
protected void a(int i, int i2) {
ArrayList<String> arrayList;
if (this.h == DownloadableVideoItem.DownloadStatus.DOWNLOADING && (arrayList = this.n) != null && arrayList.size() > 0) {
this.e = Math.round((this.l / this.n.size()) * 10000.0f);
this.f = i;
this.g += i2;
}
j();
setChanged();
notifyObservers();
}
protected void a(int i, int i2, int i3) {
this.e = i2;
this.l = i3;
DownloadableVideoItem.DownloadStatus downloadStatus = DownloadableVideoItem.DownloadStatus.values()[i];
if (downloadStatus == DownloadableVideoItem.DownloadStatus.DOWNLOADING || downloadStatus == DownloadableVideoItem.DownloadStatus.PENDING) {
downloadStatus = DownloadableVideoItem.DownloadStatus.PAUSED;
}
this.h = downloadStatus;
}
protected void a(DownloadableVideoItem.DownloadStatus downloadStatus) {
VideoDownloadManager b;
DownloadableVideoItem.DownloadStatus downloadStatus2 = this.h;
DownloadableVideoItem.DownloadStatus downloadStatus3 = DownloadableVideoItem.DownloadStatus.DOWNLOADING;
if (downloadStatus2 == downloadStatus3 && downloadStatus != downloadStatus3 && (b = VideoDownloadManager.b()) != null) {
b.c();
}
this.h = downloadStatus;
if (downloadStatus != DownloadableVideoItem.DownloadStatus.PAUSED && downloadStatus != DownloadableVideoItem.DownloadStatus.ERROR) {
this.i = "";
}
if (downloadStatus != DownloadableVideoItem.DownloadStatus.ERROR) {
this.j = 0;
}
a(0, 0);
}
public void a(String str) {
this.r = str;
}
public boolean a() {
DownloadableVideoItem.DownloadStatus downloadStatus = this.h;
DownloadableVideoItem.DownloadStatus downloadStatus2 = DownloadableVideoItem.DownloadStatus.DOWNLOADING;
if (downloadStatus != downloadStatus2) {
a(downloadStatus2);
d();
return true;
}
Log.e("HLSVideoDownloader", "start failed because downloadStatus = " + this.h.name());
return false;
}
public boolean b() {
if (this.h == DownloadableVideoItem.DownloadStatus.PAUSED || this.h == DownloadableVideoItem.DownloadStatus.COMPLETED || this.h == DownloadableVideoItem.DownloadStatus.DELETED) {
Log.e("HLSVideoDownloader", "pause not work, && downloadStatus = " + this.h.name());
return false;
}
ExecutorService executorService = this.k;
if (executorService != null && !executorService.isShutdown()) {
this.k.shutdownNow();
}
this.i = "manually pause";
a(DownloadableVideoItem.DownloadStatus.PAUSED);
return true;
}
public boolean c() {
try {
a(DownloadableVideoItem.DownloadStatus.DELETED);
if (this.k != null && !this.k.isTerminated() && !this.k.isShutdown()) {
this.k.shutdownNow();
}
SharedPreferences.Editor edit = this.q.getSharedPreferences(this.p, 0).edit();
edit.remove(this.o);
if (Build.VERSION.SDK_INT >= 9) {
edit.apply();
} else {
edit.commit();
}
if (this.c != null) {
File file = new File(this.c);
if (file.exists() && file.isDirectory()) {
File[] listFiles = file.listFiles();
for (int i = 0; i < listFiles.length; i++) {
if (listFiles[i].isFile()) {
listFiles[i].delete();
}
}
}
}
this.c = "";
this.d = "";
this.e = 0;
this.j = 0;
this.i = "delete manually";
return true;
} catch (Exception e) {
Log.e("HLSVideoDownloader", "" + e.getMessage());
return true;
}
}
}

View File

@@ -0,0 +1,33 @@
package com.baidu.cloud.media.download;
/* loaded from: classes.dex */
class c implements Runnable {
String a;
String b;
a c;
public static abstract class a {
public abstract void a(int i, int i2, int i3);
}
static class b {
int a;
int b;
int c;
b() {
}
}
public c(String str, String str2, a aVar) {
this.a = str;
this.b = str2;
this.c = aVar;
}
@Override // java.lang.Runnable
public void run() {
b a2 = com.baidu.cloud.media.download.a.a(this.a, this.b);
this.c.a(a2.a, a2.b, a2.c);
}
}

View File

@@ -0,0 +1,222 @@
package com.baidu.cloud.media.download;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import org.json.JSONObject;
/* loaded from: classes.dex */
final class d {
private String a;
private List<String> b;
private a c;
private Context d;
private String f;
private String e = null;
private String g = null;
public static abstract class a {
public abstract void a(int i);
public abstract void a(List<String> list);
}
public d(Context context, String str) {
this.a = "";
this.b = null;
this.c = null;
this.d = context.getApplicationContext();
this.f = str;
this.a = "";
this.b = new ArrayList();
this.c = null;
}
private long a(String str) {
try {
String[] split = str.split(":|=|,");
for (int i = 0; i < split.length; i++) {
if (split[i].trim().equals("BANDWIDTH")) {
return Long.parseLong(split[i + 1].trim());
}
}
return 0L;
} catch (Exception e) {
Log.d("M3U8Parser", "" + e.getMessage());
return 0L;
}
}
private void a() {
SharedPreferences.Editor edit = this.d.getSharedPreferences("__cyberplayer_dl_sec", 0).edit();
edit.putString(this.f, this.e);
if (Build.VERSION.SDK_INT >= 9) {
edit.apply();
} else {
edit.commit();
}
}
private void a(String str, List<String> list) {
String str2;
if (str == null || TextUtils.isEmpty(str)) {
this.c.a(1);
return;
}
Scanner scanner = new Scanner(str);
StringBuilder sb = new StringBuilder();
String str3 = null;
long j = 0;
String str4 = null;
boolean z = false;
boolean z2 = false;
while (true) {
try {
String str5 = "";
if (!scanner.hasNextLine()) {
scanner.close();
if (!z) {
if (this.e != null) {
a();
}
if (com.baidu.cloud.media.download.a.a(sb.toString().getBytes(), this.f)) {
this.c.a(this.b);
return;
} else {
this.c.a(5);
return;
}
}
this.b.clear();
if (!str3.startsWith("http://")) {
str5 = this.a;
}
a(com.baidu.cloud.media.download.a.a(str5 + str3), this.b);
return;
}
String nextLine = scanner.nextLine();
if (!z2 && !nextLine.startsWith("#EXTM3U")) {
scanner.close();
this.c.a(4);
return;
}
if (TextUtils.isEmpty(str4) || !str4.startsWith("#EXT-X-STREAM-INF:")) {
if (!TextUtils.isEmpty(str4) && str4.startsWith("#EXTINF:")) {
if (!nextLine.contains("://")) {
str5 = this.a;
}
if (nextLine.startsWith("/")) {
str5 = str5.substring(0, str5.indexOf("/", str5.indexOf("://") + 3));
} else if (nextLine.startsWith("../")) {
if (str5.endsWith("/")) {
str5 = str5.substring(0, str5.length() - 1);
}
str5 = str5.substring(0, str5.lastIndexOf("/") + 1);
nextLine = nextLine.substring(3);
}
list.add(str5 + nextLine);
str2 = String.valueOf(list.size()) + ".ts\n";
} else if (TextUtils.isEmpty(nextLine) || !nextLine.startsWith("#EXT-X-KEY:")) {
str2 = nextLine + "\n";
} else {
String b = b(nextLine);
if (b == null) {
scanner.close();
this.c.a(6);
return;
} else {
str2 = b + "\n";
}
}
sb.append(str2);
str4 = nextLine;
} else {
long a2 = a(str4);
if (a2 > j) {
str3 = nextLine;
} else {
a2 = j;
}
j = a2;
str4 = nextLine;
z = true;
}
z2 = true;
} catch (Exception e) {
Log.d("M3U8Parser", Log.getStackTraceString(e));
this.c.a(2);
return;
}
}
}
private String b(String str) {
String str2;
String str3 = null;
try {
boolean contains = str.contains("=media-drm-player-binding");
boolean contains2 = str.contains("=media-drm-safe-code");
boolean contains3 = str.contains("=media-drm-token");
if (!contains && !contains2 && !contains3) {
return str;
}
if (this.e == null) {
String substring = str.substring(str.indexOf("URI=\"") + 5);
String substring2 = substring.substring(0, substring.indexOf("\""));
String str4 = "pid-android-1";
try {
String a2 = VideoDownloadManager.b().a();
if (!TextUtils.isEmpty(a2)) {
str4 = a2;
}
} catch (Exception unused) {
}
String str5 = substring2 + "&playerId=" + str4;
if (contains3) {
str5 = str5 + "&token=" + this.g;
}
this.e = LocalHlsSec.bytes2HexStr(new LocalHlsSec().crypt(this.d, LocalHlsSec.hexStr2Bytes(new JSONObject(com.baidu.cloud.media.download.a.a(str5)).getString("encryptedVideoKey")), 0));
}
if (contains) {
str2 = "media-drm-player-binding";
} else if (contains2) {
str2 = "media-drm-safe-code";
} else {
if (!contains3) {
return str;
}
str2 = "media-drm-token";
}
try {
str = str.replace(str2, "media-drm-local-key");
return str;
} catch (Exception e) {
str3 = str;
e = e;
Log.d("M3U8Parser", "", e);
return str3;
}
} catch (Exception e2) {
e = e2;
}
}
public int a(String str, String str2, a aVar) {
if (TextUtils.isEmpty(str) || aVar == null) {
return 1;
}
this.g = str2;
this.c = aVar;
this.b.clear();
if (TextUtils.isEmpty(this.a)) {
this.a = str.substring(0, str.lastIndexOf(47) + 1);
}
a(com.baidu.cloud.media.download.a.a(str), this.b);
return 0;
}
}