Skip to content

Instantly share code, notes, and snippets.

@Hashbrown777
Last active July 6, 2023 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hashbrown777/fae023538705a1f3f01cd795a2314e61 to your computer and use it in GitHub Desktop.
Save Hashbrown777/fae023538705a1f3f01cd795a2314e61 to your computer and use it in GitHub Desktop.
Grab all music metadata and output it in bbcode
. './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
$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