Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How to get song "rating" tag with Powershell (taglib)

    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/sho...ile-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

  2. #2
    5 Star Lounger
    Join Date
    Jan 2010
    Location
    Los Angeles, CA
    Posts
    828
    Thanks
    4
    Thanked 38 Times in 34 Posts
    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.
    Last edited by cafed00d; 2013-10-31 at 00:20.

  3. The Following User Says Thank You to cafed00d For This Useful Post:

    macq (2013-10-31)

  4. #3
    New Lounger
    Join Date
    Oct 2013
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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:\songs\ASong.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#.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •