mirror of
https://gh-proxy.org/https://github.com/tiajinsha/JKVideo
synced 2026-07-07 23:18:38 +08:00
bug修改
This commit is contained in:
@@ -5,13 +5,35 @@ import type { PlayUrlResponse, DashAudioItem } from '../services/types';
|
||||
* 将 Bilibili DASH 响应写成 MPD 文件,返回 file:// URI 供 ExoPlayer 播放。
|
||||
* 选取 id === qn 的视频流(找不到则取第一条),带宽最高的音频流。
|
||||
*/
|
||||
export async function buildDashMpdUri(playData: PlayUrlResponse, qn: number): Promise<string> {
|
||||
export async function buildDashMpdUri(
|
||||
playData: PlayUrlResponse,
|
||||
qn: number,
|
||||
bvid?: string,
|
||||
): Promise<string> {
|
||||
const xml = buildMpdXml(playData, qn);
|
||||
const path = `${FileSystem.cacheDirectory}bili_dash_${qn}.mpd`;
|
||||
// 带 bvid 区分,避免不同视频在同一 qn 上复用同一文件名导致命中过期 MPD
|
||||
const suffix = bvid ? `${bvid}_${qn}` : String(qn);
|
||||
const path = `${FileSystem.cacheDirectory}bili_dash_${suffix}.mpd`;
|
||||
await FileSystem.writeAsStringAsync(path, xml, { encoding: FileSystem.EncodingType.UTF8 });
|
||||
return path;
|
||||
}
|
||||
|
||||
/** 删除指定视频的所有清晰度 MPD 缓存(详情页卸载时调用) */
|
||||
export async function cleanupDashMpd(bvid: string): Promise<void> {
|
||||
if (!bvid || !FileSystem.cacheDirectory) return;
|
||||
try {
|
||||
const files = await FileSystem.readDirectoryAsync(FileSystem.cacheDirectory);
|
||||
const targets = files.filter(f => f.startsWith(`bili_dash_${bvid}_`) && f.endsWith('.mpd'));
|
||||
await Promise.all(
|
||||
targets.map(f =>
|
||||
FileSystem.deleteAsync(`${FileSystem.cacheDirectory}${f}`, { idempotent: true }),
|
||||
),
|
||||
);
|
||||
} catch {
|
||||
// 忽略,缓存清理失败不影响功能
|
||||
}
|
||||
}
|
||||
|
||||
function isDolbyVision(codecs: string): boolean {
|
||||
return /^(dvhe|dvh1)/.test(codecs);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { VideoItem, LiveRoom } from '../services/types';
|
||||
import type { VideoItem } from '../services/types';
|
||||
|
||||
export interface NormalRow {
|
||||
type: 'pair';
|
||||
@@ -11,22 +11,14 @@ export interface BigRow {
|
||||
item: VideoItem;
|
||||
}
|
||||
|
||||
export interface LiveRow {
|
||||
type: 'live';
|
||||
left: LiveRoom;
|
||||
right?: LiveRoom;
|
||||
}
|
||||
export type ListRow = NormalRow | BigRow;
|
||||
|
||||
export type ListRow = NormalRow | BigRow | LiveRow;
|
||||
|
||||
export function toListRows(pages: VideoItem[][], liveRooms?: LiveRoom[]): ListRow[] {
|
||||
export function toListRows(pages: VideoItem[][]): ListRow[] {
|
||||
const rows: ListRow[] = [];
|
||||
let roomIdx = 0;
|
||||
|
||||
for (const chunk of pages) {
|
||||
if (chunk.length === 0) continue;
|
||||
|
||||
// Highest view count becomes BigRow
|
||||
let bigIdx = 0;
|
||||
let maxView = chunk[0].stat?.view ?? 0;
|
||||
for (let i = 1; i < chunk.length; i++) {
|
||||
@@ -37,36 +29,17 @@ export function toListRows(pages: VideoItem[][], liveRooms?: LiveRoom[]): ListRo
|
||||
const bigItem = chunk[bigIdx];
|
||||
const rest = chunk.filter((_, i) => i !== bigIdx);
|
||||
|
||||
const pairs: (NormalRow | LiveRow)[] = [];
|
||||
const pairs: NormalRow[] = [];
|
||||
for (let i = 0; i < rest.length; i += 2) {
|
||||
if (rest[i + 1]) {
|
||||
pairs.push({ type: 'pair', left: rest[i], right: rest[i + 1] ?? null });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (liveRooms && liveRooms.length >= 2) {
|
||||
const a = liveRooms[roomIdx % liveRooms.length];
|
||||
const b = liveRooms[(roomIdx + 1) % liveRooms.length];
|
||||
roomIdx += 2;
|
||||
|
||||
if (rows.length < 20) {
|
||||
rows.push({ type: 'big', item: bigItem });
|
||||
rows.push({ type: 'live', left: a, right: b });
|
||||
rows.push(...pairs);
|
||||
} else {
|
||||
rows.push(...pairs);
|
||||
rows.push({ type: 'big', item: bigItem });
|
||||
rows.push({ type: 'live', left: a, right: b });
|
||||
}
|
||||
if (rows.length < 20) {
|
||||
rows.push({ type: 'big', item: bigItem }, ...pairs);
|
||||
} else {
|
||||
// No live data, fall back to original logic
|
||||
if (rows.length < 20) {
|
||||
rows.push({ type: 'big', item: bigItem }, ...pairs);
|
||||
} else {
|
||||
rows.push(...pairs, { type: 'big', item: bigItem });
|
||||
}
|
||||
rows.push(...pairs, { type: 'big', item: bigItem });
|
||||
}
|
||||
}
|
||||
return rows;
|
||||
|
||||
Reference in New Issue
Block a user