侧边栏壁纸
  • 累计撰写 65 篇文章
  • 累计创建 46 个标签
  • 累计收到 105 条评论

目 录CONTENT

文章目录

适用于ios的surge、shadowrocket、stash等的Bilibili港澳台番剧解锁

草莓牛奶
2023-11-04 / 4 评论 / 0 点赞 / 588 阅读 / 1,539 字 / 正在检测是否收录...
温馨提示:
「博客文章out of date 会及时更新,无特殊说明仍然有效,欢迎指正内容中的错误」

零、前言

①适用于surge、shadowrocket、stash、Loon等IOS客户端,主要实现方式通过向反代服务器进行请求

②适用于没有港澳台代理,以cloudfront为例,不出意外每月的成本就是0

image-20231104204109712

一、现状问题

1.解除B站区域限制脚本

由于B 站已经停用了账号授权依赖的关键 API,导致脚本解除B站区域限制 ,会显示“正在获取授权,请稍后……”或"账号未登录, 若已登录请尝试退出重新登录"

img

目前的临时解决方法是账号授权问题,临时解决方案 · Issue #1249

2.IOS不存在漫游客户端

脚本BiliUniverse/Roaming: 通过公共解析服务器实现地区漫游,进而提供其他增强功能 ,处于初始化的状态

主要问题在于B站客户端采用bilibili.pgc.gateway.player.v2 -> PlayView PGC 视频播放链接接口(V2 版本),漫游服务器目前不支持,相互之间难以适配

二、准备工作

需要利用cdn反代3个域名:api.bilibili.comapp.bilibili.com(Failover gRPC 接口)、grpc.biliapi.net(原生 gRPC 接口)

详细方法详见:

利用cloudflare works解锁Bilibili(B站)港澳台番剧

利用Cloudfront解锁Bilibili(B站)港澳台番剧

利用Gcore解锁Bilibili(B站)港澳台番剧

注:

①gRPC 接口是通过post请求访问的,cloudfront选择运行的HTTP方法的时候需要注意

②B站的IP库的接口是https://api.live.bilibili.com/ip_service/v1/ip_service/get_ip_addr?ip=1.1.1.1 ,建议检查一下制定的CDN的IP是港澳台的

image-20231104204231600

三、配置脚本

1.javascript脚本

假设反代的CDN的域名映射关系如下:

api.bilibili.com→api.example.com

app.bilibili.com→app.example.com

grpc.biliapi.net→grpc.example.com

以下js脚本主要用于处理传入的请求,转发至对应的反代域名:BiliBili.Roaming.request.beta.js

const URL = new URLs();

// headers转小写
for (const [key, value] of Object.entries($request.headers)) {
	delete $request.headers[key]
	$request.headers[key.toLowerCase()] = value
};

/***************** Processing *****************/
!(async () => {
	let url = URL.parse($request.url);
	console.log(url.path);
	if (url.host === "api.bilibili.com") {
		url.host = "api.example.com";
	}
	if (url.host === "grpc.biliapi.net") {
		url.host = "grpc.example.com";
	}
	if (url.host === "app.bilibili.com") {
		url.host = "app.example.com";
	}
	if ($request?.headers?.host) $request.headers.host = url.host;
	if ($request?.headers?.authority) $request.headers.authority = url.host;
	$request.url = URL.stringify(url);
})()
	.catch((e) => console.error(e))
	.finally(() => {
		$done($request)
	})
	
// https://github.com/DualSubs/URL/blob/main/URLs.embedded.min.js
function URLs(s){return new class{constructor(s=[]){this.name="URL v1.0.2",this.opts=s,this.json={scheme:"",host:"",path:"",params:{}}}parse(s){let t=s.match(/(?<scheme>.+):\/\/(?<host>[^/]+)\/?(?<path>[^?]+)?\??(?<params>.*)?/)?.groups??null;return t?.path||(t.path=""),t?.params&&(t.params=Object.fromEntries(t.params.split("&").map((s=>s.split("="))))),t}stringify(s=this.json){return s?.params?s.scheme+"://"+s.host+"/"+s.path+"?"+Object.entries(s.params).map((s=>s.join("="))).join("&"):s.scheme+"://"+s.host+"/"+s.path}}(s)}

2.配置模块

注意需要修改配置中的www.example.com,至于各个客户端如何配置可以参考⚙ Enhanced · BiliUniverse或自行探索

(以下内容不保证100%正确)

①适用于surge和shadowrocket的模块:BiliBili.Roaming.beta.sgmodule

#!name=📺 BiliBili: ✈ Roaming β

#!desc=(BETA) 哔哩哔哩:漫游模式                      (播放链接反向代理)
#!openUrl=http://boxjs.com/#/app/BiliBili.Roaming.beta
#!author=VirgilClyne
#!homepage=https://github.com/BiliUniverse
#!manual=https://github.com/BiliUniverse/Roaming/wiki
#!icon=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/bilibili_3.png

[Script]
BiliBili.Roaming.season = type=http-request, pattern=^https?:\/\/api\.bilibili\.com\/pgc\/view\/v2\/app\/season?(\?.+)?$, requires-body=0, max-size=0, timeout=15, debug=1, script-path=https://www.example.com/BiliBili.Roaming.request.beta.js, argument=

BiliIntl.Roaming.grpc = type=http-request, type=http-request, pattern=^https?:\/\/grpc\.biliapi\.net\/bilibili\.pgc\.gateway\.player\.v2\.PlayURL\/PlayView(?:\?.*)?$, requires-body=0, max-size=0, timeout=15, debug=1, script-path=https://www.example.com/BiliBili.Roaming.request.beta.js, argument=

BiliIntl.Roaming.app = type=http-request, type=http-request, pattern=^https?:\/\/app\.bilibili\.com\/bilibili\.pgc\.gateway\.player\.v2\.PlayURL\/PlayView(?:\?.*)?$, requires-body=0, max-size=0, timeout=15, debug=1, script-path=https://www.example.com/BiliBili.Roaming.request.beta.js, argument=

BiliIntl.Roaming.search = type=http-request, type=http-request, pattern=^https?:\/\/app\.bilibili\.com\/bilibili\.polymer\.app\.search\.v1\.Search\/SearchByType(?:\?.*)?$, requires-body=0, max-size=0, timeout=15, debug=1, script-path=https://www.example.com/BiliBili.Roaming.request.beta.js, argument=

[MITM]
hostname = %APPEND% api.bilibili.com, grpc.biliapi.net, app.bilibili.com
tcp-connection = true

②适用于stash的覆写:BiliBili.Roaming.beta.sgmodule

name: "📺 BiliBili: ✈ Roaming β"
desc: (BETA) 哔哩哔哩:漫游模式                      (播放链接反向代理)
openUrl: http://boxjs.com/#/app/BiliBili.Roaming.beta
author: VirgilClyne
homepage: https://github.com/BiliUniverse
manual: https://github.com/BiliUniverse/Roaming/wiki
icon: https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/bilibili_3.png

http:
  mitm:
    - "api.bilibili.com"
    - "grpc.biliapi.net"
    - "app.bilibili.com"
  script:
    - match: ^https?:\/\/api\.bilibili\.com\/pgc\/view\/v2\/app\/season
      name: BiliBili.Roaming.request
      type: request
      require-body: false
      timeout: 15
      max-size: 0
    - match: ^https?:\/\/grpc\.biliapi\.net\/bilibili\.pgc\.gateway\.player\.v2\.PlayURL\/PlayView
      name: BiliBili.Roaming.request
      type: request
      require-body: false
      timeout: 15
      max-size: 0
    - match: ^https?:\/\/app\.bilibili\.com\/bilibili\.pgc\.gateway\.player\.v2\.PlayURL\/PlayView
      name: BiliBili.Roaming.request
      type: request
      require-body: false
      timeout: 15
      max-size: 0
    - match: ^https?:\/\/app\.bilibili\.com\/bilibili\.polymer\.app\.search\.v1\.Search\/SearchByType
      name: BiliBili.Roaming.request
      type: request
      require-body: false
      timeout: 15
      max-size: 0
script-providers:
  BiliBili.Roaming.request:
    url: https://www.example.com/BiliBili.Roaming.request.beta.js
    interval: 86400

③适用于Loon的插件:BiliBili.Roaming.beta.plugin

#!name=📺 BiliBili: ✈ Roaming β
#!desc=(BETA) 哔哩哔哩:漫游模式 (播放链接反向代理)
#!openUrl=http://boxjs.com/#/app/BiliBili.Roaming.beta
#!author=VirgilClyne
#!homepage=https://github.com/BiliUniverse
#!manual=https://github.com/BiliUniverse/Roaming/wiki
#!icon=https://raw.githubusercontent.com/Koolson/Qure/master/IconSet/Color/bilibili_3.png

[Script]
http-request ^https?://api.bilibili.com/pgc/view/v2/app/season(?.+)?$ requires-body=0, timeout=15, script-path=https://www.example.com/BiliBili.Roaming.request.beta.js, tag=BiliBili.Roaming.season, argument=

http-request ^https?://grpc.biliapi.net/bilibili.pgc.gateway.player.v2.PlayURL/PlayView(?.+)?$ requires-body=0, timeout=15, script-path=https://www.example.com/BiliBili.Roaming.request.beta.js, tag=BiliBili.Roaming.grpc, argument=

http-request ^https?://app.bilibili.com/bilibili.pgc.gateway.player.v2.PlayURL/PlayView(?.+)?$ requires-body=0, timeout=15, script-path=https://www.example.com/BiliBili.Roaming.request.beta.js, tag=BiliBili.Roaming.app, argument=

http-request ^https?://app.bilibili.com/bilibili.polymer.app.search.v1.Search/SearchByType(?.+)?$ requires-body=0, timeout=15, script-path=https://www.example.com/BiliBili.Roaming.request.beta.js, tag=BiliBili.Roaming.app, argument=

[MITM]
hostname = %APPEND% api.bilibili.com, grpc.biliapi.net, app.biliintl.com
tcp-connection = true

四、成果展示

image-20231112184134795

image-20231104212303814

image-20231104212313408

0

评论区