Browse Source

新增檔名強制拉丁化、標準化功能

develop
pcnick 3 weeks ago
parent
commit
a0ca39b247
  1. 36
      Animelibk.ps1

36
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;
}

Loading…
Cancel
Save