• How to get song “rating” tag with Powershell (taglib)

    Home » Forums » Developers, developers, developers » DevOps Lounge » How to get song “rating” tag with Powershell (taglib)

    Author
    Topic
    #491459

    I am using Powershell to help manage my music. But, I would like a way to get the “rating” tag for flac and mp3 – ideally using taglib sharp. I saw an earlier post where cafed00d said they do this so I am hopeful for assistance. That thread is:
    http://windowssecrets.com/forums/showthread//143993-Various-PowerShell-questions-and-extended-file-properties

    I have been able to retrieve the rating tag for mp3 files using the Windows Shell as follows:

    Code:
    $shell = new-object -comobject shell.application
    $ShFolder=$shell.namespace(“d:song”)
    $ShFile    =$ShFolder.parsename(“title.mp3”)
    $ShRating  = $ShFolder.getdetailsof($ShFile,19)

    While this is fine for mp3, it does not work for .flac music files which is the bulk of my collection. I installed and use taglib-sharp which gets and sets a variety of tags for flac and mp3 – just not the “rating” tag.

    I’m hoping there is something in taglib I just can’t see. Barring that, I’m open to using other extensions.

    Thanks

    Viewing 0 reply threads
    Author
    Replies
    • #1420170

      Here is the code that I am using for MP3s:

      Code:
      $mp3 = [TagLib.File]::Create($_)
      $tag = ($mp3.tag.tags[0] | where-object {$_ -is [TagLib.Id3v2.PopularimeterFrame]})
      if ($tag) {
        $rating = $tag.rating
      }

      The $_ is a file object obtained via “Get-ChildItem *.mp3”. The $rating is a value from 0 to 255.

      This code works only for MP3. I haven’t tried to get the ratings from FLAC files. The trick is to dump as much information as you can to determine if any of that information is the rating. For MP3s, I use MP3Tag to examine all of the tags, that helps me determine what I need to look for in the file. If I didn’t have that program, I’d have to loop through $mp3.tag and $mp3.tag.tags to see what all is stored there. Fortunately, you can do this on-the-fly with the Powershell command line – just load your FLAC file and start looking at what is available.

      If you solve this, I’d be interested in the solution. I might at that time be interested in reripping my music as FLAC, though it would mean re-recording my LPs. Though honestly I can’t tell the difference between the original CD or LP and the ripped song encoded in a high variable bit rate MP3 (it took me forever to get past the organ in the spaceship in Myst, a musical ear I don’t have!) so this effort might not be worthwhile for me.

      • #1420267

        Oh, that works nice for MP3. But, it doesn’t work for FLAC.

        The closest I came was with this:

        $flac = [taglib.file]::create(“d:songsASong.flac”)
        $xiph = $flac.gettag(“xiph”)

        It displays the tag names but not the values. Instead of GetTag you can also do this but it also just retrieves the tag names:

        $flac.tag.tags[0].tag

        It would still be nice to have a solution in TagLib# although I’ve moved on. I wrote a PowerShell function which parses the FLAC metadata blocks and then decodes the Vorbis Comment block which contains the tags and values. I can now see every tag value (but not set or change them). If I ever get around to documenting my function I’ll post the code but I don’t think there is a lot of interest so it’s not high on my priority list. I used to be an operating systems programmer so it was kind of fun to learn how to do bit and byte stuff in PowerShell. But, I still would have preferred it work right away in TagLib#.

    Viewing 0 reply threads
    Reply To: How to get song “rating” tag with Powershell (taglib)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: