package e6;

import androidx.media3.exoplayer.hls.playlist.HlsMediaPlaylist;
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 com.bytedance.sdk.component.utils.wey;
import defpackage.e;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.concurrent.TimeUnit;
import nb.g;
import org.json.JSONObject;
import v5.c;
import xyz.stream.api.a0;

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final long f25500f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public RandomAccessFile f25504j;

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public volatile long f25506l;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public volatile long f25496b = -2147483648L;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Object f25497c = new Object();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public volatile int f25501g = -100;

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

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

    public b(lb lbVar) {
        this.f25500f = 0L;
        this.f25504j = null;
        this.f25505k = lbVar;
        try {
            String strJnr = lbVar.jnr();
            String strQhl = lbVar.qhl();
            File fileO = g.O(strJnr, strQhl);
            this.f25498d = fileO;
            File fileJ = g.J(strJnr, strQhl);
            this.f25499e = fileJ;
            if (fileJ.exists()) {
                this.f25504j = new RandomAccessFile(fileJ, "r");
            } else {
                this.f25504j = new RandomAccessFile(fileO, "rw");
            }
            if (!fileJ.exists()) {
                this.f25500f = fileO.length();
                a();
            }
            this.f25495a = o6.b.f31432i == 2;
        } catch (Throwable unused) {
            lbVar.irt();
        }
    }

    public static void b(b bVar, int i10, String str) {
        JSONObject jSONObjectLb;
        bVar.f25503i = false;
        bVar.f25501g = i10;
        bVar.f25496b = -1L;
        wey.ro("CSJ_MediaDLPlay", "handleFailResponse: ", Integer.valueOf(i10), " ", str);
        lb lbVar = bVar.f25505k;
        if (lbVar == null || !lbVar.fm() || (jSONObjectLb = bVar.f25505k.lb()) == null) {
            return;
        }
        try {
            jSONObjectLb.put("error_real_code", i10);
            jSONObjectLb.put("error_real_msg", str);
        } catch (Throwable th) {
            wey.fm("CSJ_MediaDLPlay", "handleFailResponse: ", th);
        }
    }

    public static void c(b bVar) {
        synchronized (bVar.f25497c) {
            if (bVar.f25499e.exists()) {
                bVar.f25505k.irt();
                bVar.f25505k.qhl();
                return;
            }
            try {
            } finally {
            }
            if (!bVar.f25498d.renameTo(bVar.f25499e)) {
                throw new IOException("Error renaming file " + bVar.f25498d + " to " + bVar.f25499e + " for completion!");
            }
            RandomAccessFile randomAccessFile = bVar.f25504j;
            if (randomAccessFile != null) {
                randomAccessFile.close();
            }
            bVar.f25504j = new RandomAccessFile(bVar.f25499e, "rw");
            bVar.f25505k.qhl();
            bVar.f25505k.irt();
        }
    }

    public final void a() {
        ku.fm fmVarLb = c.a() != null ? c.a().lb() : new ku.fm("v_cache");
        lb lbVar = this.f25505k;
        long jGqi = lbVar.gqi();
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        fmVarLb.fm(jGqi, timeUnit).ro(lbVar.wey(), timeUnit).lb(lbVar.sds(), timeUnit);
        ku kuVarFm = fmVarLb.fm();
        lbVar.qhl();
        kuVarFm.fm(new duv.fm().fm(HlsMediaPlaylist.Interstitial.TIMELINE_OCCUPIES_RANGE, e.m(new StringBuilder("bytes="), this.f25500f, "-")).ro(lbVar.irt()).fm().fm("videoLoadWhenPlaying").fm(9).ro()).fm(new a0(this, 15));
    }
}
