feat(strm): 同名多版本择优 / keep_ext,并支持合并展示与播放切换 (#30)

* feat(strm): 同名多版本择优/keep_ext,并支持合并展示与播放切换

默认对同名不同扩展(如 .mkv/.mp4)按体积→mtime→扩展名优先级择优生成一条 strm,冲突打日志;开启 keep_ext 则分别生成 name.ext.strm。媒体详情与播放器可切换版本,列表继续合并同片多版本,Emby MediaSources 名称区分容器/分辨率。

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

* fix(meta): 边车匹配忽略 .mkv.strm 中间扩展,同片共享 NFO/海报/字幕

NFO、海报、字幕与刮削写出统一使用 mediaSidecarBase 词干,使竞女01.mkv.strm
与竞女01.mp4.strm 配对同一套 竞女01.nfo / 竞女01-poster / 竞女01.srt;
仍兼容历史上的 name.mkv.nfo 命名。

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

* fix(emby): People NFO 按共享词干匹配 keep_ext strm

resolveMediaPeople 改为查找竞女01.nfo(并兼容旧的竞女01.mkv.nfo),
同时修正把 decodeNFOFile 的 partial 误当 ok 导致完整 NFO 被跳过的问题。

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: truewhile <truewhile@users.noreply.github.com>
This commit is contained in:
truewhile
2026-09-07 13:56:30 +08:00
committed by GitHub
parent 6bf8a6878a
commit 38b85bb487
32 changed files with 1045 additions and 167 deletions
@@ -0,0 +1,72 @@
import { Layers } from 'lucide-react'
import { Link } from 'react-router-dom'
import type { Media } from '../types'
import { mediaVersionLabel, mediaVersionsOf } from '../utils/mediaVersion'
type MediaVersionSwitcherProps = {
media: Media
/** 详情页:用 Link 跳转播放;播放页:回调切换 */
mode?: 'detail' | 'player'
onSelect?: (version: Media) => void
className?: string
}
export function MediaVersionSwitcher({
media,
mode = 'detail',
onSelect,
className = '',
}: MediaVersionSwitcherProps) {
const versions = mediaVersionsOf(media)
if (versions.length <= 1) return null
const dark = mode === 'player'
return (
<div className={`space-y-2 ${className}`.trim()}>
<div className={`flex items-center gap-2 text-sm font-semibold ${dark ? 'text-white/90' : 'text-ink-600'}`}>
<Layers size={14} className={dark ? 'text-white/60' : 'text-sand-500'} />
<span>版本({versions.length})</span>
</div>
<div className="flex flex-wrap gap-2">
{versions.map((version) => {
const active = version.id === media.id
const label = mediaVersionLabel(version)
const className = dark
? active
? 'border-white/40 bg-white/20 text-white'
: 'border-white/15 bg-white/5 text-white/80 hover:bg-white/15'
: active
? 'border-brand-500/40 bg-brand-50 text-[#b07d35]'
: 'border-gray-200 bg-white text-ink-100 hover:border-brand-500/30 hover:bg-brand-50/40'
if (mode === 'player') {
return (
<button
key={version.id}
type="button"
disabled={active}
onClick={() => onSelect?.(version)}
className={`rounded-xl border px-3 py-1.5 text-xs font-semibold transition disabled:cursor-default ${className}`}
title={version.path}
>
{label}
</button>
)
}
return (
<Link
key={version.id}
to={`/play/${version.id}`}
state={{ from: `/media/${media.id}` }}
className={`rounded-xl border px-3 py-1.5 text-xs font-semibold transition ${className}`}
title={version.path}
>
{label}
{active ? ' · 当前' : ''}
</Link>
)
})}
</div>
</div>
)
}
@@ -5,6 +5,7 @@ import { PageBackButton } from '../components/PageBackButton'
import { ExternalPlayerButton } from '../components/ExternalPlayerButton'
import { ManualScrapeDialog } from '../components/ManualScrapeDialog'
import { MediaVersionSwitcher } from '../components/MediaVersionSwitcher'
import { MetadataEditDialog } from '../components/MetadataEditDialog'
import { OrganizeMediaDialog } from '../components/OrganizeMediaDialog'
import type { Media } from '../types'
@@ -163,6 +164,7 @@ export function MediaDetailMainContent({
onToggleFavourite={onToggleFavourite}
playTargetId={playTargetId}
/>
<MediaVersionSwitcher media={media} mode="detail" />
{isAdmin && (
<MediaDetailAdminPanel
media={media}
+18
View File
@@ -18,6 +18,8 @@ import { PlayerTopBar } from './PlayerTopBar'
import { PlayerVideoStage } from './PlayerVideoStage'
import { PlayerDanmakuPanel } from '../components/PlayerDanmakuPanel'
import { PlayerPlaylistPanel } from '../components/PlayerPlaylistPanel'
import { MediaVersionSwitcher } from '../components/MediaVersionSwitcher'
import { mediaVersionsOf } from '../utils/mediaVersion'
// Fullscreen, dark-themed video page.
//
@@ -420,6 +422,15 @@ export function PlayerPage() {
[navigate, location.search, location.state],
)
const versionList = useMemo(() => mediaVersionsOf(media), [media])
const switchVersion = useCallback(
(version: Media) => {
if (!version?.id || version.id === media?.id) return
playEpisode(version)
},
[media?.id, playEpisode],
)
const handlePrevEpisode = useCallback(() => {
if (prevEpisode) {
playEpisode(prevEpisode)
@@ -575,6 +586,13 @@ export function PlayerPage() {
onBack={goBack}
onToggleMode={toggleMode}
/>
{versionList.length > 1 && (
<div className="pointer-events-none absolute inset-x-0 top-16 z-20 flex justify-center px-4 sm:top-20">
<div className="pointer-events-auto max-w-3xl rounded-2xl border border-white/15 bg-black/70 px-3 py-2 shadow-xl backdrop-blur">
<MediaVersionSwitcher media={media!} mode="player" onSelect={switchVersion} className="text-white" />
</div>
</div>
)}
<PlayerVideoStage
media={media}
loadError={loadError}
+25
View File
@@ -509,6 +509,12 @@ const SETTING_DEFS: SettingDef[] = [
{ value: '3', label: '不带 path' },
],
},
{
key: 'strm.keep_ext',
label: '保留视频扩展名(多版本)',
type: 'toggle',
hint: '关闭(默认):同名不同扩展(如 竞女01.mkv / 竞女01.mp4)择优生成一条 name.strm;开启:分别生成 name.mkv.strm / name.mp4.strm,保留全部版本供播放切换',
},
{ key: 'strm.115_relay_key', label: '115 中继授权共享密钥', type: 'text', hint: 'QMediaSync/MQFamily 中继授权的共享 AES 密钥;不配置则中继授权不可用' },
{ key: 'strm.download_threads', label: '下载队列线程数', type: 'number', hint: '元数据下载并发数' },
{ key: 'strm.upload_threads', label: '上传队列线程数', type: 'number', hint: '元数据上传并发数' },
@@ -610,6 +616,7 @@ export function StrmSyncPathDialog({
download_meta: existing?.download_meta ?? true,
upload_meta: existing?.upload_meta ?? false,
delete_dir: existing?.delete_dir ?? false,
keep_ext: existing?.keep_ext ?? false,
cron: existing?.cron ?? '',
enable_cron: existing?.enable_cron ?? false,
sync_mode: existing?.sync_mode ?? 'incremental',
@@ -628,6 +635,19 @@ export function StrmSyncPathDialog({
// 兼容两类历史数据:新版保存的 local_path 末段是目录名,旧版是目录 ID。
const prevRemoteTailRef = useRef(existing ? initRemoteTail(existing) : '')
useEffect(() => {
if (existing) return
strmAPI
.getSettings()
.then((settings) => {
const keepExt = settings['strm.keep_ext']
if (keepExt === 'true' || keepExt === '1') {
setForm((f) => ({ ...f, keep_ext: true }))
}
})
.catch(() => undefined)
}, [existing])
const set = <K extends keyof StrmSyncPathInput>(key: K, value: StrmSyncPathInput[K]) =>
setForm((f) => ({ ...f, [key]: value }))
@@ -917,6 +937,11 @@ export function StrmSyncPathDialog({
<ToggleRow label="下载元数据" checked={form.download_meta ?? true} onChange={(v) => set('download_meta', v)} />
<ToggleRow label="上传元数据" checked={form.upload_meta ?? false} onChange={(v) => set('upload_meta', v)} />
<ToggleRow label="清理空目录" checked={form.delete_dir ?? false} onChange={(v) => set('delete_dir', v)} />
<ToggleRow
label="保留视频扩展名(多版本)"
checked={form.keep_ext ?? false}
onChange={(v) => set('keep_ext', v)}
/>
<ToggleRow label="启用定时同步" checked={form.enable_cron ?? false} onChange={(v) => set('enable_cron', v)} />
<ToggleRow label="启用该目录" checked={form.enabled ?? true} onChange={(v) => set('enabled', v)} />
</div>
+3
View File
@@ -70,6 +70,7 @@ export interface StrmSyncPath {
download_meta: boolean
upload_meta: boolean
delete_dir: boolean
keep_ext: boolean
cron: string
enable_cron: boolean
sync_mode?: 'incremental' | 'full'
@@ -98,6 +99,7 @@ export interface StrmSyncPathInput {
download_meta?: boolean
upload_meta?: boolean
delete_dir?: boolean
keep_ext?: boolean
cron?: string
enable_cron?: boolean
sync_mode?: 'incremental' | 'full'
@@ -167,6 +169,7 @@ export interface StrmSettingsMap {
'strm.download_meta': string
'strm.upload_meta': string
'strm.delete_dir': string
'strm.keep_ext': string
'strm.download_threads': string
'strm.upload_threads': string
[key: string]: string
+60
View File
@@ -0,0 +1,60 @@
import type { Media } from '../types'
/** 从路径 / strm URL 推断容器扩展名(mkv/mp4…)。 */
export function mediaVersionContainer(media: Media): string {
const path = (media.path || '').replace(/\\/g, '/')
const base = path.split('/').pop() || ''
const ext = base.includes('.') ? base.slice(base.lastIndexOf('.')).toLowerCase() : ''
let name = ext ? base.slice(0, -ext.length) : base
if (ext === '.strm') {
const second = name.includes('.') ? name.slice(name.lastIndexOf('.')).toLowerCase() : ''
if (second && second !== '.strm') {
return second.replace(/^\./, '')
}
const strm = (media.strm_url || '').toLowerCase()
const marker = '/video.'
const idx = strm.lastIndexOf(marker)
if (idx >= 0) {
let rest = strm.slice(idx + marker.length)
const end = rest.search(/[?#&/]/)
if (end >= 0) rest = rest.slice(0, end)
rest = rest.replace(/^\./, '').trim()
if (rest) return rest
}
return 'strm'
}
return ext.replace(/^\./, '')
}
function formatSize(bytes: number): string {
if (!bytes || bytes < 1024) return bytes ? `${bytes} B` : ''
const units = ['KB', 'MB', 'GB', 'TB']
let value = bytes
let unit = -1
do {
value /= 1024
unit += 1
} while (value >= 1024 && unit < units.length - 1)
return `${value.toFixed(1)} ${units[unit]}`
}
/** 版本切换展示名:分辨率 · 容器 · 编码 · 体积,缺省回退文件名。 */
export function mediaVersionLabel(media: Media): string {
const parts: string[] = []
if (media.height > 0) parts.push(`${media.height}p`)
else if (media.width > 0) parts.push(`${media.width}w`)
const container = mediaVersionContainer(media)
if (container && container !== 'strm') parts.push(container.toUpperCase())
if (media.video_codec?.trim()) parts.push(media.video_codec.trim().toUpperCase())
const size = formatSize(media.size_bytes)
if (size) parts.push(size)
if (parts.length > 0) return parts.join(' · ')
const base = (media.path || '').replace(/\\/g, '/').split('/').pop()
return base || media.title || media.id
}
export function mediaVersionsOf(media: Media | null | undefined): Media[] {
if (!media) return []
if (media.versions && media.versions.length > 1) return media.versions
return [media]
}