From 933b2f6ed7028b620f5068e37e502ca2256ed0cf Mon Sep 17 00:00:00 2001 From: pcnick Date: Sun, 21 Nov 2021 16:29:52 +0800 Subject: [PATCH] Anime Link Libary: moofiy regex for file name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修正分析檔名的正規表示法 --- Animelibk.ps1 | 52 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/Animelibk.ps1 b/Animelibk.ps1 index b5f63c8..8fbd6dd 100644 --- a/Animelibk.ps1 +++ b/Animelibk.ps1 @@ -61,10 +61,27 @@ function Get-StandName { }) # 因應檔名不同而設定多組正規方式 - $Result = @( - #$($Path -match "\[([^\]]*)\]\[(\d{1,2})\]") - $($File.Name -match "[\[\s]([^\]]*?)(?:[\]\[\-\s]+)(\d{1,2})[\]\s]") - ) | % { if ($_) { $Matches }} + $Result = @($( + #$($File.Name -match "[\[\s]([^\]]*?)(?:[\]\[\-\s]+)(\d{1,2})[\]\s]") + $($File.Name -match "[\[\s](?\b[^\]]*\b)(?:[\]\[\-\s]+)(?\d{1,2})(?:[vV]\d|FIN|END)?[\]\s]") + ) | % { if ($_) { $Matches }}) + + # 檔名分析測試用 +# $Pathes = @( +# "L:\Anime\200910 聖剣の刀鍛冶(聖劍鍛造師)\[DMG][The Sacred Blacksmith][01-12 END][848x480][BIG5]\[DMG][The Sacred Blacksmith][04V2][848x480][BIG5].rmvb" +# "H:\Anime\201901 盾の勇者の成り上がり\[LKSUB][Tate no Yuusha no Nariagari][01-25][GB][720P][MP4]\[LKSUB][Tate no Yuusha no Nariagari][01][GB][720P].mp4" +# "L:\Anime\202004 ストライク・ザ・ブラッド OVA IV\[Suzu-Kaze][Strike_the_Blood_IV_OVA][01-12FIN][BDRip_1080P][HEVC_YUV420P10]\[Suzu-Kaze] Strike the Blood IV 12FIN [BDRip 1920x1080 HEVC YUV420P10 FLAC].mkv" +# "L:\Anime\200910 アスラクライン II(機巧魔神)\[DMG][Asura Cryin2][01-13 END][848x480][BIG5][RMVB]\[DMG][Asura Cryin 2][01][848x480][Big5].rmvb" +# "H:\Data\Downloads\異世界食堂\[Lilith-Raws] Isekai Shokudou S02 - 06 [Baha][WEB-DL][1080p][AVC AAC][CHT][MP4].mp4" +# ) +# $TestName = @($Pathes | % {$_.Split("\\")[-1]}) +# $Result = @( $TestName | % { @( + #$($_ -match "\[([^\]]*)\]\[(\d{1,2})\]") +# $($_ -match "[\[\s](?\b[^\]]*\b)(?:[\]\[\-\s]+)(?\d{1,2})(?:[vV]\d|FIN|END)?[\]\s]") +# ) | % { if ($_) { $Matches }}}) +# Write-Output $Result +# $Matches + # OLD Edition #$File.Name -match "\[([^\]]*)\]\[(\d{1,2})\]" | Out-Null @@ -74,10 +91,10 @@ function Get-StandName { # 建立回傳資料物件,以方便後續資料處理。 $OutputData = "" | Select newName, Season, Episode, newFullName; - $OutputData.newName = $Result[1]; + $OutputData.newName = $Result.Name; $OutputData.Season = $WorkData.Season; - $OutputData.Episode = [int] $Result[2]; - $OutputData.newFullName = "{0} S{3:00}E{1}{2}" -f $Result[1], $Result[2], $File.Extension, $WorkData.Season; + $OutputData.Episode = [int] $Result.Episode; + $OutputData.newFullName = "{0} S{3:00}E{1}{2}" -f $Result.Name, $Result.Episode, $File.Extension, $WorkData.Season; #$OutputData | ConvertTo-Json; # Type 2,在輸出顯示上,此型態建立較傾向 Hash,而上面 select 建立的,較偏向 pscustomobject @@ -132,6 +149,7 @@ $ENDResult = $BuildList | % { Target = $($_.File.Fullname -replace '([\[\]])', '`$1') } #try { + # 判斷 New-Item @Command 是否成功,將 NEWNAME 物件作為回傳值 if (New-Item @Command) { $_.NewName } #} catch { @@ -139,7 +157,7 @@ $ENDResult = $BuildList | % { } #$ENDResult #$ENDResult.gettype(); -$ENDResult | % { if ($_) { $WorkData.Episode += $_.Episode }} +$ENDResult | % { if ($_.Episode) { $WorkData.Episode += $_.Episode }} $WorkData | ConvertTo-Json | Out-File -Encoding "UTF8" "$JsonPath\animelibk.json" exit 0; @@ -147,8 +165,8 @@ exit 0; # SIG # Begin signature block # MIIFxwYJKoZIhvcNAQcCoIIFuDCCBbQCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB # gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR -# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQU8hOX2EpjptM6JRQpENcCS+vQ -# KL6gggNSMIIDTjCCAjagAwIBAgIQdMnAQ4BDAo9Lgfn+QeDdhjANBgkqhkiG9w0B +# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUX9/yYsS2o/ap36sf/Bq1uDoj +# CIOgggNSMIIDTjCCAjagAwIBAgIQdMnAQ4BDAo9Lgfn+QeDdhjANBgkqhkiG9w0B # AQUFADAqMRMwEQYDVQQDDApOaWNrIENoYW5nMRMwEQYDVQQKDAplYXJpY2sub3Jn # MB4XDTIxMTAzMTEwMDI1MVoXDTIyMTAzMTEwMjI1MVowMzEiMCAGCSqGSIb3DQEJ # ARYTcGNuaWNrMTAwQGdtYWlsLmNvbTENMAsGA1UEAwwETmljazCCASIwDQYJKoZI @@ -169,11 +187,11 @@ exit 0; # AgEBMD4wKjETMBEGA1UEAwwKTmljayBDaGFuZzETMBEGA1UECgwKZWFyaWNrLm9y # ZwIQdMnAQ4BDAo9Lgfn+QeDdhjAJBgUrDgMCGgUAoHgwGAYKKwYBBAGCNwIBDDEK # MAigAoAAoQKAADAZBgkqhkiG9w0BCQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3 -# AgELMQ4wDAYKKwYBBAGCNwIBFTAjBgkqhkiG9w0BCQQxFgQU1FQyPec3rnbdh3xg -# UI1KxQR1VNowDQYJKoZIhvcNAQEBBQAEggEAFZhn/fCXLVeHwJbTknYoljeOmZXv -# bCbZTEV+uuhILGbjLyQC9/UTyqQC9OF3JmaDkO0RUgURnIKKEM4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