From 18a9786645bf70cb62fc3934f7b1100712746f5a Mon Sep 17 00:00:00 2001 From: FatChocobo Date: Tue, 28 Nov 2023 00:00:10 +0800 Subject: [PATCH] =?UTF-8?q?fix(balh):=20=E4=BF=AE=E5=A4=8D=E9=9B=86?= =?UTF-8?q?=E6=95=B0=E5=AE=9A=E4=BD=8D=E5=92=8C=E5=9B=BD=E5=86=85=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E8=B7=B3=E8=BD=AC=20(#1266)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix new player * fix * fix client-app * wip: 行尾不需要分号 * chore: update version --------- Co-authored-by: ipcjs --- .../unblock-area-limit/src/api/biliplus.ts | 2 +- .../src/feature/bili/area_limit_for_vue.ts | 57 ++++++++++++------- .../redirect_to_bangumi_or_insert_player.ts | 11 +++- packages/unblock-area-limit/src/main.user.js | 2 +- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/packages/unblock-area-limit/src/api/biliplus.ts b/packages/unblock-area-limit/src/api/biliplus.ts index 599cc9a7..71d0ea21 100644 --- a/packages/unblock-area-limit/src/api/biliplus.ts +++ b/packages/unblock-area-limit/src/api/biliplus.ts @@ -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(`${balh_config.server}/api/view?id=${aid}&update=${update}${access_key_param_if_exist()}`); diff --git a/packages/unblock-area-limit/src/feature/bili/area_limit_for_vue.ts b/packages/unblock-area-limit/src/feature/bili/area_limit_for_vue.ts index 66231c98..813a2c92 100644 --- a/packages/unblock-area-limit/src/feature/bili/area_limit_for_vue.ts +++ b/packages/unblock-area-limit/src/feature/bili/area_limit_for_vue.ts @@ -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 @@ -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)) } } } @@ -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 diff --git a/packages/unblock-area-limit/src/feature/bili/redirect_to_bangumi_or_insert_player.ts b/packages/unblock-area-limit/src/feature/bili/redirect_to_bangumi_or_insert_player.ts index 10de15d4..feca2bd8 100644 --- a/packages/unblock-area-limit/src/feature/bili/redirect_to_bangumi_or_insert_player.ts +++ b/packages/unblock-area-limit/src/feature/bili/redirect_to_bangumi_or_insert_player.ts @@ -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) { @@ -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 diff --git a/packages/unblock-area-limit/src/main.user.js b/packages/unblock-area-limit/src/main.user.js index 9097853c..348e7d80 100644 --- a/packages/unblock-area-limit/src/main.user.js +++ b/packages/unblock-area-limit/src/main.user.js @@ -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