package f6;

import android.content.Context;
import androidx.media3.exoplayer.hls.playlist.HlsMediaPlaylist;
import androidx.recyclerview.widget.d;
import com.bykv.vk.openvk.fm.fm.fm.lb.lb;
import com.bytedance.sdk.component.ro.fm.duv;
import com.bytedance.sdk.component.ro.fm.ku;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import nb.g;
import v5.c;

/* JADX INFO: loaded from: classes.dex */
public final class b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f25944a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final lb f25945b;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final File f25947d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final File f25948e;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public volatile boolean f25946c = false;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final ArrayList f25949f = new ArrayList();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public volatile boolean f25950g = false;

    public b(Context context, lb lbVar) {
        this.f25947d = null;
        this.f25948e = null;
        this.f25944a = context;
        this.f25945b = lbVar;
        this.f25947d = g.O(lbVar.jnr(), lbVar.qhl());
        this.f25948e = g.J(lbVar.jnr(), lbVar.qhl());
    }

    public static void b(b bVar, lb lbVar, int i10, String str) {
        bVar.getClass();
        synchronized (y5.a.class) {
            try {
                for (y5.a aVar : bVar.f25949f) {
                    if (aVar != null) {
                        aVar.fm(lbVar, i10, str);
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public static void c(b bVar, Closeable closeable) {
        bVar.getClass();
        if (closeable != null) {
            try {
                closeable.close();
            } catch (Exception unused) {
            }
        }
    }

    public static void e(b bVar) {
        File file = bVar.f25947d;
        File file2 = bVar.f25948e;
        try {
            if (file.renameTo(file2)) {
                return;
            }
            throw new IOException("Error renaming file " + file + " to " + file2 + " for completion!");
        } catch (Throwable th) {
            th.getMessage();
        }
    }

    public final void a(lb lbVar, int i10) {
        synchronized (y5.a.class) {
            try {
                for (y5.a aVar : this.f25949f) {
                    if (aVar != null) {
                        aVar.fm(lbVar, i10);
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:23:0x0049, code lost:
    
        if (r1.length() >= r13.yz()) goto L24;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void d(y5.a aVar) {
        if (this.f25950g) {
            synchronized (y5.a.class) {
                this.f25949f.add(aVar);
            }
            return;
        }
        this.f25949f.add(aVar);
        int i10 = 1;
        if (!this.f25948e.exists()) {
            lb lbVar = this.f25945b;
            if (!lbVar.dsz()) {
                File file = this.f25947d;
                if (file.length() < lbVar.ajl()) {
                    if (lbVar.yz() > 0) {
                    }
                }
            }
            this.f25950g = true;
            this.f25945b.wu(0);
            ku.fm fmVarLb = c.a() != null ? c.a().lb() : new ku.fm("v_preload");
            lb lbVar2 = this.f25945b;
            long jGqi = lbVar2.gqi();
            TimeUnit timeUnit = TimeUnit.MILLISECONDS;
            fmVarLb.fm(jGqi, timeUnit).ro(lbVar2.wey(), timeUnit).lb(lbVar2.sds(), timeUnit);
            ku kuVarFm = fmVarLb.fm();
            duv.fm fmVar = new duv.fm();
            long length = this.f25947d.length();
            int iAjl = lbVar2.ajl();
            boolean zDsz = lbVar2.dsz();
            int iYz = lbVar2.yz();
            if (iYz > 0) {
                if (iYz >= lbVar2.duv()) {
                    zDsz = true;
                } else {
                    iAjl = iYz;
                }
            }
            fmVar.fm("videoPreload").fm(6);
            if (zDsz) {
                fmVar.fm(HlsMediaPlaylist.Interstitial.TIMELINE_OCCUPIES_RANGE, "bytes=" + length + "-").ro(lbVar2.irt()).fm().ro();
            } else {
                fmVar.fm(HlsMediaPlaylist.Interstitial.TIMELINE_OCCUPIES_RANGE, "bytes=" + length + "-" + iAjl).ro(lbVar2.irt()).fm().ro();
            }
            kuVarFm.fm(fmVar.ro()).fm(new d(this, length, i10));
            return;
        }
        this.f25945b.wu(1);
        a(this.f25945b, 200);
        a.a(this.f25945b);
    }
}
