Reporting mp3 tags in Powershell

I’m slowly getting to grips with Powershell.

# -----------------------------------------------------------------
# Script - Catalog-MP3s.ps1 #
# Gets mp3 tags from the mp3 file.
# -----------------------------------------------------------------
# Parameter is either a directory or an individual mp3 Param ( $P_DIR_OR_MP3 )  # --------------------------
# Function: get-mp3info
# The function gets the tags
# for the specified mp3
# --------------------------
Function get-mp3info ($P_MP3)
{
     # Get the tages into a variable
     $TAGS = [TagLib.File]::Create("$P_MP3")
     $TAGS_OBJECT = @{Filename = $TAGS.Name;

     Bitrate = $TAGS.Properties.AudioBitRate;
     Artist = $TAGS.tag.FirstArtist;
     Title =  $TAGS.tag.Title;
     Genre = $TAGS.tag.FirstGenre;
     LP = $TAGS.tag.Album}

     # Output as an object
     New-Object PSObject -Property $TAGS_OBJECT
}

     # --------------------------
     # Main body
     # --------------------------
     # Store the location of the taglib dll
     $TAGLIB="C:UsersMattDownloadstaglib-sharp-2.1.0.0-windowstaglib-sharp-2.1.0.0-windowsLibrariestaglib-sharp.dll"

     # Load the DLL
     [System.Reflection.Assembly]::LoadFile($Taglib)

     # Get a list of all the MP3s under the specified folder
     # - exclude anything that's not an mp3
     # - Fullname contains the full path and filename
     $MP3_LIST = gci -recurse Filesystem::$DIR_OR_MP3 |
                     where {$_.Extension -eq '.mp3'} |
                     select FullName

     # Walk through the list, and output the tags
     foreach ($MP3 in $MP3_LIST)
     {
          get-mp3info $MP3.Fullname
     }

PowerShell – Automatically organizing your mp3-collection – Speaking of which… – Site Home – MSDN Blogs
Scripting Mp3 Tags through PowerShell | PowerShell.nu

Advertisements