package d3;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import x4.AbstractC3251q;

/* JADX INFO: renamed from: d3.l, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC1901l {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final S4.m f15771a = new S4.m("<\\s*/?[a-zA-Z]");

    public static String a(String str) throws Throwable {
        Throwable th;
        HttpURLConnection httpURLConnection;
        try {
            URLConnection uRLConnectionOpenConnection = new URL(str).openConnection();
            kotlin.jvm.internal.o.f(uRLConnectionOpenConnection, "null cannot be cast to non-null type java.net.HttpURLConnection");
            httpURLConnection = (HttpURLConnection) uRLConnectionOpenConnection;
            try {
                httpURLConnection.setRequestMethod("GET");
                httpURLConnection.setRequestProperty("User-Agent", "DebridStream/1.0 (Android)");
                httpURLConnection.setConnectTimeout(15000);
                httpURLConnection.setReadTimeout(15000);
                httpURLConnection.setInstanceFollowRedirects(true);
                InputStream inputStream = httpURLConnection.getInputStream();
                kotlin.jvm.internal.o.g(inputStream, "getInputStream(...)");
                BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, S4.a.f6257a), 8192);
                try {
                    String strP = A4.g.P(bufferedReader);
                    bufferedReader.close();
                    httpURLConnection.disconnect();
                    return strP;
                } finally {
                }
            } catch (Exception unused) {
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                return null;
            } catch (Throwable th2) {
                th = th2;
                if (httpURLConnection != null) {
                    httpURLConnection.disconnect();
                }
                throw th;
            }
        } catch (Exception unused2) {
            httpURLConnection = null;
        } catch (Throwable th3) {
            th = th3;
            httpURLConnection = null;
        }
    }

    public static ArrayList b(String str) {
        ArrayList arrayList = new ArrayList();
        List listD1 = S4.p.d1(S4.w.y0(S4.w.y0(str, "\r\n", "\n"), "\r", "\n"), new String[]{"\n\n"}, 6);
        Pattern patternCompile = Pattern.compile("(\\d{2}):(\\d{2}):(\\d{2})[,.](\\d{3})\\s*-->\\s*(\\d{2}):(\\d{2}):(\\d{2})[,.](\\d{3})");
        kotlin.jvm.internal.o.g(patternCompile, "compile(...)");
        Iterator it = listD1.iterator();
        while (it.hasNext()) {
            String string = S4.p.o1((String) it.next()).toString();
            kotlin.jvm.internal.o.h(string, "<this>");
            List listD0 = R4.n.d0(new H4.f(string, 4));
            if (!listD0.isEmpty()) {
                int size = listD0.size();
                int i6 = 0;
                while (true) {
                    if (i6 < size) {
                        CharSequence input = (CharSequence) listD0.get(i6);
                        kotlin.jvm.internal.o.h(input, "input");
                        Matcher matcher = patternCompile.matcher(input);
                        kotlin.jvm.internal.o.g(matcher, "matcher(...)");
                        S4.k kVar = !matcher.find(0) ? null : new S4.k(matcher, input);
                        if (kVar != null) {
                            arrayList.add(new w4.q(Long.valueOf(c((String) ((S4.j) kVar.a()).get(1), (String) ((S4.j) kVar.a()).get(2), (String) ((S4.j) kVar.a()).get(3), (String) ((S4.j) kVar.a()).get(4))), Long.valueOf(c((String) ((S4.j) kVar.a()).get(5), (String) ((S4.j) kVar.a()).get(6), (String) ((S4.j) kVar.a()).get(7), (String) ((S4.j) kVar.a()).get(8))), S4.p.o1(AbstractC3251q.m0(AbstractC3251q.a0(listD0, i6 + 1), "\n", null, null, null, 62)).toString()));
                            break;
                        }
                        i6++;
                    }
                }
            }
        }
        return arrayList;
    }

    public static long c(String str, String str2, String str3, String str4) {
        return Long.parseLong(str4) + TimeUnit.SECONDS.toMillis(Long.parseLong(str3)) + TimeUnit.MINUTES.toMillis(Long.parseLong(str2)) + TimeUnit.HOURS.toMillis(Long.parseLong(str));
    }
}
