Last active
July 6, 2023 13:35
-
-
Save Hashbrown777/fae023538705a1f3f01cd795a2314e61 to your computer and use it in GitHub Desktop.
Grab all music metadata and output it in bbcode
This file contains hidden or 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
. './metadata.ps1' | |
Function Bbcode-Row { | |
Param ([switch]$Heading, $From) | |
Begin { | |
'[tr]' | |
} | |
Process { | |
('[th]','[td]')[!$Heading] | |
if ($From) { | |
$_ = $From."$_" | |
} | |
'' + $_ | |
('[/th]','[/td]')[!$Heading] | |
} | |
End { | |
'[/tr]' | |
} | |
} | |
Function ConvertTo-Bbcode { | |
Param ($Fields) | |
Begin { | |
'[table]' | |
$first = $True | |
} | |
Process { | |
if ($first) { | |
if (!$Fields) { | |
$Fields = $_ ` | |
| Get-Member -MemberType NoteProperty ` | |
| %{ $_.Name } | |
} | |
($Fields | Bbcode-Row -Heading) -join '' | |
$first = $False | |
} | |
($Fields | Bbcode-Row -From $_) -join '' | |
} | |
End { | |
'[/table]' | |
} | |
} | |
$meta = 'Year','Album','#','Title','Length','Bit rate' | |
Get-ChildItem -Recurse -Include *.flac,*.mp3 ` | |
| MetaData -Filter "^($($meta -join '|'))`$" ` | |
| ConvertTo-Bbcode -Fields $meta ` | |
| Out-File -Encoding utf8 info.txt |
This file contains hidden or 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
$shell = New-Object -ComObject Shell.Application | |
$namespaces = @{} | |
Function MetaData { | |
Param ( | |
$Filter = '' | |
) | |
Process { | |
$namespace = $namespaces[$_.Directory.FullName] | |
if (!$namespace) { | |
$namespace = $namespaces[$_.Directory.FullName] = @{ | |
folder = $shell.namespace($_.Directory.FullName) | |
} | |
$namespace['properties'] = 0..266 ` | |
| ?{ | |
$name = $namespace['folder'].getDetailsOf($namespace['folder'].items, $_) | |
if ($name -match $Filter) { | |
$namespace[$_] = $name | |
$True | |
} | |
else { | |
$False | |
} | |
} | |
} | |
$name = $_.Name | |
$file = $namespace['folder'].items() | ?{ $_.name() -eq $name } | |
$output = [PSCustomObject]@{} | |
$namespace['properties'] | %{ | |
$detail = $namespace['folder'].getDetailsOf($file, $_) | |
if ($detail) { | |
$output ` | |
| Add-Member ` | |
-MemberType NoteProperty ` | |
-Name $namespace[$_] ` | |
-Value ($detail -replace '^\u200E','') | |
} | |
} | |
$output | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment