mono / taglib-sharp

Library for reading and writing metadata in media files
GNU Lesser General Public License v2.1
1.3k stars 312 forks source link

"/" is removed from performers and albumartists #227

Open david-hill opened 4 years ago

david-hill commented 4 years ago

"Morton Feldman - Sabat / Clarke" becomes: "Morton Feldman - Sabat Clarke"

$taglib = "d:\tools\taglib-sharp.dll"

function findartist { $=$args[0] $media = [taglib.file]::create($_.FullName) $tags = $media.GetTag('Id3v2') $fileperformers = $tags.performers $filealbumartists = $tags.albumartists if (-not ( $fileperformers -eq $null) -and [string]::IsNullOrEmpty($fileperformers) -eq $False ) { return $fileperformers } elseif ( -not ( $filealbumartists -eq $null ) -and [string]::IsNullOrEmpty($filealbumartists) -eq $False ) { return $filealbumartists } else { return $False } }

$basepath="D:\files" $a = Get-ChildItem $basepath -recurse | Where-Object {$_.PSIsContainer -eq $True}

$a | Where-Object {$.GetFiles().Count -ne 0 -and $.GetDirectories().count -eq 0} | get-childitem | ForEach-Object { if ( $.FullName -like '*mp3' -or $.FullName -like 'flac' -or $_.FullName -like 'm4a' -or $.FullName -like '*wav') { if (Test-Path -LiteralPath $.FullName) { $artist=findartist $ if (-not ( $artist -eq $False) ) { if ( ( -not ( $artist -match "\&") ) -and ( -not ( $artist -match "\/" ) ) ) { $dir=Split-Path -Path $_.FullName -Parent if ( -not ( "$dir" -like "$basepath\$artist*" ) -and -not ("$dir" -like "$basepath\$artist") ) { write-host "dir" $dir write-host "$basepath\$artist" write-host $artist if (-not(Test-Path -LiteralPath "$basepath\$artist") ) { New-Item -Path "$basepath" -Name "$artist" -ItemType "directory" } move-item -literalpath "$dir" -destination "$basepath\$artist" -Force } } else { write-host "$artist" } } } } }

tmilker commented 4 years ago

/ is the separator in ID3 for frames that can have multiple values. TPE1 (Performers) explicitly defines its use. TPE2 (Album Artist) doesn't but it appears to be treated the same by taglib-sharp. Unfortunately, ID3 doesn't define a way to escape /.

I am guessing that Powershell is automatically concatenating the arrays you're getting into strings which is hiding the real behavior from you.