feat(subtitle): 文本字幕外置化仅限 TRANSCODE 源;右键菜单合并为级联子菜单

- 内嵌 ASS 抽取与字体抽取挂到 verdict == TRANSCODE(extract-subs /
  --extract-internal 仍可强制),直传片源不再生成外挂副本
- 外挂 SRT 兜底仅在 [Subtitles] export 不含 ass 时启用,避免同语言双份
- 新增同语言判重(含旧命名 <stem>.<lang>.srt),重复抽取不再产生重复字幕
- 识别中英双语轨为 zh-en,语言白名单加入 zh-en
- 外挂字幕统一 <stem>.internal.<lang>.srt 命名
- 右键菜单合并为 SceneMarshal 级联子菜单(ExtendedSubCommandsKey),
  四项:媒体整理 / 媒体归档 / 补外挂字幕 / 入库校验,图标 assets/menu 自绘
- HANDOFF 补右键菜单说明;新增 docs/movie-duplicates.md 记录电影库清理
This commit is contained in:
ali
2026-11-19 13:55:33 +08:00
parent fe5e211222
commit a57a392d7a
17 changed files with 375 additions and 67 deletions
+103 -24
View File
@@ -1,21 +1,36 @@
#Requires -Version 7.0
<#
.SYNOPSIS
在 Windows 资源管理器右键菜单里注册 SceneMarshal 的「重命名」「归档」两项。
在 Windows 资源管理器右键菜单注册 SceneMarshal 菜单(当前用户,无需管理员)。
.DESCRIPTION
只写 HKCU(当前用户),不需要管理员权限,可随时用 uninstall-explorer-menu.ps1 移除。
注册位置(每处两个菜单项):
HKCU\Software\Classes\Directory\shell\<Key> (文件夹右键)
HKCU\Software\Classes\Directory\Background\shell\<Key> (文件夹空白处右键)
HKCU\Software\Classes\SystemFileAssociations\.mkv\shell\<Key>
默认注册成「SceneMarshal ▸」级联子菜单,子项:
1. 重命名(自动) → auto
2. 归档… → media-archive(交互选分类)
3. 补外挂字幕(转码片源) → extract-subs
4. 入库前体检(只读) → check
级联写法与 Windows 自带项(UpdateEncryptionSettingsWork)一致:
父键上写 ExtendedSubCommandsKey = 该键自身的 HKCR 相对路径,子项放在父键的 Shell\ 下。
注册位置(每处一个父菜单):
HKCU\Software\Classes\Directory\shell\SceneMarshal (文件夹右键)
HKCU\Software\Classes\Directory\Background\shell\SceneMarshal (文件夹空白处右键)
HKCU\Software\Classes\SystemFileAssociations\.mkv\shell\SceneMarshal
... 同上 .mp4 / .avi(文件右键,取其所在目录)
.PARAMETER Flat
兜底模式:不级联,直接注册 4 个平级菜单项(名称带「SceneMarshal ▸ 」前缀)。
.EXAMPLE
.\install-explorer-menu.ps1
.EXAMPLE
.\install-explorer-menu.ps1 -Flat
#>
[CmdletBinding()]
param()
param(
[switch]$Flat
)
$ErrorActionPreference = 'Stop'
@@ -35,37 +50,101 @@ $repoRoot = Split-Path -Parent $PSScriptRoot
$iconPath = Join-Path $repoRoot 'assets\scenemarshal.ico'
if (-not (Test-Path -LiteralPath $iconPath)) { $iconPath = $pwsh }
$actions = @(
@{ Key = 'SceneMarshal'; Text = 'SceneMarshal 重命名'; Action = 'rename' },
@{ Key = 'SceneMarshalArchive'; Text = 'SceneMarshal 归档'; Action = 'archive' }
$menuName = 'SceneMarshal'
$iconsDir = Join-Path $repoRoot 'assets\menu'
function Get-ItemIcon([string]$name) {
$p = Join-Path $iconsDir $name
if (Test-Path -LiteralPath $p) { return $p }
return $iconPath
}
# 级联子项:ExtendedSubCommandsKey 模式下 Explorer 取 MUIVerb 作为显示名
$items = @(
@{ Key = '01-rename'; Text = '媒体整理'; Action = 'rename'; Icon = (Get-ItemIcon 'rename.ico') },
@{ Key = '02-archive'; Text = '媒体归档'; Action = 'archive'; Icon = (Get-ItemIcon 'archive.ico') },
@{ Key = '03-extract-subs'; Text = '补外挂字幕'; Action = 'extract-subs'; Icon = (Get-ItemIcon 'subtitle.ico') },
@{ Key = '04-check'; Text = '入库校验'; Action = 'check'; Icon = (Get-ItemIcon 'check.ico') }
)
# Relative = ExtendedSubCommandsKey 的值(相对 HKEY_CLASSES_ROOT),同时用于定位注册表路径
$locations = @(
@{ Shell = 'HKCU:\Software\Classes\Directory\shell'; Token = '%1' },
@{ Shell = 'HKCU:\Software\Classes\Directory\Background\shell'; Token = '%V' },
@{ Shell = 'HKCU:\Software\Classes\SystemFileAssociations\.mkv\shell'; Token = '%1' },
@{ Shell = 'HKCU:\Software\Classes\SystemFileAssociations\.mp4\shell'; Token = '%1' },
@{ Shell = 'HKCU:\Software\Classes\SystemFileAssociations\.avi\shell'; Token = '%1' }
@{ Relative = 'Directory\shell\SceneMarshal'; Token = '%1' },
@{ Relative = 'Directory\Background\shell\SceneMarshal'; Token = '%V' },
@{ Relative = 'SystemFileAssociations\.mkv\shell\SceneMarshal'; Token = '%1' },
@{ Relative = 'SystemFileAssociations\.mp4\shell\SceneMarshal'; Token = '%1' },
@{ Relative = 'SystemFileAssociations\.avi\shell\SceneMarshal'; Token = '%1' }
)
function New-MenuCommand([string]$Action, [string]$Token) {
'"' + $pwsh + '" -NoLogo -NoProfile -File "' + $runner + '" -Action ' + $Action + ' -Pause "' + $Token + '"'
}
function Get-RegPath([string]$relative) {
return "HKCU:\Software\Classes\$relative"
}
# ---------------------------------------------------------------- 清理旧结构
foreach ($loc in $locations) {
foreach ($item in $actions) {
$key = Join-Path $loc.Shell $item.Key
$commandKey = Join-Path $key 'command'
New-Item -Path $key -Force | Out-Null
foreach ($name in @($menuName, 'SceneMarshalArchive')) {
$old = Join-Path (Split-Path -Parent (Get-RegPath $loc.Relative)) $name
if (Test-Path -LiteralPath $old) { Remove-Item -LiteralPath $old -Recurse -Force }
}
# 兜底模式的平级项
$shellOf = Split-Path -Parent (Get-RegPath $loc.Relative)
Get-ChildItem -LiteralPath $shellOf -ErrorAction SilentlyContinue |
Where-Object { $_.PSChildName -like 'SceneMarshal-*' } |
ForEach-Object { Remove-Item -LiteralPath $_.PSPath -Recurse -Force }
}
# 早期尝试留下的共享子菜单键
foreach ($sub in @('SceneMarshalMenu', 'SceneMarshalMenuBg')) {
$old = "HKCU:\Software\Classes\$sub"
if (Test-Path -LiteralPath $old) { Remove-Item -LiteralPath $old -Recurse -Force }
}
# ---------------------------------------------------------------- 注册
foreach ($loc in $locations) {
$parent = Get-RegPath $loc.Relative
if (-not (Test-Path -LiteralPath $parent)) { New-Item -Path $parent -Force | Out-Null }
if ($Flat) {
# 兜底:每个位置注册 4 个平级项
foreach ($item in $items) {
$key = Join-Path $parent ("SceneMarshal-{0}" -f $item.Action)
$commandKey = Join-Path $key 'command'
New-Item -Path $commandKey -Force | Out-Null
New-ItemProperty -Path $key -Name 'MUIVerb' -Value ("$menuName ▸ " + $item.Text) -PropertyType String -Force | Out-Null
New-ItemProperty -Path $key -Name 'Icon' -Value $item.Icon -PropertyType String -Force | Out-Null
New-ItemProperty -Path $commandKey -Name '(default)' -Value (New-MenuCommand $item.Action $loc.Token) -PropertyType String -Force | Out-Null
}
continue
}
New-ItemProperty -Path $parent -Name 'MUIVerb' -Value $menuName -PropertyType String -Force | Out-Null
New-ItemProperty -Path $parent -Name 'ExtendedSubCommandsKey' -Value $loc.Relative -PropertyType String -Force | Out-Null
New-ItemProperty -Path $parent -Name 'Icon' -Value $iconPath -PropertyType String -Force | Out-Null
$childrenShell = Join-Path $parent 'Shell'
New-Item -Path $childrenShell -Force | Out-Null
foreach ($item in $items) {
$child = Join-Path $childrenShell $item.Key
$commandKey = Join-Path $child 'command'
New-Item -Path $commandKey -Force | Out-Null
New-ItemProperty -Path $key -Name '(default)' -Value $item.Text -PropertyType String -Force | Out-Null
New-ItemProperty -Path $key -Name 'Icon' -Value $iconPath -PropertyType String -Force | Out-Null
New-ItemProperty -Path $child -Name 'MUIVerb' -Value $item.Text -PropertyType String -Force | Out-Null
New-ItemProperty -Path $child -Name 'Icon' -Value $item.Icon -PropertyType String -Force | Out-Null
New-ItemProperty -Path $commandKey -Name '(default)' -Value (New-MenuCommand $item.Action $loc.Token) -PropertyType String -Force | Out-Null
}
}
Write-Host '✔ 已注册右键菜单(当前用户)' -ForegroundColor Green
foreach ($item in $actions) {
Write-Host (" - 「{0}」 × 文件夹 / 空白处 / mkv,mp4,avi" -f $item.Text) -ForegroundColor DarkGray
if ($Flat) {
Write-Host '✔ 已注册平级菜单项(兜底模式)' -ForegroundColor Green
}
else {
Write-Host '✔ 已注册右键级联菜单(ExtendedSubCommandsKey 自引用)' -ForegroundColor Green
}
Write-Host " $menuName ▸" -ForegroundColor Cyan
foreach ($item in $items) {
Write-Host (" {0}" -f $item.Text) -ForegroundColor DarkGray
}
Write-Host ' 位置:文件夹 / 空白处 / .mkv / .mp4 / .avi' -ForegroundColor DarkGray
Write-Host '提示:若菜单未立即出现,重启一次 explorer.exe 或重新登录。' -ForegroundColor Yellow