Javinizer
Javinizer copied to clipboard
Feature Request: Folder Renaming from Nfo
Suggested Behavior
Rename existing folders based on XML information contained in the nfo files.
Current Behavior
Javinizer already does what I'm suggesting, but it requires you to run a scrape. This would allow for folder renaming without re-scraping. This is useful for library organization after scraping has occurred, or if you have custom nfo files that you don't want to overwrite.
Example
I renamed all my folders recently and made this PowerShell script to do so. It might give you an idea of what I'm thinking of. I might try turning it into a function, but I'm a PowerShell amateur. The invalid symbols / regex part was copied from the Convert-JVString.ps1 file in Javinizer.
$invalidSymbols = @(
'\',
'/',
':',
'*',
'?',
'"',
'<',
'>',
'|',
"'"
)
Get-ChildItem -Include *.nfo -Exclude *-pt[2-9].nfo -Depth 1 |
ForEach-Object {
[xml]$xmlJAV = Get-Content -LiteralPath $_.FullName
$ID = $xmlJAV.movie.id
$Actors = $xmlJAV.movie.actor.name
$Year = $xmlJAV.movie.year
$Studio = $xmlJAV.movie.studio
if ($Actors -eq 'Unknown') {
$Actors = '@Unknown'
}
if ($Actors.count -gt 1) {
$Actors = '@Group'
}
$OldTitle = Split-Path -Path $_.DirectoryName -Leaf
$NewTitle = "$ID - $Actors ($Year) [$Studio]"
foreach ($symbol in $invalidSymbols) {
if ([regex]::Escape($symbol) -eq '/') {
$NewTitle = $NewTitle -replace [regex]::Escape($symbol), '-'
} else {
$NewTitle = $NewTitle -replace [regex]::Escape($symbol), ''
}
}
if ($OldTitle -ne $NewTitle) {
Rename-Item -LiteralPath $_.DirectoryName -NewName $NewTitle
}
}
Your Environment
- Module version used: Javinizer.2.3.3
- Operating System and PowerShell version: Windows 10 / PowerShell 7.1.2
Definitely would be a nice feature to have.
Your script looks like a great start, and if you want to take a stab at converting it into a function and integrating into the Javinizer CLI that would be welcomed!
I have it working as a function now, but it's still half-baked. I'm piping in the settings, so it uses the sort.format.folder setting to determine how to rename the folders, and defaults to the location.output for the path.
The existing format strings don't all correspond to information stored in the nfo, so I'm working on what to do if those are included.
It's coming along though.
function Rename-JVFolders {
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('location.output')]
[String]$Path,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[Alias('sort.format.folder')]
[String]$FolderFormat
)
process {
Get-ChildItem -LiteralPath $Path -Include *.nfo -Exclude *-pt[2-9]*,*-pt[0-9][0-9]* -Recurse |
ForEach-Object {
[xml]$xmlNfo = Get-Content -LiteralPath $_.FullName
$movietitle = $xmlNfo.movie.title
$movieoriginaltitle = $xmlNfo.movie.originaltitle
$movieid = $xmlNfo.movie.id
$moviepremiered = $xmlNfo.movie.premiered
$movieyear = $xmlNfo.movie.year
$moviedirector = $xmlNfo.movie.director
$moviestudio = $xmlNfo.movie.studio
$movieruntime = $xmlNfo.movie.runtime
$movieset = $xmlNfo.movie.set
$movieactorname = $xmlNfo.movie.actor.name
if ($movieactorname -eq 'Unknown') {
$movieactorname = '@Unknown'
}
if ($movieactorname.count -gt 1) {
$movieactorname = '@Group'
}
$FolderFormatVariables = @{
'<ID>' = $movieid
'<DIRECTOR>' = $moviedirector
'<TITLE>' = $movietitle
'<RELEASEDATE>' = $moviepremiered
'<YEAR>' = $movieyear
'<STUDIO>' = $moviestudio
'<RUNTIME>' = $movieruntime
'<SET>' = $movieset
'<ACTORS>' = $movieactorname
'<ORIGINALTITLE>' = $movieoriginaltitle
}
$NewTitle = $FolderFormat
foreach ($string in $FolderFormatVariables.keys) {
$NewTitle = $NewTitle -replace $string, $FolderFormatVariables[$string]
}
$invalidSymbols = @(
'\',
'/',
':',
'*',
'?',
'"',
'<',
'>',
'|',
"'"
)
foreach ($symbol in $invalidSymbols) {
if ([regex]::Escape($symbol) -eq '/') {
$NewTitle = $NewTitle -replace [regex]::Escape($symbol), '-'
} else {
$NewTitle = $NewTitle -replace [regex]::Escape($symbol), ''
}
}
$OldTitle = Split-Path -Path $_.DirectoryName -Leaf
if ($OldTitle -ne $NewTitle) {
Rename-Item -LiteralPath $_.DirectoryName -NewName $NewTitle
}
}
}
}
Looks good so far. I've also been working on the Update-JVNfo function again, which might actually have some functionality you can reuse/reference here. It's also reading the existing nfo to re-populate the aggregated data object.
Like you were saying, there are a few missing fields that are currently impossible to grab from the nfo depending on how you defined your settings. I was actually thinking of making some tweaks to add all aggregated data fields into the nfo just so it could easily be recreated with new settings.