package com.ss.android.ugc.aweme.video.preload;

import X.0HH;
import X.4Ms;
import X.AnonymousClass7R6;
import X.AnonymousClass7UR;
import X.AnonymousClass7dQ;
import X.AnonymousClass7dW;
import X.AnonymousClass7dX;
import X.AnonymousClass7lW;
import X.AnonymousClass80F;
import X.AnonymousClass80L;
import X.AnonymousClass8BE;
import X.AnonymousClass8BK;
import X.AnonymousClass8N3;
import X.AnonymousClass8N6;
import X.AnonymousClass8N9;
import X.AnonymousClass8NA;
import X.AnonymousClass8NQ;
import X.AnonymousClass8PM;
import X.AnonymousClass8PN;
import X.AnonymousClass8RS;
import X.AnonymousClass8S4;
import X.AnonymousClass8S6;
import X.AnonymousClass8SA;
import X.AnonymousClass8SB;
import X.AnonymousClass8SF;
import X.AnonymousClass8SG;
import X.AnonymousClass8SI;
import X.AnonymousClass8SO;
import X.AnonymousClass8SP;
import X.AnonymousClass8SQ;
import X.AnonymousClass8SR;
import X.AnonymousClass8SS;
import X.AnonymousClass8ST;
import X.AnonymousClass8SU;
import X.AnonymousClass8SV;
import X.AnonymousClass8SY;
import X.AnonymousClass8UD;
import X.AnonymousClass8US;
import X.AnonymousClass8UV;
import X.AnonymousClass8UX;
import X.AnonymousClass8WG;
import X.AnonymousClass8WI;
import X.AnonymousClass8WO;
import X.AnonymousClass8WX;
import X.C02697ac;
import X.C02717ae;
import X.C12377yW;
import X.C16758Di;
import X.C19248Mx;
import X.C19258My;
import X.C20588Sb;
import X.C20598Sc;
import X.C20608Sd;
import X.C20638Sg;
import X.C20648Sh;
import X.C20658Si;
import X.C20678Sk;
import X.C21438Vi;
import X.C21558Vu;
import X.C21598Vy;
import X.M12;
import X.MHC;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.video.preload.model.PreloadStrategyConfig;
import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.LinkedBlockingQueue;
import org.json.JSONException;
import org.json.JSONObject;

public class VideoCachePreloader implements C20608Sd {
    public static final String CACHE_FILE = AnonymousClass8NQ.VideoCache.getCacheDirName();
    public static final String TAG = VideoCachePreloader.class.getSimpleName();
    public static File sCache;
    public static File sVideoCacheFile;
    public WeakReference<Object> completeListener;
    public final IVideoPreloadConfig config = AnonymousClass8BE.LIZ.LIZ();
    public WeakReference<C20638Sg> downloadFinishListener;
    public final List<WeakReference<AnonymousClass8N3>> downloadProgressListeners = new CopyOnWriteArrayList();
    public boolean hasProxyInited;
    public HashMap<String, AnonymousClass8SY> ioReadTimeInfoMap = new AnonymousClass8SQ(this);
    public C02697ac mCurrentDownloadInfo = null;
    public boolean mLazyGetUrlsMode;
    public AnonymousClass8SF mPreLoadThread;
    public double mRealtimeNetworkSpeedInBps = -1.0d;
    public HashMap<String, List<C02697ac>> mSingleTimeReadTimeInfoMap = new AnonymousClass8NA(this);
    public AnonymousClass8S6 mSpeedHandler;
    public long mTotalDownloadBytes;
    public Map<String, List<AnonymousClass8SA>> readTimeInfoMap = Collections.synchronizedMap(new AnonymousClass8SP(this));
    public Map<String, List<AnonymousClass7dW>> requestModelListMap = Collections.synchronizedMap(new AnonymousClass8N9(this));
    public Map<String, AnonymousClass7dW> requestModelMap = Collections.synchronizedMap(new LinkedHashMap<String, AnonymousClass7dW>() {
        static {
            Covode.recordClassIndex(122846);
        }

        public final boolean removeEldestEntry(Map.Entry entry) {
            if (size() > 10) {
                return true;
            }
            return false;
        }
    });

    public void addMedias(List<C16758Di> list, boolean z, boolean z2, String str) {
    }

    public void addMediasOpt(C20588Sb r1, boolean z, boolean z2, String str) {
    }

    public void addPreloadCallback(AnonymousClass7UR r1) {
    }

    public void addPreloadItem(C16758Di r1, C20658Si r2) {
    }

    public void clearCache(C16758Di r1) {
    }

    public void createScene(String str, String str2) {
    }

    public void destroyScene(String str) {
    }

    public String getCachePath(C16758Di r2) {
        return "";
    }

    public boolean isSupportDash() {
        return false;
    }

    public void loadVerifyLib() {
    }

    public void makeCurrentScene(String str) {
    }

    public void onProxyUrl(C16758Di r1, String str) {
    }

    public boolean preload(C16758Di r2, int i) {
        return AnonymousClass8SS.LIZ(this, r2, i);
    }

    public boolean preload(String str, String str2, int i, long j, AnonymousClass8PM r7, AnonymousClass8BK r8) {
        return false;
    }

    public boolean preload(String str, String str2, int i, AnonymousClass8PM r5, AnonymousClass8BK r6) {
        return false;
    }

    public void removePlayTaskDownloadProgressListener(C20648Sh r1) {
    }

    public void removePreloadCallback(AnonymousClass7UR r1) {
    }

    public void resetConcurrentNum() {
    }

    public void setConcurrentNum(int i) {
    }

    public void setPeakAlgoInfo(String str) {
    }

    public void setPlayTaskDownloadProgressListener(C20648Sh r1) {
    }

    public void setPreloadCallback(AnonymousClass7UR r1) {
    }

    public void setPreloadStrategyConfig(PreloadStrategyConfig preloadStrategyConfig) {
    }

    public void setSmartPreloadAlgorithmJson(String str) {
    }

    public void setSmartPreloadPlayTaskAlgorithmJson(String str) {
    }

    public void setTimelinessAlgorithmJson(String str) {
    }

    public void smartPreloadBusinessEvent(String str) {
    }

    public void smartPreloadPlayTaskBusinessEvent(String str) {
    }

    public void smartTimelinessPreloadBusinessEvent(String str) {
    }

    public int startMethodHook() {
        return -1;
    }

    public boolean supportPreloadObservable() {
        return false;
    }

    public long tryToClearAndGetCachesByUsedTime(long j, boolean z) {
        return -1;
    }

    public void updateAppState(boolean z) {
    }

    public void updateDnsBackupIpMap(Map<String, String> map) {
    }

    public void writeDataToFile(String str, long j, long j2, int i, byte[] bArr) {
    }

    public static VideoCachePreloader getInstance() {
        return AnonymousClass8SV.LIZ;
    }

    public File getCacheFile() {
        return sCache;
    }

    public double getRealtimeNetworkSpeedInBps() {
        return this.mRealtimeNetworkSpeedInBps;
    }

    public long getTotalDownloadBytes() {
        return this.mTotalDownloadBytes;
    }

    public AnonymousClass8NQ getType() {
        return AnonymousClass8NQ.VideoCache;
    }

    public boolean isInited() {
        return this.hasProxyInited;
    }

    public void cancelAll() {
        if (checkInit()) {
            this.mPreLoadThread.LIZ(2);
        }
    }

    public void clearCache() {
        if (checkInit()) {
            this.mPreLoadThread.LIZ(3);
        }
    }

    public String getNetworkLibName() {
        if (AnonymousClass8SG.LJIIJ) {
            return "ttnet";
        }
        return "okhttp";
    }

    static {
        Covode.recordClassIndex(122845);
    }

    private void setPreloadTimeout() {
        int i;
        if (AnonymousClass8SG.LJIIJ) {
            i = this.config.getExperiment().VideoCacheTTnetPreloadTimeoutExperiment();
        } else {
            i = 30000;
        }
        C21438Vi LIZ = C21438Vi.LIZ();
        LIZ.LJII = (long) i;
        LIZ.LJIIIIZZ = 30000;
        LIZ.LJIIIZ = 30000;
    }

    private void setProxyTimeout() {
        int i;
        if (AnonymousClass8SG.LJIIJ) {
            i = this.config.getExperiment().VideoCacheTTnetProxyTimeoutExperiment();
        } else {
            i = 10000;
        }
        C21598Vy LIZ = C21598Vy.LIZ();
        LIZ.LJIIIIZZ = (long) i;
        LIZ.LJIIIZ = 10000;
        LIZ.LJIIJ = 10000;
    }

    public boolean checkInit() {
        if (this.mPreLoadThread != null) {
            return true;
        }
        initProxy();
        try {
            AnonymousClass8SF r0 = new AnonymousClass8SF(this);
            this.mPreLoadThread = r0;
            r0.start();
            return true;
        } catch (Exception unused) {
            return false;
        }
    }

    public void quit() {
        AnonymousClass8SF r1 = this.mPreLoadThread;
        if (r1 != null) {
            r1.LIZ(4);
            this.mPreLoadThread = null;
        }
        AnonymousClass8S6 r12 = this.mSpeedHandler;
        if (r12 != null && !MHC.LIZIZ()) {
            r12.LIZJ.removeCallbacks(r12);
            r12.LIZLLL = false;
            r12.LJ = false;
        }
    }

    public AnonymousClass8SB getTotalPreloadIoReadTimeInfo() {
        AnonymousClass8SB r6 = new AnonymousClass8SB();
        for (String str : this.ioReadTimeInfoMap.keySet()) {
            AnonymousClass8SY r4 = this.ioReadTimeInfoMap.get(str);
            if (r4 != null) {
                r6.LIZ += r4.LIZLLL;
                r6.LIZIZ += r4.LIZJ;
            }
        }
        return r6;
    }

    private AnonymousClass8UD initDiskLruCache() {
        File videoCacheDir;
        long LIZ;
        File file;
        Application application = AnonymousClass7dQ.LIZ;
        AnonymousClass8UD r9 = null;
        if (application == null || (videoCacheDir = getVideoCacheDir(application)) == null) {
            return null;
        }
        long j = 104857600;
        int VideoCacheMaxCacheSizeExperiment = this.config.getExperiment().VideoCacheMaxCacheSizeExperiment();
        if (VideoCacheMaxCacheSizeExperiment > 0) {
            j = (long) (VideoCacheMaxCacheSizeExperiment * 1048576);
        }
        if (Build.VERSION.SDK_INT >= 23) {
            LIZ = j;
        } else {
            LIZ = (AnonymousClass80F.LIZ() * 1048576) / 8;
        }
        if (this.config.getStorageManager().LIZ() && (file = sVideoCacheFile) != null) {
            LIZ = file.getFreeSpace() / 8;
        }
        if (LIZ <= j) {
            if (LIZ < 10485760) {
                j = 10485760;
            } else {
                j = LIZ;
            }
        }
        sCache = videoCacheDir;
        try {
            AnonymousClass8UD r1 = new AnonymousClass8UD(videoCacheDir);
            try {
                r1.LJ = j;
                r1.LIZ();
                return r1;
            } catch (IOException e) {
                e = e;
                r9 = r1;
            }
        } catch (IOException e2) {
            e = e2;
            0HH.LIZ(e);
            return r9;
        }
    }

    public void initProxy() {
        AnonymousClass8UD initDiskLruCache;
        boolean z;
        boolean z2;
        boolean z3;
        if (!this.hasProxyInited && (initDiskLruCache = initDiskLruCache()) != null) {
            if (this.config.getExperiment().PlayerPreloadLazyGetUrlsExperiment().booleanValue() || AnonymousClass7dQ.LIZ().isDebug()) {
                z = true;
            } else {
                z = false;
            }
            this.mLazyGetUrlsMode = z;
            int VideoSpeedQueueSizeExperiment = this.config.getExperiment().VideoSpeedQueueSizeExperiment();
            if (this.config.getSpeedManager().LIZ() != VideoSpeedQueueSizeExperiment && VideoSpeedQueueSizeExperiment > 0) {
                this.config.getSpeedManager().LIZ(VideoSpeedQueueSizeExperiment);
                this.config.getSpeedManager().LIZIZ(VideoSpeedQueueSizeExperiment);
            }
            AnonymousClass8ST.LIZ = 1;
            C21438Vi.LJI.LIZJ = new LinkedBlockingQueue();
            AnonymousClass8SG.LJJIII = AnonymousClass7dQ.LIZ().isDebug();
            AnonymousClass8SG.LJIILJJIL = 10;
            AnonymousClass8SG.LJJII = this.config.getExperiment().VideoCacheWriteAsynchronousExperiment().booleanValue();
            AnonymousClass8SG.LJJ = 1;
            AnonymousClass8SG.LJJIFFI = this.config.getExperiment().UseVideoCacheHttpDnsExperiment().booleanValue();
            AnonymousClass8SG.LJIIL = this.config.getPlayerCommonParamManager().LIZIZ();
            AnonymousClass8SG.LJIL = this.config.getPlayerCommonParamManager().LIZ();
            AnonymousClass8SG.LJIILL = this.config.getExperiment().CheckVideoCacheRequestHeaderExperiment().booleanValue();
            AnonymousClass8SG.LJIILLIIL = this.config.getExperiment().PreloadLocalCachePathVideoPlayExperiment().booleanValue();
            AnonymousClass8SG.LJIJI = this.config.getExperiment().VideoCacheAutoAdjustPreloadMaxExperiment().booleanValue();
            AnonymousClass8SG.LJIILIIL = this.config.getExperiment().VideoCacheReadBuffersizeExperiment();
            AnonymousClass8SG.LJIIZILJ = this.config.getExperiment().PlayerAbUseLastIf403Exp().booleanValue();
            if (this.config.getExperiment().PlayUse2UrlExperiment() == 1) {
                z2 = true;
            } else {
                z2 = false;
            }
            AnonymousClass8SG.LJIJ = z2;
            if (this.config.getExperiment().PlayeAbUserHttp2Exp() == 1 || AnonymousClass7dQ.LIZ().isDebug()) {
                z3 = true;
            } else {
                z3 = false;
            }
            AnonymousClass8SG.LJIJJ = z3;
            AnonymousClass8WO.LIZJ = 300;
            if (this.config.getExperiment().UseTTNetExperiment() == 1) {
                AnonymousClass8SG.LJIIJ = true;
            } else {
                AnonymousClass8SG.LJIIJ = false;
            }
            AnonymousClass8SG.LJIIJJI = this.config.getExperiment().VideoCacheMonitorNetStatus().booleanValue();
            AnonymousClass8SG.LJIJJLI = this.config.getMusicService().LIZ();
            C21558Vu.LIZ = new C19258My(this);
            AnonymousClass8SG.LJJI = new AnonymousClass8SU(this);
            C21558Vu.LIZIZ = true;
            AnonymousClass8SG.LJIIIIZZ = new C19248Mx(this);
            AnonymousClass8SG.LJIIIZ = new AnonymousClass8N6(this);
            AnonymousClass8SG.LJII = new AnonymousClass8SO(this);
            AnonymousClass8SG.LJI = new AnonymousClass8S4(this);
            C21598Vy LIZ = C21598Vy.LIZ();
            if (LIZ.LJIIL.compareAndSet(false, true)) {
                new Thread(LIZ.LJIIJJI).start();
            }
            Application application = AnonymousClass7dQ.LIZ;
            if (application != null) {
                Context applicationContext = application.getApplicationContext();
                if (AnonymousClass7lW.LIZJ && applicationContext == null) {
                    applicationContext = AnonymousClass7lW.LIZ;
                }
                AnonymousClass8SG.LJ = applicationContext;
                if (AnonymousClass8SG.LIZIZ == null) {
                    C12377yW r0 = AnonymousClass8SG.LIZ;
                    if (r0 == null || !r0.LIZ.getAbsolutePath().equals(initDiskLruCache.LIZ.getAbsolutePath())) {
                        AnonymousClass8SG.LIZIZ = initDiskLruCache;
                        AnonymousClass8SG.LIZLLL = AnonymousClass8UX.LIZ((Context) application);
                        AnonymousClass8UD r02 = AnonymousClass8SG.LIZIZ;
                        r02.LIZLLL.add(new AnonymousClass8UV());
                        C21598Vy LIZ2 = C21598Vy.LIZ();
                        LIZ2.LJFF = initDiskLruCache;
                        LIZ2.LJ = AnonymousClass8SG.LIZLLL;
                        C21438Vi LIZ3 = C21438Vi.LIZ();
                        LIZ3.LIZLLL = initDiskLruCache;
                        LIZ3.LIZJ = AnonymousClass8SG.LIZLLL;
                    } else {
                        throw new IllegalArgumentException("DiskLruCache & DiskCache can not use same path");
                    }
                }
                setPreloadTimeout();
                setProxyTimeout();
                this.hasProxyInited = true;
                return;
            }
            throw new IllegalArgumentException("DiskLruCache and Context can't be null !!!");
        }
    }

    public void cancelAll(int i) {
        cancelAll();
    }

    public static String getKey(C16758Di r0) {
        return r0.getBitRatedRatioUri();
    }

    public boolean preload(C16758Di r2) {
        return preload(r2, 0);
    }

    public void setDownloadFinishListener(C20638Sg r2) {
        this.downloadFinishListener = new WeakReference<>(r2);
    }

    public void setMaxPreloadSize(int i) {
        C21438Vi.LJI.LIZIZ = i;
    }

    public int cacheSize(C16758Di r4) {
        if (r4 != null) {
            return (int) AnonymousClass8US.LIZ.LIZ(r4.getBitRatedRatioUri());
        }
        return 0;
    }

    public void cancelProxy(C16758Di r3) {
        C21598Vy.LIZ().LIZ(r3.getBitRatedRatioUri());
    }

    public List<AnonymousClass7dW> getRequestInfoList(C16758Di r3) {
        return this.requestModelListMap.get(r3.getBitRatedRatioUri());
    }

    public List<C02697ac> getSingleTimeDownloadList(C16758Di r3) {
        return this.mSingleTimeReadTimeInfoMap.get(r3.getBitRatedRatioUri());
    }

    public boolean isCacheCompleted(C16758Di r2) {
        if (r2 == null) {
            return false;
        }
        return isCache(r2);
    }

    public void removeDownloadFinishListener(C20638Sg r2) {
        WeakReference<C20638Sg> weakReference = this.downloadFinishListener;
        if (weakReference != null && weakReference.get() == r2) {
            this.downloadFinishListener = null;
        }
    }

    public static File INVOKEVIRTUAL_com_ss_android_ugc_aweme_video_preload_VideoCachePreloader_com_ss_android_ugc_aweme_lancet_ContextLancet_getCacheDir(Context context) {
        if (4Ms.LIZIZ != null && 4Ms.LJ) {
            return 4Ms.LIZIZ;
        }
        File cacheDir = context.getCacheDir();
        4Ms.LIZIZ = cacheDir;
        return cacheDir;
    }

    public void cancelPreload(C16758Di r4) {
        if (checkInit()) {
            AnonymousClass8SF r2 = this.mPreLoadThread;
            r2.LIZ(r2.LIZ(1, r4, -1));
        }
    }

    public C02717ae convertReadTimeInfo(AnonymousClass8SA r3) {
        if (r3 == null) {
            return null;
        }
        C02717ae r1 = new C02717ae();
        r1.LIZJ = r3.LIZJ;
        r1.LIZ = r3.LIZ;
        r1.LIZLLL = r3.LIZLLL;
        r1.LIZIZ = r3.LIZIZ;
        return r1;
    }

    public AnonymousClass7dW getRequestInfo(C16758Di r3) {
        try {
            return this.requestModelMap.get(r3.getBitRatedRatioUri());
        } catch (Exception e) {
            0HH.LIZ(e);
            return null;
        }
    }

    public boolean isCache(C16758Di r7) {
        if (r7 == null || AnonymousClass8US.LIZ.LIZ(r7.getBitRatedRatioUri()) <= 0) {
            return false;
        }
        return true;
    }

    public void addDownloadProgressListener(AnonymousClass8N3 r4) {
        Iterator<WeakReference<AnonymousClass8N3>> it = this.downloadProgressListeners.iterator();
        if (!it.hasNext() || it.next().get() != r4) {
            this.downloadProgressListeners.add(new WeakReference(r4));
        }
    }

    public void createCurrentDownloadInfo(AnonymousClass8SI r5) {
        if (r5 != null && !TextUtils.isEmpty(r5.LIZ)) {
            List list = this.mSingleTimeReadTimeInfoMap.get(r5.LIZ);
            if (list == null) {
                list = new ArrayList();
                this.mSingleTimeReadTimeInfoMap.put(r5.LIZ, list);
            }
            C02697ac r2 = new C02697ac();
            String str = r5.LIZ;
            M12.LIZ(str);
            r2.LIZ = str;
            r2.LIZIZ = (long) (list.size() + 1);
            list.add(r2);
            this.mCurrentDownloadInfo = r2;
        }
    }

    public C02697ac getLastSingleTimeInfo(String str) {
        List list;
        if (!TextUtils.isEmpty(str) && (list = this.mSingleTimeReadTimeInfoMap.get(str)) != null && list.size() > 0) {
            return (C02697ac) list.get(list.size() - 1);
        }
        return null;
    }

    public AnonymousClass8SB getPreloadIoReadTimeInfo(C16758Di r5) {
        String bitRatedRatioUri = r5.getBitRatedRatioUri();
        if (!this.ioReadTimeInfoMap.containsKey(bitRatedRatioUri)) {
            return null;
        }
        AnonymousClass8SY r3 = this.ioReadTimeInfoMap.get(bitRatedRatioUri);
        AnonymousClass8SB r2 = new AnonymousClass8SB();
        r2.LIZ = r3.LIZLLL;
        r2.LIZIZ = r3.LIZJ;
        return r2;
    }

    public long getPreloadedSize(String str) {
        File LJ;
        AnonymousClass8UD r1 = C21438Vi.LIZ().LIZLLL;
        if (!(r1 == null || TextUtils.isEmpty(str) || (LJ = r1.LJ(AnonymousClass80L.LIZ(str))) == null)) {
            long length = LJ.length();
            if (length > 0) {
                return length;
            }
        }
        return 0;
    }

    public long getVideoSize(String str) {
        AnonymousClass8WX LIZ;
        AnonymousClass8UX r4 = C21438Vi.LIZ().LIZJ;
        if (r4 == null || TextUtils.isEmpty(str) || (LIZ = r4.LIZ(AnonymousClass80L.LIZ(str), 0)) == null) {
            return 0;
        }
        return (long) LIZ.LIZJ;
    }

    public void removeDownloadProgressListener(AnonymousClass8N3 r5) {
        ArrayList arrayList = new ArrayList();
        for (WeakReference next : this.downloadProgressListeners) {
            if (next.get() == r5) {
                arrayList.add(next);
            }
        }
        this.downloadProgressListeners.removeAll(arrayList);
    }

    private File getVideoCacheDir(Context context) {
        File file = sVideoCacheFile;
        if (file != null) {
            return file;
        }
        File INVOKEVIRTUAL_com_ss_android_ugc_aweme_video_preload_VideoCachePreloader_com_ss_android_ugc_aweme_lancet_ContextLancet_getCacheDir = INVOKEVIRTUAL_com_ss_android_ugc_aweme_video_preload_VideoCachePreloader_com_ss_android_ugc_aweme_lancet_ContextLancet_getCacheDir(context);
        if (this.config.getStorageManager().LIZ()) {
            INVOKEVIRTUAL_com_ss_android_ugc_aweme_video_preload_VideoCachePreloader_com_ss_android_ugc_aweme_lancet_ContextLancet_getCacheDir = this.config.getStorageManager().LIZ(context, AnonymousClass8RS.PREFER_PRIVATE);
        }
        if (AnonymousClass7dQ.LIZ().isDebug()) {
            INVOKEVIRTUAL_com_ss_android_ugc_aweme_video_preload_VideoCachePreloader_com_ss_android_ugc_aweme_lancet_ContextLancet_getCacheDir = AnonymousClass8SR.LIZ(context);
        }
        if (INVOKEVIRTUAL_com_ss_android_ugc_aweme_video_preload_VideoCachePreloader_com_ss_android_ugc_aweme_lancet_ContextLancet_getCacheDir == null) {
            return null;
        }
        File file2 = new File(INVOKEVIRTUAL_com_ss_android_ugc_aweme_video_preload_VideoCachePreloader_com_ss_android_ugc_aweme_lancet_ContextLancet_getCacheDir, CACHE_FILE);
        if (!file2.exists()) {
            file2.mkdirs();
        }
        sVideoCacheFile = file2;
        return file2;
    }

    public AnonymousClass7dX convertToCDNLog(AnonymousClass8SI r4) {
        if (r4 == null) {
            return null;
        }
        AnonymousClass7dX r2 = new AnonymousClass7dX();
        r2.LIZ = 2;
        r2.LJII = r4.LIZ;
        r2.LJJIIJ = r4.LIZIZ;
        r2.LJJIJIIJI = r4.LIZJ;
        r2.LJJIJIIJIL = r4.LIZLLL;
        r2.LJJIJIL = r4.LJ;
        r2.LJJIJL = r4.LJFF;
        r2.LJIILIIL = r4.LJI;
        r2.LJJIJLIJ = r4.LJII;
        r2.LJJIL = r4.LJIIIIZZ;
        r2.LJJIZ = (long) r4.LJIIIZ;
        r2.LJJJ = r4.LJIIJ;
        r2.LJIILLIIL = r4.LJIIJJI;
        r2.LJJJI = r4.LJIIL;
        r2.LJJJIL = r4.LJIILIIL;
        return r2;
    }

    public AnonymousClass7R6 readTimeInfo(C16758Di r6) {
        try {
            List<AnonymousClass8SA> list = this.readTimeInfoMap.get(r6.getBitRatedRatioUri());
            if (list == null || list.size() <= 0) {
                return null;
            }
            AnonymousClass7R6 r4 = new AnonymousClass7R6();
            r4.LIZJ = list.size();
            for (AnonymousClass8SA r2 : list) {
                if (r2 != null) {
                    r4.LIZ += r2.LIZLLL;
                    r4.LIZIZ += r2.LIZJ;
                }
            }
            return r4;
        } catch (Exception e) {
            0HH.LIZ(e);
            return null;
        }
    }

    public JSONObject genAlogJSON(String str, String str2, String str3) {
        JSONObject jSONObject;
        if (!AnonymousClass7dQ.LIZLLL().isEnabled()) {
            return null;
        }
        jSONObject = new JSONObject();
        try {
            jSONObject.put("tag", str);
            jSONObject.put("msg", str2);
            jSONObject.put("vid", str3);
            return jSONObject;
        } catch (JSONException e) {
            0HH.LIZ(e);
        } catch (Throwable unused) {
        }
        return jSONObject;
    }

    public boolean preload(String str, String str2, int i) {
        return preload(str, str2, i, AnonymousClass8PN.LIZIZ, (AnonymousClass8BK) null);
    }

    public String proxyUrl(C16758Di r12, String str, String[] strArr) {
        AnonymousClass8WX LIZ;
        if (this.config.getCacheHelper().LIZ()) {
            String LIZ2 = this.config.getCacheHelper().LIZ(r12.getSourceId());
            if (this.config.getCacheHelper().LIZIZ(LIZ2)) {
                return LIZ2;
            }
        }
        C21598Vy LIZ3 = C21598Vy.LIZ();
        if (TextUtils.isEmpty(str) || strArr == null || strArr.length <= 0) {
            return null;
        }
        AnonymousClass8UD r1 = LIZ3.LJFF;
        if (r1 == null || LIZ3.LJ == null) {
            return strArr[0];
        }
        String LIZ4 = AnonymousClass80L.LIZ(str);
        AnonymousClass8US.LIZ.LIZ(str, LIZ4);
        if (AnonymousClass8SG.LJIILLIIL) {
            File LIZ5 = r1.LIZ(LIZ4);
            if (LIZ5.exists() && LIZ5.isFile() && (LIZ = LIZ3.LJ.LIZ(LIZ4, 0)) != null && LIZ5.length() >= ((long) LIZ.LIZJ)) {
                if (AnonymousClass8SG.LJI != null) {
                    AnonymousClass8WG.LIZIZ((Runnable) new C20678Sk(LIZ3, str, LIZ));
                }
                return LIZ5.getAbsolutePath();
            }
        }
        List<String> LIZ6 = AnonymousClass8WG.LIZ(strArr);
        if (LIZ3.LIZJ.get() == 1 && LIZ6 != null) {
            StringBuilder sb = new StringBuilder(512);
            while (true) {
                String LIZ7 = AnonymousClass8WI.LIZ(sb, str, LIZ4, LIZ6, "");
                if (LIZ7.length() <= 3072) {
                    return "http://127.0.0.1:" + LIZ3.LIZIZ + "?" + LIZ7;
                } else if (LIZ6.size() == 1) {
                    break;
                } else {
                    LIZ6.remove(LIZ6.size() - 1);
                }
            }
        }
        return strArr[0];
    }

    public boolean preload(C16758Di r2, int i, AnonymousClass8PM r4, AnonymousClass8BK r5) {
        if (!checkInit()) {
            return false;
        }
        this.mPreLoadThread.LIZ(r2, i);
        return true;
    }

    public boolean preload(String str, String str2, int i, long j) {
        return preload(str, str2, i, j, AnonymousClass8PN.LIZIZ, (AnonymousClass8BK) null);
    }

    public boolean preload(List<C16758Di> list, int i, List<C16758Di> list2, int i2) {
        if (!checkInit()) {
            return false;
        }
        if (this.config.isPlayerPreferchCaption() && list != null && !list.isEmpty()) {
            if (this.config.playerPreferchCaptionSize() > 0.0f) {
                i = (int) (this.config.playerPreferchCaptionSize() * 1024.0f);
            }
            for (C16758Di next : list) {
                if (next != null) {
                    this.mPreLoadThread.LIZ(next, i);
                }
            }
        }
        if (!this.config.isPlayerPreferchTtsAudio() || list2 == null || list2.isEmpty()) {
            return true;
        }
        if (this.config.playerPreferchTtsAudioSize() > 0.0f) {
            i2 = (int) (this.config.playerPreferchTtsAudioSize() * 1024.0f);
        }
        for (C16758Di next2 : list2) {
            if (next2 != null) {
                this.mPreLoadThread.LIZ(next2, i2);
            }
        }
        return true;
    }

    public void copyCache(C16758Di r1, String str, boolean z, boolean z2, C20598Sc r5) {
        if (r5 != null) {
            r5.LIZ();
        }
    }
}
