How to read "moods" that have been set by MM in mpeg-4 files

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: How to read "moods" that have been set by MM in mpeg-4 files

How to read "moods" that have been set by MM in mpeg-4 files

by jsnorman » Mon Jul 05, 2010 12:29 am

So I have been trying for the last 2 weeks to read the "mood" tags in the iTunes format AAC files (mpeg4).

According the MM documentation, mpeg4 files store the mood tag as "mood" but there is no mention of where the tag is stored. Worse, the tag is actually stored as "MOOD" all caps so the documentation for MM is incorrect on this point (you can see this by viewing an m4a file tagged by MM with a mood that has a unique name - just search the file for the mood you set and you will see the MOOD call caps tag).

After trying every possible tag field I could find (including the AppleDataBox, AdditionalInfoBox, and AnnotationBox; and also tried running through each child box recursively) I could not find the mood (or MOOD) tags.

So, in case anyone else is stymied by this, the correct answer appears to be that MM stores the MOOD tag as a two part "mean","name" tag pair with the "mean" equal to "com.apple.iTunes". A code excerpt that shows how to properly read the mood code as set by MM is below.

Using this code (plus my ratings transfer code in another post) I have been able to make my playlists location independent as follows: (a) each file in a playlist is tagged with a mood that is the playlist name from within MM, (b) I use my program to copy ratings and moods over to itunes, but since itunes doesn't use moods I instead make each "mood" a playlist and add files tagged with a mood to a playlist of same name (that is my tracktoplaylist method referenced below). in this way, I can now move files anywhere, change drives, change directory structure, change file naming formats, and still recreate my playlists and ratings in both MM and iTunes in a matter if minutes. Of course I can easily recreate the playlists in MM by using an auto playlist.

Here is code to access MM created MOOD tags (in C#) [NOTE: the "correct" way to store mood tags is in the text field using lower case "mood" for m4a files, so this code will probably only work with MM tagged MOODS; my actual program looks for both formats:

Code: Select all

// Uses taglib-sharp, itunes COM resource
// assumes fileTrack has already been verified as a valid file track of type IITFileOrCDTrack
                                try
                                {
                                    file = TagLib.File.Create(fileTrack.Location);
                                    fileTagApple = (TagLib.Mpeg4.AppleTag)(file.GetTag(TagTypes.Apple));
                                    else if (fileTagApple != null)
                                    {
                                        if ((databoxResults = fileTagApple.DataBoxes("com.apple.iTunes", "MOOD")) != null)
                                            foreach (TagLib.Mpeg4.AppleDataBox parent in databoxResults)
                                            {
                                                data = parent.Data.ToString();
                                                // data contains the mood - do stuff here with track
                                            }
                                    }
                                }
                                catch (Exception e)
                                {
                                    Console.WriteLine(e);
                                }

Top