Skip to content

Commit b9551bb

Browse files
Howard20181ipcjs
andauthored
fix(balh): 修复其他地区无法播放仅限大陆番剧 (#1300)
* fix(balh): 修复其他地区无法播放仅限大陆番剧 * wip: 整理代码 --------- Co-authored-by: ipcjs <[email protected]>
1 parent 3eb0ec6 commit b9551bb

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

packages/unblock-area-limit/src/feature/bili/area_limit_for_vue.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AppSeasonInfo, BiliBiliApi } from "../../api/bilibili"
1+
import { BiliBiliApi } from "../../api/bilibili"
22
import { BiliPlusApi } from "../../api/biliplus"
33
import { Converters } from "../../util/converters"
44
import { cookieStorage } from "../../util/cookie"
@@ -413,10 +413,10 @@ export function removeEpAreaLimit(ep: StringAnyObject) {
413413
ep.epRights.allow_dm = 1
414414
}
415415
if (ep.rights) {
416-
ep.rights.area_limit = false
416+
ep.rights.area_limit = 0
417417
ep.rights.allow_dm = 1
418418
}
419-
if (ep.badge === '受限') {
419+
if (ep.badge === '受限' || ep.badge_info.text === '受限') {
420420
ep.badge = ''
421421
ep.badge_info = { "bg_color": "#FB7299", "bg_color_night": "#BB5B76", "text": "" }
422422
ep.badge_type = 0
@@ -505,6 +505,8 @@ export function area_limit_for_vue() {
505505
// data.initEpList.forEach(removeEpAreaLimit)
506506
// data.rights.area_limit = false
507507
// data.rights.allow_dm = 1
508+
} else if (data.seasonInfo.mediaInfo.episodes.length > 0) {
509+
data.seasonInfo.mediaInfo.episodes.forEach(removeEpAreaLimit)
508510
} else if (data.seasonInfo && !data.seasonInfo.mediaInfo.rights.can_watch) {
509511
// 新版没有Playable的是预告 PV,不能直接跳过,can_watch=false 才替换
510512
return;

packages/unblock-area-limit/src/feature/bili/area_limit_xhr_.ts

+17-25
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ import { Converters, uposMap } from '../../util/converters';
44
import { _ } from '../../util/react'
55
import { Async, Promise } from '../../util/async';
66
import { r, _t } from '../../feature/r'
7-
import { util_error, util_info, util_log, util_warn, util_debug, logHub } from '../../util/log'
7+
import { util_error, util_warn, log } from '../../util/log'
88
import { cookieStorage } from '../../util/cookie'
99
import { balh_config, isClosed } from '../../feature/config'
10-
import { Func } from '../../util/utils';
1110
import { util_page } from '../../feature/page'
1211
import { access_key_param_if_exist, platform_android_param_if_app_only } from '../../api/bilibili-utils'
13-
import { BiliPlusApi, generateMobiPlayUrlParams, getMobiPlayUrl, fixMobiPlayUrlJson, fixThailandPlayUrlJson } from '../../api/biliplus'
12+
import { generateMobiPlayUrlParams, getMobiPlayUrl, fixMobiPlayUrlJson, fixThailandPlayUrlJson } from '../../api/biliplus'
1413
import { ui } from '../../util/ui'
1514
import { Strings } from '../../util/strings'
1615
import { util_init } from '../../util/initiator'
@@ -43,23 +42,23 @@ export const area_limit_xhr = (() => {
4342
/// {@endtemplate}
4443
transformResponse: ({ url, response, xhr, container }) => {
4544
if (url.match(RegExps.url('api.bilibili.com/pgc/view/web/season?'))) {
46-
log('/pgc/view/web/season:', xhr.responseText)
4745
let json = JSON.parse(xhr.responseText)
4846
if (json.code === 0 && json.result) {
4947
// processSeasonInfo(json.result)
5048
json.result.episodes.forEach(removeEpAreaLimit)
51-
json.result.rights.area_limit = false
49+
json.result.rights.area_limit = 0
50+
json.result.rights.ban_area_show = 0
5251
return json
5352
}
5453
} else if (url.match(RegExps.url('bangumi.bilibili.com/view/web_api/season/user/status'))
5554
|| url.match(RegExps.url('api.bilibili.com/pgc/view/web/season/user/status'))) {
56-
log('/season/user/status:', xhr.responseText)
5755
let json = JSON.parse(xhr.responseText)
5856
let rewriteResult = false
5957
if (json.code === 0 && json.result) {
6058
areaLimit(json.result.area_limit !== 0)
6159
if (json.result.area_limit !== 0) {
6260
json.result.area_limit = 0 // 取消区域限制
61+
json.result.ban_area_show = 0
6362
rewriteResult = true
6463
}
6564
if (balh_config.blocked_vip) {
@@ -211,24 +210,26 @@ export const area_limit_xhr = (() => {
211210
log('/x/player/playurl', 'origin', `block: ${container.__block_response}`, xhr.response)
212211
// todo : 当前只实现了r.const.mode.REPLACE, 需要支持其他模式
213212
// 2018-10-14: 等B站全面启用新版再说(;¬_¬)
214-
} else if (url.match(RegExps.url('api.bilibili.com/pgc/player/web/playurl'))
213+
} else if (url.match(RegExps.url('api.bilibili.com/pgc/player/web/playurl')) || url.match(RegExps.url('api.bilibili.com/pgc/player/web/v2/playurl'))
215214
&& !Strings.getSearchParam(url, 'balh_ajax')) {
216-
log('/pgc/player/web/playurl', 'origin', `block: ${container.__block_response}`, xhr.response)
217-
if (!container.__redirect) { // 请求没有被重定向, 则需要检测结果是否有区域限制
218-
let json = typeof xhr.response === 'object' ? xhr.response : JSON.parse(xhr.responseText)
215+
const reqUrl = new URL(url, document.location.href)
216+
const isV1 = reqUrl.pathname === '/pgc/player/web/playurl'
217+
let json = typeof xhr.response === 'object' ? xhr.response : JSON.parse(xhr.responseText)
218+
if (!container.__redirect || (!isV1 && isAreaLimitForPlayUrl(json.result))) { // 请求没有被重定向, 则需要检测结果是否有区域限制
219219
if (balh_config.blocked_vip || json.code || isAreaLimitForPlayUrl(json.result)) {
220220
areaLimit(true)
221221
// 2022-09-17 ipcjs: 为什么这里用的是请求url, 而不是响应url?...
222-
let requestUrl = container.__url
222+
let requestUrl = isV1 ? container.__url : `//api.bilibili.com/pgc/player/web/playurl${reqUrl.search}`
223223
if (isBangumiPage()) {
224224
requestUrl += `&module=bangumi`
225225
}
226226
return bilibiliApis._playurl.asyncAjax(requestUrl)
227227
.then(data => {
228228
if (!data.code) {
229-
data = { code: 0, result: data, message: "0" }
229+
data = isV1
230+
? { code: 0, result: data, message: "0" }
231+
: { code: 0, message: "success", result: { video_info: data } }
230232
}
231-
log('/pgc/player/web/playurl', 'proxy', data)
232233
return data
233234
})
234235
} else {
@@ -288,7 +289,6 @@ export const area_limit_xhr = (() => {
288289
} else if (url.match(RegExps.url('api.bilibili.com/pgc/player/web/playurl'))
289290
&& !Strings.getSearchParam(url, 'balh_ajax')
290291
&& needRedirect()) {
291-
log('/pgc/player/web/playurl')
292292
// debugger
293293
container.__redirect = true // 标记该请求被重定向
294294
if (isBangumiPage()) {
@@ -297,13 +297,8 @@ export const area_limit_xhr = (() => {
297297
return bilibiliApis._playurl.asyncAjax(url)
298298
.then(data => {
299299
if (!data.code) {
300-
data = {
301-
code: 0,
302-
result: data,
303-
message: "0",
304-
}
300+
data = { code: 0, result: data, message: "0" }
305301
}
306-
log('/pgc/player/web/playurl', 'proxy(redirect)', data)
307302
return data
308303
})
309304
}
@@ -337,7 +332,6 @@ export const area_limit_xhr = (() => {
337332
let oriResultTransformer
338333
let oriResultTransformerWhenProxyError
339334
let one_api;
340-
// log(param)
341335
if (param.url.match(RegExps.urlPath('/web_api/get_source'))) {
342336
one_api = bilibiliApis._get_source;
343337
oriResultTransformer = p => p
@@ -372,7 +366,6 @@ export const area_limit_xhr = (() => {
372366
param.data = undefined
373367
}
374368
if (isBangumiPage()) {
375-
log(`playurl add 'module=bangumi' param`)
376369
param.url += `&module=bangumi`
377370
}
378371
// 加上这个参数, 防止重复拦截这个url
@@ -385,7 +378,6 @@ export const area_limit_xhr = (() => {
385378
}
386379
oriResultTransformer = p => p
387380
.then(json => {
388-
log(json)
389381
if (isNewPlayurl && !json.code) {
390382
json = json.result
391383
}
@@ -536,7 +528,7 @@ export const area_limit_xhr = (() => {
536528
}
537529

538530
function isBangumiPage() {
539-
const mediaInfo = window.__INITIAL_STATE__?.mediaInfo
531+
const mediaInfo = window.__INITIAL_STATE__?.mediaInfo || window.__NEXT_DATA__?.props.pageProps.dehydratedState?.queries[0]?.state.data.seasonInfo?.mediaInfo
540532
return isBangumi(mediaInfo?.season_type || mediaInfo?.ssType)
541533
}
542534

@@ -606,7 +598,7 @@ export const area_limit_xhr = (() => {
606598
}
607599

608600
function isAreaLimitForPlayUrl(json) {
609-
return (json.errorcid && json.errorcid == '8986943') || (json.durl && json.durl.length === 1 && json.durl[0].length === 15126 && json.durl[0].size === 124627);
601+
return (json.errorcid && json.errorcid == '8986943') || (json.durl && json.durl.length === 1 && json.durl[0].length === 15126 && json.durl[0].size === 124627) || !json.video_info;
610602
}
611603

612604
var bilibiliApis = (function () {

0 commit comments

Comments
 (0)