Compare commits

..

2 Commits

  1. 68
      Animelibk.ps1

68
Animelibk.ps1

@ -67,8 +67,8 @@ if ($RecorDB -notmatch ":") { $RecorDB = "$JsonPath\$RecorDB" }
$WorkData = $(if (Test-Path $RecorDB) { $WorkData = $(if (Test-Path $RecorDB) {
Get-Content $RecorDB | ConvertFrom-Json Get-Content $RecorDB | ConvertFrom-Json
} else { } else {
"" | Select-Object ID, WorkName, TargetName, DestinName, Season, Episode ""
}) }) | Select-Object ID, WorkName, TargetName, DestinName, Season, Episode, Latinization, Standard
$RecorDB $RecorDB
# 確認資料狀態,缺少則進行物件資料建立 # 確認資料狀態,缺少則進行物件資料建立
@ -87,6 +87,27 @@ if (-not($WorkData.Season)) {
if (-not($WorkData.Episode)) { if (-not($WorkData.Episode)) {
$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 $WorkData
# $Seasons_TC = "", "Seasons 1", "Seasons 2", "Seasons 3", "Seasons 4", "Seasons 5" # $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 $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 = "" | Select-Object newName, Season, Episode, newFullName;
$OutputData.newName = $Result.Name; $OutputData.newName = if ($LS) { $WorkData.Latinization } else { $Result.Name.Trim() }
$OutputData.Season = $WorkData.Season; $OutputData.Season = $WorkData.Season;
$OutputData.Episode = [int] $Result.Episode; $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; return $OutputData;
} }
@ -164,7 +192,7 @@ $StructPathObj = @{
if ($Single) { if ($Single) {
# 單集模式 # 單集模式
$List = @(Get-Item -Path $(Edit-PathChar $Path)) $List = @(Get-Item -Path $(Edit-PathChar $Path))
$BuildList = $List | select $FileObj, $StructPathObj, $NewNameObj | ? {$_.NewName.Episode -notin $WorkData.Episode} $BuildList = $List | Select-Object $FileObj, $StructPathObj, $NewNameObj | ? {$_.NewName.Episode -notin $WorkData.Episode}
#$BuildList | ? {$_.NewName.Episode -notin $WorkData.Episode} | Format-List #$BuildList | ? {$_.NewName.Episode -notin $WorkData.Episode} | Format-List
# } elseif ($Sub) { # } elseif ($Sub) {
# $List = @(Get-Item -Path $(Edit-PathChar $Path)) # $List = @(Get-Item -Path $(Edit-PathChar $Path))
@ -172,26 +200,30 @@ if ($Single) {
} elseif ($testrun) { } elseif ($testrun) {
$List = @(Edit-PathChar $Path | Get-Item | ? { $_.GetType().Name -eq "FileInfo" }) + $List = @(Edit-PathChar $Path | Get-Item | ? { $_.GetType().Name -eq "FileInfo" }) +
@(Edit-PathChar $Path | Get-Item | ? { $_.GetType().Name -eq "DirectoryInfo" } | % { $_.GetFiles() }) @(Edit-PathChar $Path | Get-Item | ? { $_.GetType().Name -eq "DirectoryInfo" } | % { $_.GetFiles() })
$BuildList = $List | select $FileObj, $StructPathObj, $NewNameObj $BuildList = $List | Select-Object $FileObj, $StructPathObj, $NewNameObj
if ($Include -ne "") { $BuildList = $BuildList | ? {$_.File.Extension -in $Include} } if ($Include -ne "") { $BuildList = $BuildList | ? {$_.File.Extension -in $Include} }
if (-not($Force)) { $BuildList = $BuildList | ? {$_.NewName.Episode -notin $WorkData.Episode} } if (-not($Force)) { $BuildList = $BuildList | ? {$_.NewName.Episode -notin $WorkData.Episode} }
} else { } else {
exit 0; exit 0;
} }
$ENDResult = $BuildList | % { $ENDResult = $BuildList | ForEach-Object {
$Command = @{ if ($_.NewName.Episode -and ($_.NewName.newName.Length -gt 0)) {
ItemType = 'HardLink' $Command = @{
Path = $("{0}\{1}" -f $_.StructPath, $_.NewName.newFullName) ItemType = 'HardLink'
Target = $(Edit-PathChar $_.File.Fullname -nowlid) Path = $("{0}\{1}" -f $_.StructPath, $_.NewName.newFullName)
} Target = $(Edit-PathChar $_.File.Fullname -nowlid)
#try { }
if (New-Item @Command) { #try {
Write-Host $_.NewName.newFullName if (New-Item @Command) {
$_.NewName } Write-Host $_.NewName.newFullName
$_.NewName }
#} catch { #} catch {
#} } else {
"{0} 處理錯誤" -f $_.File.FullName | Write-Error
$_.NewName
}
} }
#$ENDResult #$ENDResult
#$ENDResult.gettype(); #$ENDResult.gettype();

Loading…
Cancel
Save