导航菜单

页面标题

页面副标题

哔哩哔哩 v1.6.6 - ResolveResourceParams.java 源代码

正在查看: 哔哩哔哩 v1.6.6 应用的 ResolveResourceParams.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.bilibili.tv.player.basic.context;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Keep;
import android.text.TextUtils;
import bl.mg;
import bl.pz;
import bl.qa;
import bl.qb;
import bl.qe;
import com.bilibili.lib.media.resolver.params.ResolveMediaResourceParams;
import com.bilibili.lib.media.resolver.params.ResolveResourceExtra;
import com.bilibili.tv.MainApplication;
import com.bilibili.tv.player.widget.PlayerMenuRight;
import java.io.Serializable;
import java.util.Collection;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import mybl.BiliFilter;
import org.json.JSONArray;
import org.json.JSONObject;
import tv.danmaku.android.log.BLog;

@Keep
public class ResolveResourceParams implements Parcelable, Serializable {
    public static final Parcelable.Creator<ResolveResourceParams> CREATOR = new Parcelable.Creator<ResolveResourceParams>() {
        @Override
        public ResolveResourceParams createFromParcel(Parcel parcel) {
            return new ResolveResourceParams(parcel);
        }

        @Override
        public ResolveResourceParams[] newArray(int i) {
            return new ResolveResourceParams[i];
        }
    };
    public static final String KEY_FLASH_RESOURCE = "flash_media_resource";
    public static final String KEY_ORIGINAL_FROM = "original_from";
    public static final String KEY_SEASON_TYPE = "season_type";
    public static final String KEY_TRACK_PATH = "track_path";
    public AdParams mAdParams;
    public long mAvid;
    public String mBvid;
    public boolean mCanProjectionScreen;
    public long mCid;
    public String mCodecMode;
    public boolean mEnablePlayUrlHttps;
    public String mEpCover;
    public long mEpisodeId;
    public int mExpectedQuality;
    public String mExpectedTypeTag;
    public ExtraParams mExtraParams;
    public String mFrom;
    public boolean mHasAlias;
    public String mLink;
    public int mPage;
    public String mPageIndex;
    public String mPageTitle;
    public int mProgress;
    public String mRawVid;
    public boolean mRequestFromDownloader;
    public boolean mResolveBiliCdnPlay;
    public int mRoomId;
    public String mSeasonId;
    public int mSpid;
    public long mStartPlayTime;
    public long mStartTimeMS;
    public int mTid;
    public String mType;
    public String mUserAgent;
    public String mVid;
    public String mWeb;
    public JSONArray skips;
    public JSONObject subtitle_data;
    public JSONObject subtitle_info;

    public interface ExtraParams extends Parcelable {
        <T> T a(String str, T t);
    }

    public static class JsonResponse extends qe {
        public JSONObject result() {
            try {
                if (a()) {
                    return new JSONObject(new String(this.b));
                }
                return null;
            } catch (Exception e) {
                return null;
            }
        }

        public JSONArray result2() {
            try {
                if (a()) {
                    return new JSONArray(new String(this.b));
                }
                return null;
            } catch (Exception e) {
                return null;
            }
        }
    }

    public void getSkipInfo() {
        int i = 0;
        this.skips = new JSONArray();
        if (BiliFilter.skip_categories.size() != 0) {
            if (isBangumi()) {
                try {
                    JSONArray optJSONArray = ((JSONObject) Executors.newSingleThreadExecutor().submit(new Callable<JSONObject>() {
                        @Override
                        public JSONObject call() {
                            return ((JsonResponse) pz.a(new qa.a(JsonResponse.class).a("https://api.bilibili.com/pgc/view/web/ep/list").a(true).b("ep_id", String.valueOf(ResolveResourceParams.this.mEpisodeId)).a(new qb()).a(), "GET")).result();
                        }
                    }).get()).optJSONObject("result").optJSONArray("episodes");
                    while (i < optJSONArray.length()) {
                        JSONObject optJSONObject = optJSONArray.optJSONObject(i);
                        if (optJSONObject.optInt("ep_id") == this.mEpisodeId && optJSONObject.optJSONObject("skip") != null) {
                            if (optJSONObject.optJSONObject("skip").optJSONObject("op") != null && BiliFilter.skip_categories.contains("intro")) {
                                double optDouble = optJSONObject.optJSONObject("skip").optJSONObject("op").optDouble("start");
                                double optDouble2 = optJSONObject.optJSONObject("skip").optJSONObject("op").optDouble("end");
                                if (optDouble < optDouble2) {
                                    JSONObject jSONObject = new JSONObject();
                                    jSONObject.put("type", "片头");
                                    jSONObject.put("start", ((long) optDouble) * 1000);
                                    jSONObject.put("end", ((long) optDouble2) * 1000);
                                    this.skips.put(jSONObject);
                                }
                            }
                            if (optJSONObject.optJSONObject("skip").optJSONObject("ed") != null && BiliFilter.skip_categories.contains("outro")) {
                                double optDouble3 = optJSONObject.optJSONObject("skip").optJSONObject("ed").optDouble("start");
                                double optDouble4 = optJSONObject.optJSONObject("skip").optJSONObject("ed").optDouble("end");
                                if (optDouble3 < optDouble4) {
                                    JSONObject jSONObject2 = new JSONObject();
                                    jSONObject2.put("type", "片尾");
                                    jSONObject2.put("start", ((long) optDouble3) * 1000);
                                    jSONObject2.put("end", ((long) optDouble4) * 1000);
                                    this.skips.put(jSONObject2);
                                }
                            }
                        }
                        i++;
                    }
                    return;
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }
            }
            try {
                JSONArray jSONArray = (JSONArray) Executors.newSingleThreadExecutor().submit(new Callable<JSONArray>() {
                    @Override
                    public JSONArray call() {
                        return ((JsonResponse) pz.a(new qa.a(JsonResponse.class).a("https://bsbsb.top/api/skipSegments").a(true).b("videoID", String.valueOf(ResolveResourceParams.this.mBvid)).b("categories", new JSONArray((Collection) BiliFilter.skip_categories).toString()).b("actionType", "skip").a(new qb()).a(), "GET")).result2();
                    }
                }).get();
                while (i < jSONArray.length()) {
                    JSONArray optJSONArray2 = jSONArray.optJSONObject(i).optJSONArray("segment");
                    JSONObject jSONObject3 = new JSONObject();
                    String optString = jSONArray.optJSONObject(i).optString("category");
                    if (optString.equals("intro")) {
                        jSONObject3.put("type", "片头");
                    }
                    if (optString.equals("outro")) {
                        jSONObject3.put("type", "片尾");
                    }
                    if (optString.equals("sponsor")) {
                        jSONObject3.put("type", "硬广");
                    }
                    jSONObject3.put("start", ((long) optJSONArray2.optDouble(0)) * 1000);
                    jSONObject3.put("end", ((long) optJSONArray2.optDouble(1)) * 1000);
                    this.skips.put(jSONObject3);
                    i++;
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }

    public void initPlayInfo() {
        getSkipInfo();
        try {
            ExecutorService newSingleThreadExecutor = Executors.newSingleThreadExecutor();
            if (this.subtitle_info == null) {
                this.subtitle_info = ((JSONObject) newSingleThreadExecutor.submit(new Callable<JSONObject>() {
                    @Override
                    public JSONObject call() {
                        return ((JsonResponse) pz.a(new qa.a(JsonResponse.class).a("https://api.bilibili.com/x/player/wbi/v2").a(true).a("Cookie", "SESSDATA=" + mg.a(MainApplication.a()).getSESSDATA()).b("aid", String.valueOf(ResolveResourceParams.this.mAvid)).b("cid", String.valueOf(ResolveResourceParams.this.mCid)).a(new qb()).a(), "GET")).result();
                    }
                }).get()).optJSONObject("data").optJSONObject("subtitle");
            }
            final int i = PlayerMenuRight.subtitle_id - 1;
            if (i != -1 && this.subtitle_info.optJSONArray("subtitles").length() != 0) {
                if ((i >= -1 || !this.subtitle_info.optJSONArray("subtitles").optJSONObject(0).optString("lan").startsWith("ai-")) && this.subtitle_info != null) {
                    this.subtitle_data = (JSONObject) newSingleThreadExecutor.submit(new Callable<JSONObject>() {
                        @Override
                        public JSONObject call() {
                            return ((JsonResponse) pz.a(new qa.a(JsonResponse.class).a("https:" + ResolveResourceParams.this.subtitle_info.optJSONArray("subtitles").optJSONObject(i < 0 ? 0 : i).optString("subtitle_url")).a(true).a(new qb()).a(), "GET")).result();
                        }
                    }).get();
                    return;
                }
                return;
            }
            this.subtitle_data = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public ResolveResourceParams() {
        this.mExtraParams = new BaseExtraParams();
    }

    public ResolveResourceParams(String str, long j, String str2, String str3, String str4, boolean z, long j2, int i, String str5, int i2, String str6) {
        this.mExtraParams = new BaseExtraParams();
        this.mFrom = str;
        this.mCid = j;
        this.mVid = str2;
        this.mLink = str4;
        this.mRawVid = str3;
        this.mHasAlias = z;
        this.mAvid = j2;
        this.mPage = i;
        this.mPageTitle = str5;
        this.mTid = i2;
        this.mType = str6;
    }

    public final boolean isEmptyCid() {
        return this.mCid <= 0;
    }

    public final boolean isLive() {
        return "live".equalsIgnoreCase(this.mFrom) || isRound();
    }

    public final boolean isBangumi() {
        return this.mEpisodeId > 0;
    }

    public final boolean isClip() {
        return "clip".equalsIgnoreCase(this.mFrom);
    }

    public final long getLiveCid() {
        return isRound() ? this.mRoomId : this.mCid;
    }

    public final boolean isRound() {
        return this.mRoomId > 0;
    }

    public boolean isNecessaryParamsCompletly() {
        return this.mCid > 0 && !TextUtils.isEmpty(this.mFrom);
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeString(this.mFrom);
        parcel.writeLong(this.mCid);
        parcel.writeString(this.mVid);
        parcel.writeString(this.mLink);
        parcel.writeString(this.mRawVid);
        parcel.writeString(this.mPageIndex);
        parcel.writeString(this.mPageTitle);
        parcel.writeByte(this.mHasAlias ? (byte) 1 : (byte) 0);
        parcel.writeInt(this.mSpid);
        parcel.writeLong(this.mAvid);
        parcel.writeInt(this.mPage);
        parcel.writeInt(this.mTid);
        parcel.writeByte(this.mRequestFromDownloader ? (byte) 1 : (byte) 0);
        parcel.writeLong(this.mEpisodeId);
        parcel.writeString(this.mSeasonId);
        parcel.writeString(this.mEpCover);
        parcel.writeByte(this.mResolveBiliCdnPlay ? (byte) 1 : (byte) 0);
        parcel.writeInt(this.mExpectedQuality);
        parcel.writeString(this.mExpectedTypeTag);
        parcel.writeString(this.mUserAgent);
        parcel.writeString(this.mWeb);
        parcel.writeString(this.mCodecMode);
        parcel.writeParcelable(this.mExtraParams, i);
        parcel.writeByte(this.mEnablePlayUrlHttps ? (byte) 1 : (byte) 0);
        parcel.writeParcelable(this.mAdParams, i);
        parcel.writeString(this.mType);
        parcel.writeInt(this.mProgress);
        parcel.writeString(this.mBvid);
    }

    protected ResolveResourceParams(Parcel parcel) {
        this.mExtraParams = new BaseExtraParams();
        this.mFrom = parcel.readString();
        this.mCid = parcel.readLong();
        this.mVid = parcel.readString();
        this.mLink = parcel.readString();
        this.mRawVid = parcel.readString();
        this.mPageIndex = parcel.readString();
        this.mPageTitle = parcel.readString();
        this.mHasAlias = parcel.readByte() != 0;
        this.mSpid = parcel.readInt();
        this.mAvid = parcel.readLong();
        this.mPage = parcel.readInt();
        this.mTid = parcel.readInt();
        this.mRequestFromDownloader = parcel.readByte() != 0;
        this.mEpisodeId = parcel.readLong();
        this.mSeasonId = parcel.readString();
        this.mEpCover = parcel.readString();
        this.mResolveBiliCdnPlay = parcel.readByte() != 0;
        this.mExpectedQuality = parcel.readInt();
        this.mExpectedTypeTag = parcel.readString();
        this.mUserAgent = parcel.readString();
        this.mWeb = parcel.readString();
        this.mCodecMode = parcel.readString();
        this.mExtraParams = (ExtraParams) parcel.readParcelable(ExtraParams.class.getClassLoader());
        this.mEnablePlayUrlHttps = parcel.readByte() != 0;
        this.mAdParams = (AdParams) parcel.readParcelable(AdParams.class.getClassLoader());
        this.mType = parcel.readString();
        this.mProgress = parcel.readInt();
        this.mBvid = parcel.readString();
    }

    public ResolveMediaResourceParams obtainMediaResourceParams() {
        return new ResolveMediaResourceParams(this.mAvid, this.mCid, this.mExpectedQuality, this.mExpectedTypeTag, this.mFrom, this.mRequestFromDownloader, this.mType);
    }

    public ResolveResourceExtra obtainResourceExtra() {
        ResolveResourceExtra resolveResourceExtra = new ResolveResourceExtra(this.mHasAlias, this.mLink, this.mRawVid, this.mVid, this.mWeb, this.mEpisodeId, this.mAvid, (String) this.mExtraParams.a(KEY_TRACK_PATH, "0"));
        resolveResourceExtra.b(((Integer) this.mExtraParams.a(KEY_SEASON_TYPE, -1)).intValue());
        return resolveResourceExtra;
    }

    public long getSeasonId() {
        if (TextUtils.isEmpty(this.mSeasonId)) {
            return 0L;
        }
        try {
            return Long.parseLong(this.mSeasonId);
        } catch (NumberFormatException e) {
            return 0L;
        }
    }

    public int getQualityInt() {
        int qualityFromTypeTag;
        return (TextUtils.isEmpty(this.mExpectedTypeTag) || (qualityFromTypeTag = getQualityFromTypeTag(this.mExpectedTypeTag)) < 0) ? this.mExpectedQuality : qualityFromTypeTag;
    }

    public static int getQualityFromTypeTag(String str) {
        if (!TextUtils.isEmpty(str)) {
            String[] split = str.split("\\.");
            if (split.length > 0) {
                try {
                    return Integer.parseInt(String.valueOf(split[split.length - 1]));
                } catch (NumberFormatException e) {
                    BLog.w("unknown quality from type tag.");
                }
            }
        }
        return -1;
    }
}