package com.bytedance.sdk.openadsdk.core.YoT.tN;

import android.text.TextUtils;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/* loaded from: classes2.dex */
public class tN {
    private final Map<Sg, String> Sg;
    private final List<String> YFl;

    public tN(List<String> list) {
        this.YFl = list;
        HashMap hashMap = new HashMap();
        this.Sg = hashMap;
        hashMap.put(Sg.CACHEBUSTING, Sg());
    }

    public List<String> YFl() {
        Sg[] values;
        ArrayList arrayList = new ArrayList();
        for (String str : this.YFl) {
            if (!TextUtils.isEmpty(str)) {
                for (Sg sg : Sg.values()) {
                    String str2 = this.Sg.get(sg);
                    if (str2 == null) {
                        str2 = "";
                    }
                    str = str.replaceAll("\\[" + sg.name() + "\\]", str2);
                }
                arrayList.add(str);
            }
        }
        return arrayList;
    }

    public tN YFl(com.bytedance.sdk.openadsdk.core.YoT.YFl.YFl yFl) {
        if (yFl != null) {
            this.Sg.put(Sg.ERRORCODE, yFl.YFl());
        }
        return this;
    }

    public tN YFl(long j) {
        if (j >= 0) {
            String Sg = Sg(j);
            if (!TextUtils.isEmpty(Sg)) {
                this.Sg.put(Sg.CONTENTPLAYHEAD, Sg);
            }
        }
        return this;
    }

    public tN YFl(String str) {
        if (!TextUtils.isEmpty(str)) {
            try {
                str = URLEncoder.encode(str, "UTF-8");
            } catch (Throwable unused) {
            }
            this.Sg.put(Sg.ASSETURI, str);
        }
        return this;
    }

    private String Sg() {
        return String.format(Locale.US, "%08d", Long.valueOf(Math.round(Math.random() * 1.0E8d)));
    }

    private String Sg(long j) {
        return String.format(Locale.getDefault(), "%02d:%02d:%02d.%03d", Long.valueOf(TimeUnit.MILLISECONDS.toHours(j)), Long.valueOf(TimeUnit.MILLISECONDS.toMinutes(j) % TimeUnit.HOURS.toMinutes(1L)), Long.valueOf(TimeUnit.MILLISECONDS.toSeconds(j) % TimeUnit.MINUTES.toSeconds(1L)), Long.valueOf(j % 1000));
    }
}
