Skip to content

Commit

Permalink
Added more use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
seeyabye committed Sep 24, 2020
1 parent 8e87fa8 commit 51c5d56
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Javinizer/Private/Convert-JVTitle.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ function Convert-JVTitle {
try {
$id = ($file | Select-String $RegexString).Matches.Groups[$RegexIdMatch].Value
$partNum = ($file | Select-String $RegexString).Matches.Groups[$RegexPtMatch].Value

# If ID#### and there's no hypen, subsequent searches will fail
if($id -match '^([a-z]+)(\d+)$') {
$id = $Matches[1] + "-" + ($Matches[2] -replace '^0{1,5}', '').PadLeft(3, '0')
}
} catch {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "File [$file] not matched by regex"
break
Expand Down Expand Up @@ -193,7 +198,7 @@ function Convert-JVTitle {
# Match ID-### - cd1, ID-### - cd2, etc.
elseif ($fileBaseNameUpper[$x] -match "[-][0-9]{1,6}Z?E?\s?[-]\s?(cd|part|pt)?[-]?\d{1,3}") {
$fileP1, $fileP2, $fileP3 = $fileBaseNameUpper[$x] -split "([-][0-9]{1,6}Z?E?\s?[-])"
$fileBaseNameUpperCleaned += $fileP1 + "-" + ($fileP2 -replace '-', '').Trim()
$fileBaseNameUpperCleaned += $fileP1 + "-" + (($fileP2 -replace '-', '') -replace '0{1,5}', '').Trim().PadLeft(3, '0')
$filePartNum = ((($fileP3 -replace '-', '') -replace '^0{1,5}', '') -replace '(cd|part|pt)', '').Trim()
$filePartNumber = [int]$filePartNum
}
Expand Down
8 changes: 6 additions & 2 deletions src/Tests/Unit/Javinizer-Function.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ InModuleScope 'Javinizer' {
"bbi-094 - cd14.wmv",
"bbi00094o.wmv",
"bbi00094-p.wmv",
"bbi00094 - q.wmv"
"bbi00094 - q.wmv",
"bbi00094-pt18.wmv",
"bbi00094 - pt19.wmv",
"bbi00094-cd20.wmv",
"bbi00094 - cd21.wmv"
)

Mock Get-ChildItem {
Expand All @@ -54,7 +58,7 @@ InModuleScope 'Javinizer' {
}

$files = Get-ChildItem
$results = Convert-JVTitle $files
$results = Convert-JVTitle $files -RegexEnabled $false
$results.ContentId | Should -Be (,"BBI00094" * $fileNames.Length)
$results.Id | Should -Be (,"BBI-094" * $fileNames.Length)
$results.PartNumber | Should -Be (1..$fileNames.Length)
Expand Down

0 comments on commit 51c5d56

Please sign in to comment.