Skip to content

Commit

Permalink
fix(balh): 修复集数定位和国内错误跳转 (#1266)
Browse files Browse the repository at this point in the history
* fix new player

* fix

* fix client-app

* wip: 行尾不需要分号

* chore: update version

---------

Co-authored-by: ipcjs <gipcjs@gmail.com>
  • Loading branch information
MapleRecall and ipcjs authored Nov 27, 2023
1 parent 693084e commit 18a9786
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 25 deletions.
2 changes: 1 addition & 1 deletion packages/unblock-area-limit/src/api/biliplus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ export namespace BiliPlusApi {
code?: number
title: string
list: [{ page: string, cid: string, part: string }]
bangumi?: { season_id: string }
bangumi?: { season_id: string, ogv_play_url?: string }
}
export const view = function (aid: string, update = true) {
return Async.ajax<ViewResult>(`${balh_config.server}/api/view?id=${aid}&update=${update}${access_key_param_if_exist()}`);
Expand Down
57 changes: 36 additions & 21 deletions packages/unblock-area-limit/src/feature/bili/area_limit_for_vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ function fixBangumiPlayPage() {
cookieStorage.set('balh_curr_season_id', window?.__INITIAL_STATE__?.mediaInfo?.season_id, '')
}
if (util_page.anime_ep() || util_page.anime_ss()) {
const $app = document.getElementById('app')
// 旧版偶尔会出现client-app,why?
const $app = document.getElementById('app') || document.getElementById('client-app');
if ((!$app || invalidInitialState) && !window.__NEXT_DATA__) {
// 这个fixBangumiPlayPage()函数,本来是用来重建appOnly页面的,不过最近这样appOnly的页面基本上没有了,反而出现了一批非appOnly但页面也需要重建的情况
// 如:https://www.bilibili.com/bangumi/media/md28235576
Expand Down Expand Up @@ -332,7 +333,7 @@ function fixBangumiPlayPage() {
window.bangumi_area_limit_hack._setupSettings()
} catch (e) {
util_warn('重建ep页面失败', e)
ui.alert(Objects.stringify(e))
ui.alert(Objects.stringify(e as any))
}
}
}
Expand Down Expand Up @@ -430,27 +431,41 @@ export function area_limit_for_vue() {
function replaceNextData() {
modifyGlobalValue('__NEXT_DATA__', {
onWrite: (value) => {
const queries = value.props.pageProps.dehydratedState.queries
if (!queries) return value
for (const query of queries) {
const data = query.state.data
switch (query.queryKey[0]) {
case 'pgc/view/web/season':
// 最重要的一项数据, 直接决定页面是否可播放
Object.keys(data.epMap).forEach(epId => removeEpAreaLimit(data.epMap[epId]))
data.mediaInfo.episodes.forEach(removeEpAreaLimit)
// 其他字段对结果似乎没有影响, 故注释掉(
// data.mediaInfo.hasPlayableEp = true
// data.initEpList.forEach(removeEpAreaLimit)
// data.rights.area_limit = false
// data.rights.allow_dm = 1
break;
case 'season/user/status':
processUserStatus(data)
break;
// 结构变了很多,新版是SSR可能一开始会取不到或者是个dom,无论如何先try一下
try {
// 一开始是个dom,放里面一起try了
if (value instanceof Element) {
value = JSON.parse(value.innerHTML)
}
const queries = value.props.pageProps.dehydratedState.queries
if (!queries) return value
for (const query of queries) {
const data = query.state.data
switch (query.queryKey[0]) {
case 'pgc/view/web/season':
if (data.epMap) {
// 最重要的一项数据, 直接决定页面是否可播放
Object.keys(data.epMap).forEach(epId => removeEpAreaLimit(data.epMap[epId]))
data.mediaInfo.episodes.forEach(removeEpAreaLimit)
// 其他字段对结果似乎没有影响, 故注释掉(
// data.mediaInfo.hasPlayableEp = true
// data.initEpList.forEach(removeEpAreaLimit)
// data.rights.area_limit = false
// data.rights.allow_dm = 1
} else if (data.seasonInfo && !data.seasonInfo.mediaInfo.hasPlayableEp) {
// 新版全都没用了,干脆没有Playable的直接就替换掉
return;
}
break;
case 'season/user/status':
processUserStatus(data)
break;
}
}
return value
} catch {
return
}
return value
},
onRead: (value) => {
// debugger
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ export function redirect_to_bangumi_or_insert_player() {
// return Promise.reject('该AV号不属于任何番剧页');//No bangumi in api response
} else {
// 当前av属于番剧页面, 继续处理
season_id = data.bangumi.season_id;
return BiliPlusApi.season(season_id);
if (data.bangumi.ogv_play_url) {
// 有url直接跳转,不再请求一次了,顺带解决集数定位不对的问题
msg.innerText = '即将跳转到:' + data.bangumi.ogv_play_url
location.href = data.bangumi.ogv_play_url
} else {
season_id = data.bangumi.season_id;
return BiliPlusApi.season(season_id);
}
}
})
.then(function (result) {
Expand Down Expand Up @@ -92,6 +98,7 @@ export function redirect_to_bangumi_or_insert_player() {
episode_id = ep_id_by_cid || ep_id_by_aid_page || ep_id_by_aid
}
if (episode_id) {
// FIXME: 这种地址有可能不能定位到正确的集数
let bangumi_url = `//www.bilibili.com/bangumi/play/ss${season_id}#${episode_id}`
log('Redirect', 'aid:', aid, 'page:', page, 'cid:', cid, '==>', bangumi_url, 'season_id:', season_id, 'ep_id:', episode_id)
msg.innerText = '即将跳转到:' + bangumi_url
Expand Down
2 changes: 1 addition & 1 deletion packages/unblock-area-limit/src/main.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name 解除B站区域限制
// @namespace https://github.com/ipcjs
// @version 8.4.3
// @version 8.4.4
// @description 通过替换获取视频地址接口的方式, 实现解除B站区域限制;
// @author ipcjs
// @supportURL https://github.com/ipcjs/bilibili-helper/blob/user.js/packages/unblock-area-limit/README.md
Expand Down

0 comments on commit 18a9786

Please sign in to comment.