From a0ca39b247c9bfd82ef02457b6cc0e4b3604aabb Mon Sep 17 00:00:00 2001 From: pcnick Date: Sat, 4 Jul 2026 18:50:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=AA=94=E5=90=8D=E5=BC=B7?= =?UTF-8?q?=E5=88=B6=E6=8B=89=E4=B8=81=E5=8C=96=E3=80=81=E6=A8=99=E6=BA=96?= =?UTF-8?q?=E5=8C=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Animelibk.ps1 | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/Animelibk.ps1 b/Animelibk.ps1 index 5c5286c..bfd20d2 100644 --- a/Animelibk.ps1 +++ b/Animelibk.ps1 @@ -67,8 +67,8 @@ if ($RecorDB -notmatch ":") { $RecorDB = "$JsonPath\$RecorDB" } $WorkData = $(if (Test-Path $RecorDB) { Get-Content $RecorDB | ConvertFrom-Json } else { - "" | Select-Object ID, WorkName, TargetName, DestinName, Season, Episode -}) + "" +}) | Select-Object ID, WorkName, TargetName, DestinName, Season, Episode, Latinization, Standard $RecorDB # 確認資料狀態,缺少則進行物件資料建立 @@ -87,6 +87,27 @@ if (-not($WorkData.Season)) { if (-not($WorkData.Episode)) { $WorkData.Episode = @(); } +# Latinization +$Latinization = { + param($String) + + # 載入置換檔 + $C = if (Test-path $PSScriptRoot\C2E.csv) {Import-Csv -Encoding UTF8 $PSScriptRoot\C2E.csv} + + if ($WorkData.Latinization.Length -eq 0) { + $T = Read-Host "請輸入拉丁化作品名稱" + # 常見字詞置換 + $N = $C | ForEach-Object {$String = $String -replace $_.C, $_.EN} + # 尋找非拉丁字元,以產生取代規則 + $TString = $String + while($TString -match '[^\[\]\d\s\-\.A-Za-z]+') { + if ($RuleString.Length -gt 0) {$RuleString = $RuleString + '.+'} + $RuleString = $RuleString + $Matches[0] + $TString = $TString -replace $Matches[0], '-' + } + return $String -replace $RuleString, $T + } +} $WorkData # $Seasons_TC = "", "Seasons 1", "Seasons 2", "Seasons 3", "Seasons 4", "Seasons 5" @@ -130,12 +151,19 @@ function Get-StandName { $Result = $File.Name | % { Get-NameRegex $_ -Regex $EpisodeRegex } | % { $(Get-NameRegex $_["L"] -Regex $NameRegex -Exclude "(BD|DVD|HDTV)RIP|BIG5" -End) + $_ } | Select -First 1 + # 拉丁化、標準化 + if ($LS = $WorkData.Standard -or ($Result.Name -match '[^\[\]\d\s\-\.A-Za-z]+')) { + if ($WorkData.Latinization.Length -eq 0) { + $WorkData.Latinization = &$Latinization -String $Result.Name.Trim() + } + } + # 建立回傳資料物件,以方便後續資料處理。 $OutputData = "" | Select newName, Season, Episode, newFullName; - $OutputData.newName = $Result.Name; + $OutputData.newName = if ($LS) { $WorkData.Latinization } else { $Result.Name.Trim() } $OutputData.Season = $WorkData.Season; $OutputData.Episode = [int] $Result.Episode; - $OutputData.newFullName = "{0} S{3:00}E{1}{4}{2}" -f $Result.Name, $Result.Episode, $File.Extension, $WorkData.Season, $(if($File.Extension -in $SubExt) {".default"}); + $OutputData.newFullName = "{0} S{3:00}E{1:00}{4}{2}" -f $OutputData.newName, $OutputData.Episode, $File.Extension, $WorkData.Season, $(if($File.Extension -in $SubExt) {".default"}); return $OutputData; }