This weekend I found the need to set the Media Meta Tags in MP3 files I have RIPed. I found this Huddled Masses article for using the taglib-sharp library. I find Hashtables as a convenient machine for passing Pthese kinds of adhoc Name\Value pairs.
[
void] [Reflection.Assembly]::LoadFile(".\taglib-sharp.dll")
function
SetMedia-Tags
( [System.IO.FileInfo] $File=$(Throw "File is required")
, [hashtable] $Tags=$(Throw "Tags are required"))
{
$media = [TagLib.File]::Create($file.FullName)
foreach ($tag in $Tags.keys)
{
$media.Tag.$tag = $Tags[$tag]
}
$media.Save()
}
Example Usage:
$Tags
= @{Artists="Max Headgroom";Album="Smoke";Comment="This is a comment";Genres=@("Crazy")}
SetMedia-Tags -File ".\file1.mp3" -Tags $Tags
I used this code in a more specific project for organizing Audio Book MP3s I'll describe in a subsequent post.