Skip to content

Commit

Permalink
bilibili.app.playerunite.v1.Player/PlayViewUnite (#19)
Browse files Browse the repository at this point in the history
* bilibili.app.playerunite.v1

* bilibili.app.playerunite.v1.Player/PlayViewUnite
  • Loading branch information
MotooriKashin authored Sep 22, 2024
1 parent b0334d1 commit 0ecb932
Show file tree
Hide file tree
Showing 75 changed files with 23,145 additions and 32 deletions.
7 changes: 7 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"command": "./protoc --ts_proto_opt=forceLong=bigint --ts_proto_opt=initializeFieldsAsUndefined=false --plugin=protoc-gen-ts_proto=\".\\\\node_modules\\\\.bin\\\\protoc-gen-ts_proto.cmd\" --ts_proto_out=. ${relativeFile}",
"problemMatcher": [],
"detail": "编译当前 proto 文件到 typescript 文件(依赖根目录下的 protoc 编译器)"
},
{
"label": "esbuild",
"type": "shell",
"command": "npx esbuild ${file} --bundle --tree-shaking=true --charset=utf8 --outfile=${fileDirname}/${fileBasenameNoExtension}.js",
"problemMatcher": [],
"detail": "编译当前 ts 文件用于临时测试"
}
]
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"@types/fs-extra": "*",
"esbuild": "*",
"fs-extra": "*",
"ts-proto": "*"
"ts-proto": "*",
"@types/chrome": "*"
},
"scripts": {
"build": "node --no-warnings --experimental-strip-types ./src/build/index.ts",
Expand Down
33 changes: 30 additions & 3 deletions src/build/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,38 @@ const cssConstructStylesheetPlugin = {
}
}

// 编译资源文件
await build({
const key = crypto.randomUUID();

build({
entryPoints: [
'src/sw/index.ts',
'src/sidebar/index.ts',
'src/options/index.ts',
],
outdir: 'dist',
outbase: "src",
bundle: true,
minify: true,
format: 'esm',
sourcemap: true,
treeShaking: true,
charset: 'utf8',
supported: {
decorators: false, // 装饰器暂未得到任何浏览器支持
},
plugins: [cssConstructStylesheetPlugin],
define: {
__TOTP_KEY__: `'${key}'`, // 基于哈希消息认证码的一次性口令的密钥
},
loader: {
'.svg': 'text',
},
})

// 编译资源文件
build({
entryPoints: [
'src/isolated/index.ts',
'src/main/index.ts',
],
outdir: 'dist',
Expand All @@ -49,7 +76,7 @@ await build({
},
plugins: [cssConstructStylesheetPlugin],
define: {
__TOTP_KEY__: `'${crypto.randomUUID()}'`, // 基于哈希消息认证码的一次性口令的密钥
__TOTP_KEY__: `'${key}'`, // 基于哈希消息认证码的一次性口令的密钥
},
loader: {
'.svg': 'text',
Expand Down
Empty file removed src/index.ts
Empty file.
219 changes: 219 additions & 0 deletions src/io/Android.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import { GM } from "../main/GM";
import { base64 } from "../utils/base64";
import { Device } from "./com/bapis/bilibili/metadata/Device";
import { FawkesReq } from "./com/bapis/bilibili/metadata/Fawkes";
import { Locale, LocaleIds } from "./com/bapis/bilibili/metadata/Locale";
import { Metadata } from "./com/bapis/bilibili/metadata/Metadata";
import { Network, NetworkType } from "./com/bapis/bilibili/metadata/Network";
import { genAuroraEid } from "./sign/genAuroraEid";
import { genTraceId } from "./sign/genTraceId";

/** Android端通用变量 */
export namespace Andoroid {
/** 包类型 */
export const mobiApp = 'android';

/** 客户端在fawkes系统的唯一名 */
export const appkey = 'android64';

/** 客户端在fawkes系统中的环境参数 */
export const env = 'prod';

/** 启动id */
export const sessionId = crypto.randomUUID().split('-')[0];

/** 版本号(version_code) */
export const build = 8080200;

/** 渠道 */
export const channel = 'html5_app_bili';

/** 设备buvid */
export const buvid = `XU${crypto.randomUUID().split('-').join(Math.floor(Math.random() * 10).toString()).slice(-35).toLocaleUpperCase()}`;

/** 设备类型 */
export const platform = 'android';

/**
* 产品编号
* | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
* | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: |
* | 粉 | 白 | 蓝 | 直播姬 | HD | 海外 | OTT | 漫画 | TV野版 | 小视频 | 网易漫画 | 网易漫画lite | 网易漫画HD | 国际版 |
*/
export const appId = 0;

/** 手机品牌 */
export const brand = 'Apple';

/** 手机型号 */
export const model = '16';

/** 系统版本 */
export const osver = '16';

/** 设备指纹, 不区分本地或远程设备指纹,作为推送目标的索引. */
export const fp = genTraceId() + genTraceId();

/** 版本号(version_name) */
export const versionName = '8.14.0';

/** 首次启动时的毫秒时间戳 */
export const fts = BigInt(Math.floor(Date.now() / 1000));

export const userAgent = `Dalvik/2.1.0 (Linux; U; Android 12; ${model} Build/${build}) ${versionName} os/android model/${model} mobi_app/${mobiApp} build/${build} channel/master innerVer/${build} osVer/12 network/2 grpc-java-cronet/1.36.1`;

const localeIds = LocaleIds.create({ language: 'zh', region: 'CN' });

/** 发送 grpc 请求 */
export async function rpc(
/** 请求url */
input: RequestInfo | URL,
/** 请求 body */
post: Uint8Array,
/** 登录鉴权 */
accessKey: string,
/** 用户uid */
mid = 0n,
) {
const body = new ArrayBuffer(post.length + 5);
const dataview = new DataView(body);
dataview.setUint32(1, post.length); // 写入字节标记
const uInt8 = new Uint8Array(body);
uInt8[0] = 1; // 写入压缩标记
uInt8.set(post, 5); // 写入数据
const response = await GM.fetch(
input,
{
method: 'POST',
body,
},
[
{
header: 'referer', // grpc 请求不该有referer
operation: <any>'remove',
},
{
header: 'user-agent',
operation: <any>'set',
value: userAgent,
},
{
header: 'Content-type',
operation: 'set',
value: 'application/grpc',
},
{
header: 'te',
operation: 'set',
value: 'trailers',
},
{
header: 'x-bili-gaia-vtoken',
operation: 'set',
value: '',
},
{
header: 'x-bili-aurora-eid',
operation: 'set',
value: genAuroraEid(mid),
},
{
header: 'x-bili-mid',
operation: 'set',
value: mid.toString(),
},
{
header: 'x-bili-aurora-zone',
operation: 'set',
value: '',
},
{
header: 'x-bili-trace-id',
operation: 'set',
value: genTraceId(),
},
{
header: 'x-bili-fawkes-req-bin',
operation: 'set',
value: base64.fromUint8Array(FawkesReq.encode({ appkey, env, sessionId }).finish()),
},
{
header: 'x-bili-metadata-bin',
operation: 'set',
value: base64.fromUint8Array(Metadata.encode({ accessKey, mobiApp, build, channel, buvid, platform }).finish()),
},
{
header: 'authorization',
operation: 'set',
value: `identify_v1 ${accessKey}`,
},
{
header: 'x-bili-device-bin',
operation: 'set',
value: base64.fromUint8Array(Device.encode({ appId, build, buvid, mobiApp, platform, channel, brand, model, osver, fpLocal: fp, fpRemote: fp, versionName, fp, fts }).finish()),
},
{
header: 'x-bili-network-bin',
operation: 'set',
value: base64.fromUint8Array(Network.encode({ type: NetworkType.WIFI }).finish()),
},
{
header: 'x-bili-restriction-bin',
operation: 'set',
value: '',
},
{
header: 'x-bili-locale-bin',
operation: 'set',
value: base64.fromUint8Array(Locale.encode({ cLocale: localeIds, sLocale: localeIds }).finish()),
},
{
header: 'x-bili-exps-bin',
operation: 'set',
value: '',
},
{
header: 'buvid',
operation: 'set',
value: buvid,
},
{
header: 'grpc-encoding',
operation: 'set',
value: 'gzip',
},
{
header: 'grpc-accept-encoding',
operation: 'set',
value: 'identity,gzip',
},
],
[
{
header: 'Access-Control-Allow-Credentials', // 允许携带cookie
operation: <any>'set',
value: 'true',
},
{
header: 'Access-Control-Allow-Methods', // 允许各种请求方法
value: 'GET,POST,PUT,OPTIONS,DELETE',
operation: 'set'
},
{
header: 'Access-Control-Allow-Origin', // 允许请求来源
operation: 'set',
value: 'https://www.bilibili.com',
},
{
header: 'Access-Control-Expose-Headers', // 允许读取grpc头
operation: 'set',
value: 'grpc-status,grpc-message,grpc-status-details-bin,grpc-encoding',
}
]
);
const arraybuffer = await response.arrayBuffer();
// 需要剔除5字节的grpc压缩及字节标记!
const uint8Array = new Uint8Array(arraybuffer.slice(5));
return new Response(new Blob([uint8Array]).stream().pipeThrough(new DecompressionStream('gzip')));
}
}
22 changes: 22 additions & 0 deletions src/io/com/bapis/bilibili/app/playerunite/PGCAnyModel.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

package bilibili.app.playerunite.pgcanymodel;

import "src/io/com/bapis/bilibili/pgc/gateway/player/v2/PlayViewBusinessInfo.proto";
import "src/io/com/bapis/bilibili/pgc/gateway/player/v2/Event.proto";
import "src/io/com/bapis/bilibili/pgc/gateway/player/v2/ViewInfo.proto";
import "src/io/com/bapis/bilibili/pgc/gateway/player/v2/PlayAbilityExtConf.proto";
import "src/io/com/bapis/bilibili/pgc/gateway/player/v2/PlayExtInfo.proto";

message PGCAnyModel {

bilibili.pgc.gateway.player.v2.PlayViewBusinessInfo business = 3;

bilibili.pgc.gateway.player.v2.Event event = 4;

bilibili.pgc.gateway.player.v2.ViewInfo view_info = 5;

bilibili.pgc.gateway.player.v2.PlayAbilityExtConf play_ext_conf = 6;

bilibili.pgc.gateway.player.v2.PlayExtInfo play_ext_info = 7;
}
Loading

0 comments on commit 0ecb932

Please sign in to comment.