mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-01 03:56:38 +08:00
优化界面,优化多版本切换逻辑
This commit is contained in:
@@ -1,4 +1,10 @@
|
||||
import { mediaVersionLabel } from './mediaVersion.ts'
|
||||
import {
|
||||
isStrmMedia,
|
||||
mediaVersionFileName,
|
||||
mediaVersionLabel,
|
||||
mediaVersionMatches,
|
||||
mediaVersionSourceLabel,
|
||||
} from './mediaVersion.ts'
|
||||
import type { Media } from '../types/index.ts'
|
||||
|
||||
function check(name: string, condition: boolean) {
|
||||
@@ -41,4 +47,21 @@ const dottedPart = mediaVersionLabel(media({
|
||||
}))
|
||||
check('part2 filename fallback keeps part token', dottedPart.includes('part2'))
|
||||
|
||||
// 折叠后的选集行 id 是最优版本;播放中的可能是组内另一个版本。
|
||||
const local4k = media({ id: 'v-4k', path: '/media/Inception.2010.2160p.mkv', height: 2160 })
|
||||
const local1080 = media({ id: 'v-1080', path: '/media/Inception.2010.1080p.mkv', height: 1080 })
|
||||
const cloudRow = media({ id: 'v-cloud', path: '/strm/Inception.2010.mkv.strm', strm_url: '/api/strm/play/cloud115/video.mkv?pickcode=a' })
|
||||
const groupedRow = media({ id: 'v-4k', versions: [local4k, local1080, cloudRow] })
|
||||
|
||||
check('matches own id', mediaVersionMatches(groupedRow, 'v-4k'))
|
||||
check('matches nested version id', mediaVersionMatches(groupedRow, 'v-1080'))
|
||||
check('rejects unrelated id', !mediaVersionMatches(groupedRow, 'v-other'))
|
||||
check('rejects empty id', !mediaVersionMatches(groupedRow, ''))
|
||||
|
||||
check('strm is cloud source', mediaVersionSourceLabel(cloudRow) === '云端直链')
|
||||
check('mkv is local source', mediaVersionSourceLabel(local1080) === '本地文件')
|
||||
check('strm filename drops outer extension', mediaVersionFileName(cloudRow) === 'Inception.2010.mkv')
|
||||
check('missing path has no filename', mediaVersionFileName(media({ path: '' })) === '')
|
||||
check('isStrmMedia detects strm url', isStrmMedia(cloudRow))
|
||||
|
||||
console.log('mediaVersion.test.ts: ok')
|
||||
|
||||
@@ -176,3 +176,30 @@ export function mediaVersionsOf(media: Media | null | undefined): Media[] {
|
||||
if (media.versions && media.versions.length > 1) return media.versions
|
||||
return [media]
|
||||
}
|
||||
|
||||
/**
|
||||
* media 自身或它的任一版本是否命中 id。
|
||||
*
|
||||
* 选集列表按「版本组」折叠后,行的 id 是该组首个(最优)版本;用户切到
|
||||
* 组内其它版本时播放中的 id 与行 id 不再相等,必须连带比对 versions,
|
||||
* 否则当前集高亮、上一集/下一集都会失效。
|
||||
*/
|
||||
export function mediaVersionMatches(media: Media | null | undefined, id: string): boolean {
|
||||
if (!media || !id) return false
|
||||
if (media.id === id) return true
|
||||
return Boolean(media.versions?.some((version) => version.id === id))
|
||||
}
|
||||
|
||||
/** 版本来源:云端(STRM / 网盘直链)或本地文件。 */
|
||||
export function mediaVersionSourceLabel(media: Media): string {
|
||||
return isStrmMedia(media) ? '云端直链' : '本地文件'
|
||||
}
|
||||
|
||||
/** 版本文件名(去掉目录,并剥掉 .strm 外层扩展名),用作版本选项的次要说明。 */
|
||||
export function mediaVersionFileName(media: Media): string {
|
||||
const path = (media.path || '').replace(/\\/g, '/').trim()
|
||||
if (!path) return ''
|
||||
const base = path.split('/').filter(Boolean).pop() || ''
|
||||
if (!base) return ''
|
||||
return base.replace(/\.strm$/i, '')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user