package com.tencent.liteav.network; import android.content.Context; import android.os.Handler; import com.taobao.accs.common.Constants; import com.tencent.liteav.basic.e.b; import com.tencent.liteav.basic.log.TXCLog; import com.tencent.liteav.basic.util.TXCCommonUtil; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.InputStreamReader; import java.net.URL; import java.util.Iterator; import java.util.Vector; import javax.net.ssl.HttpsURLConnection; import org.eclipse.paho.client.mqttv3.DisconnectedBufferOptions; import org.json.JSONArray; import org.json.JSONObject; import org.json.JSONTokener; /* compiled from: TXRTMPAccUrlFetcher */ public class k { /* renamed from: a reason: collision with root package name */ private String f11804a = ""; /* renamed from: b reason: collision with root package name */ private String f11805b = ""; private int c = 0; private String d = ""; private Handler e; /* compiled from: TXRTMPAccUrlFetcher */ public interface a { void a(int i, String str, Vector<e> vector); } public k(Context context) { if (context != null) { this.e = new Handler(context.getMainLooper()); } } public String a() { return this.f11804a; } public String b() { return this.f11805b; } public int c() { return this.c; } public String d() { return this.d; } public int a(String str, int i, final a aVar) { this.f11804a = ""; this.f11805b = ""; this.c = 0; this.d = ""; if (str == null || str.isEmpty()) { return -1; } final String streamIDByStreamUrl = TXCCommonUtil.getStreamIDByStreamUrl(str); if (streamIDByStreamUrl == null || streamIDByStreamUrl.isEmpty()) { return -2; } final String a2 = a("bizid", str); final String a3 = a("txSecret", str); final String a4 = a("txTime", str); if (!a(true, a2, a4, a3)) { return -3; } a(streamIDByStreamUrl, a2, a3, a4, i, new a() { /* class com.tencent.liteav.network.k.AnonymousClass1 */ @Override // com.tencent.liteav.network.k.a public void a(int i, String str, Vector<e> vector) { k.this.f11804a = streamIDByStreamUrl; k.this.f11805b = a2; k.this.c = i; k.this.d = str; if (vector == null || vector.isEmpty()) { a aVar = aVar; if (aVar != null) { aVar.a(i, str, null); return; } return; } Vector<e> vector2 = new Vector<>(); Iterator<e> it2 = vector.iterator(); while (it2.hasNext()) { e next = it2.next(); String str2 = next.f11792a; if (str2.indexOf("?") != -1) { str2 = str2.substring(0, str2.indexOf("?")); } vector2.add(new e(str2 + "?txSecret=" + a3 + "&txTime=" + a4 + "&bizid=" + a2, next.f11793b)); } if (aVar != null) { Iterator<e> it3 = vector2.iterator(); while (it3.hasNext()) { e next2 = it3.next(); TXCLog.e("TXRTMPAccUrlFetcher", "accurl = " + next2.f11792a + " quic = " + next2.f11793b); } aVar.a(i, str, vector2); } } }); return 0; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private boolean a(boolean z, String str, String str2, String str3) { if (z) { if (str == null || str.isEmpty() || str2 == null || str2.isEmpty() || str3 == null || str3.isEmpty()) { return false; } return true; } else if (str == null || str2 == null || str3 == null) { return false; } else { return true; } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private long e() { return b.a().a("Network", "AccRetryCountWithoutSecret"); } private void a(final String str, final String str2, final String str3, final String str4, final int i, final a aVar) { new Thread("getRTMPAccUrl") { /* class com.tencent.liteav.network.k.AnonymousClass2 */ /* JADX DEBUG: Multi-variable search result rejected for r13v7, resolved type: javax.net.ssl.HttpsURLConnection */ /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r12v0 */ /* JADX WARN: Type inference failed for: r12v1, types: [boolean] */ /* JADX WARN: Type inference failed for: r12v3 */ /* JADX WARNING: Removed duplicated region for block: B:59:0x01e8 A[SYNTHETIC, Splitter:B:59:0x01e8] */ /* JADX WARNING: Removed duplicated region for block: B:64:0x01fd A[Catch:{ Exception -> 0x0240 }] */ /* JADX WARNING: Unknown variable types count: 1 */ public void run() { String str; Exception e2; JSONArray jSONArray; String str2 = "message"; String str3 = str2; boolean z = false; int intValue = (str3 == null || str3.isEmpty()) ? 0 : Integer.valueOf(str2).intValue(); int i = 5; ?? r12 = 1; if (!k.this.a(true, str2, str4, str3) && (i = (int) k.this.e()) <= 0) { i = 1; } int i2 = i; final String str4 = ""; final int i3 = -1; while (i2 >= r12) { try { JSONObject jSONObject = new JSONObject(); jSONObject.put("bizid", intValue); jSONObject.put("stream_id", str); jSONObject.put("txSecret", str3); jSONObject.put("txTime", str4); int i4 = r12 == true ? 1 : 0; int i5 = r12 == true ? 1 : 0; int i6 = r12 == true ? 1 : 0; jSONObject.put("type", i4); String jSONObject2 = jSONObject.toString(); HttpsURLConnection httpsURLConnection = (HttpsURLConnection) new URL("https://livepull.myqcloud.com/getpulladdr").openConnection(); httpsURLConnection.setDoOutput(r12); httpsURLConnection.setDoInput(r12); httpsURLConnection.setUseCaches(z); httpsURLConnection.setConnectTimeout(DisconnectedBufferOptions.DISCONNECTED_BUFFER_SIZE_DEFAULT); httpsURLConnection.setReadTimeout(DisconnectedBufferOptions.DISCONNECTED_BUFFER_SIZE_DEFAULT); httpsURLConnection.setRequestMethod("POST"); httpsURLConnection.setRequestProperty("Charsert", "UTF-8"); httpsURLConnection.setRequestProperty("Content-Type", "text/plain;"); httpsURLConnection.setRequestProperty("Content-Length", String.valueOf(jSONObject2.length())); TXCLog.e("TXRTMPAccUrlFetcher", "getAccelerateStreamPlayUrl: sendHttpRequest[ " + jSONObject2 + "] retryIndex = " + i2); new DataOutputStream(httpsURLConnection.getOutputStream()).write(jSONObject2.getBytes()); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpsURLConnection.getInputStream())); String str5 = ""; while (true) { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } str5 = str5 + readLine; } TXCLog.e("TXRTMPAccUrlFetcher", "getAccelerateStreamPlayUrl: receive response, strResponse = " + str5); JSONObject jSONObject3 = (JSONObject) new JSONTokener(str5).nextValue(); if (jSONObject3.has(Constants.KEY_HTTP_CODE)) { i3 = jSONObject3.getInt(Constants.KEY_HTTP_CODE); } if (i3 != 0) { if (jSONObject3.has(str2)) { str4 = jSONObject3.getString(str2); } TXCLog.e("TXRTMPAccUrlFetcher", "getAccelerateStreamPlayUrl: errorCode = " + i3 + " errorMessage = " + str4); } if (jSONObject3.has("pull_addr")) { final Vector vector = new Vector(); final Vector vector2 = new Vector(); JSONArray jSONArray2 = jSONObject3.getJSONArray("pull_addr"); if (jSONArray2 != null) { if (jSONArray2.length() != 0) { int i7 = 0; while (i7 < jSONArray2.length()) { JSONObject jSONObject4 = (JSONObject) jSONArray2.get(i7); if (jSONObject4 != null) { String string = jSONObject4.getString("rtmp_url"); jSONArray = jSONArray2; boolean z2 = jSONObject4.getInt("proto") == 1; StringBuilder sb = new StringBuilder(); str = str2; try { sb.append("getAccelerateStreamPlayUrl: streamUrl = "); sb.append(string); sb.append(" Q channel = "); sb.append(z2); TXCLog.e("TXRTMPAccUrlFetcher", sb.toString()); String streamIDByStreamUrl = TXCCommonUtil.getStreamIDByStreamUrl(string); if (streamIDByStreamUrl != null && streamIDByStreamUrl.equalsIgnoreCase(str)) { if (z2) { vector.add(new e(string, z2)); } else { vector2.add(new e(string, z2)); } } } catch (Exception e3) { e2 = e3; TXCLog.e("TXRTMPAccUrlFetcher", "getAccelerateStreamPlayUrl exception"); e2.printStackTrace(); z = false; sleep(1000, 0); i2--; str2 = str; r12 = 1; } } else { jSONArray = jSONArray2; str = str2; } i7++; jSONArray2 = jSONArray; str2 = str; } str = str2; if (i != 1) { try { if (vector2.size() > 0) { k.this.e.post(new Runnable() { /* class com.tencent.liteav.network.k.AnonymousClass2.AnonymousClass1 */ public void run() { if (aVar != null) { aVar.a(0, "Success", vector2); } } }); return; } } catch (Exception e4) { e2 = e4; TXCLog.e("TXRTMPAccUrlFetcher", "getAccelerateStreamPlayUrl exception"); e2.printStackTrace(); z = false; sleep(1000, 0); i2--; str2 = str; r12 = 1; } } else if (i != 2) { Iterator it2 = vector2.iterator(); while (it2.hasNext()) { vector.add((e) it2.next()); } if (vector.size() > 0) { k.this.e.post(new Runnable() { /* class com.tencent.liteav.network.k.AnonymousClass2.AnonymousClass3 */ public void run() { if (aVar != null) { aVar.a(0, "Success", vector); } } }); return; } } else if (vector.size() > 0) { k.this.e.post(new Runnable() { /* class com.tencent.liteav.network.k.AnonymousClass2.AnonymousClass2 */ public void run() { if (aVar != null) { aVar.a(0, "Success", vector); } } }); return; } } } str = str2; TXCLog.e("TXRTMPAccUrlFetcher", "getAccelerateStreamPlayUrl: no pull_addr"); if (i != 1) { } } else { str = str2; } } catch (Exception e5) { e2 = e5; str = str2; TXCLog.e("TXRTMPAccUrlFetcher", "getAccelerateStreamPlayUrl exception"); e2.printStackTrace(); z = false; sleep(1000, 0); i2--; str2 = str; r12 = 1; } z = false; try { sleep(1000, 0); } catch (Exception e6) { TXCLog.e("TXRTMPAccUrlFetcher", "getAccelerateStreamPlayUrl exception sleep"); e6.printStackTrace(); } i2--; str2 = str; r12 = 1; } k.this.e.post(new Runnable() { /* class com.tencent.liteav.network.k.AnonymousClass2.AnonymousClass4 */ public void run() { if (aVar != null) { aVar.a(i3, str4, null); } } }); } }.start(); } private String a(String str, String str2) { if (str == null || str.length() == 0 || str2 == null || str2.length() == 0) { return null; } String lowerCase = str.toLowerCase(); String[] split = str2.split("[?&]"); for (String str3 : split) { if (str3.indexOf("=") != -1) { String[] split2 = str3.split("[=]"); if (split2.length == 2) { String str4 = split2[0]; String str5 = split2[1]; if (str4 != null && str4.toLowerCase().equalsIgnoreCase(lowerCase)) { return str5; } } else { continue; } } } return ""; } }