Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from jvlflame/rewrite
Rewrite
- Loading branch information
Showing
67 changed files
with
14,282 additions
and
25,327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
function Convert-JVString { | ||
[CmdletBinding()] | ||
param ( | ||
[Parameter(Mandatory = $true)] | ||
[PSObject]$Data, | ||
|
||
[Parameter(Mandatory = $true)] | ||
[String]$FormatString, | ||
|
||
[Parameter()] | ||
[Int]$PartNumber, | ||
|
||
[Parameter()] | ||
[Int]$MaxTitleLength | ||
) | ||
|
||
process { | ||
# These symbols need to be removed to create a valid Windows filesystem name | ||
$invalidSymbols = @( | ||
'\', | ||
'/', | ||
':', | ||
'*', | ||
'?', | ||
'"', | ||
'<', | ||
'>', | ||
'|', | ||
"'" | ||
) | ||
|
||
if ($maxTitleLength) { | ||
if ($Data.Title.Length -ge $MaxTitleLength) { | ||
$shortTitle = $Data.Title.Substring(0, $MaxTitleLength) | ||
$splitTitle = $shortTitle -split ' ' | ||
if ($splitTitle.Count -gt 1) { | ||
# Remove the last word of the title just in case it is cut off | ||
$title = ($splitTitle[0..($splitTitle.Length - 2)] -join ' ') | ||
if ($title[-1] -match '\W') { | ||
$Data.Title = ($title.Substring(0, $title.Length - 2)) + '...' | ||
} else { | ||
$Data.Title = $title + '...' | ||
} | ||
} else { | ||
$Data.Title = $shortTitle + '...' | ||
} | ||
} | ||
} | ||
|
||
$convertedName = $FormatString ` | ||
-replace '<ID>', "$($Data.Id)" ` | ||
-replace '<TITLE>', "$($Data.Title)" ` | ||
-replace '<RELEASEDATE>', "$($Data.ReleaseDate)" ` | ||
-replace '<YEAR>', "$(($Data.ReleaseDate -split '-')[0])" ` | ||
-replace '<STUDIO>', "$($Data.Maker)" ` | ||
-replace '<RUNTIME>', "$($Data.Runtime)" ` | ||
-replace '<SET>', "$($Data.Series)" ` | ||
-replace '<LABEL>', "$($Data.Label)" ` | ||
-replace '<ORIGINALTITLE>', "$($Data.AlternateTitle)" | ||
|
||
foreach ($symbol in $invalidSymbols) { | ||
if ([regex]::Escape($symbol) -eq '/') { | ||
$convertedName = $convertedName -replace [regex]::Escape($symbol), '-' | ||
} else { | ||
$convertedName = $convertedName -replace [regex]::Escape($symbol), '' | ||
} | ||
} | ||
|
||
if ($PartNumber) { | ||
$convertedName += "-pt$PartNumber" | ||
} | ||
|
||
Write-Output $convertedName | ||
} | ||
} |
Oops, something went wrong.