mono / taglib-sharp

Library for reading and writing metadata in media files
GNU Lesser General Public License v2.1
1.27k stars 312 forks source link

Genres[] tag - Genres not displaying properly in applications #126

Open MartinHarran opened 5 years ago

MartinHarran commented 5 years ago

`Hi everyone

I am developing a C# application that gathers genre information about a song in Discogs and inserts it into an MP3 file using Taglib-sharp. I am running into problems however when I add the genres in using the Genres[] tag; what particularly bugs me (no pun intended!) is the variation in how the tag is interpreted in various applications, not just the difference between different applications but the variation within specific applications.

Here is the relevant piece of code:

            [ ...]
           genres = new List<string>();
            DiscogCall(extTrack); // Search Discogs, return genres/styles as string list
            [ ... ]
            //tag mp3 file
            TagLib.File mp3 = TagLib.File.Create(mp3FileName);
            mp3.Tag.Title = extTrack.Name;
            mp3.Tag.Performers = extTrack.TagArtists;
            mp3.Tag.Album = extTrack.Album.Name;
            mp3.Tag.AlbumArtists = extTrack.TagArtists;
            mp3.Tag.Genres = genres.ToArray();
            mp3.Save();

Here are the results of five files for which I have gathered genre/style information;

File No Genres list
File #1 Ballad;Pop Rock;Vocal;Disco;Soft Rock;Rhythm & Blues
File #2 Ragtime;Honky Tonk;Easy Listening;Ballad;Swing;Piano Blues;Vocal;Dixieland;Country Blues;Rock & Roll;Space-Age;Big Band
File #3 Vocal;Easy Listening;Lounge;Swingbeat;Soundtrack;Ballad;Theme;Bossa Nova;Religious;Country
File #4 Psychedelic Rock;Pop Rock;Beat;Rock & Roll;Classic Rock
File #5 Disco;Soul;Ballad;Vocal

The individual items in the lists above are stored inside the Genres tag as a string array - I have shown them here separated by semicolons for illustration but what I have shown above also matches the JoinedGenres tag displayed in the ‘locals’ window when the file is opened using Taglib in Visual Studio.

Here is how they appear in Windows Explorer (preview panel and Properties\Details).

File No Genres list
File #1 Ballad Pop Rock/28/4/Soft Rock/Rhythm & Blues
File #2 Ragtime/Honky Tonk/98/116/83/Piano Blues/28/Dixieland/Country Blues/78/Space-Age/96
File #3 Vocal (98)Lounge/Swingbeat/24/116/Theme/Bossa Nova/Religious/2
File #4 Psychedelic Rock Pop Rock/135/78/1
File #5 Disco (42)(116)(28)

Explorer displays the tags in varying ways with no real discernible pattern. In File #1, it picks up the first 3 tags as a single tag (separated by space, no delimiter); the next 2 tags are correctly delimited with a forward slash but are showing the Taglib index numbers for the genres instead of the relevant tag text (the index numbers are correct for the genre); the final two genres are displayed correctly.

In File #2, all the tags are delimited correctly but some are displayed as text and some as the genre index no.

The other 3 files are a mixture of what is happening in File #1 and File #2.

I have also looked at the results in both Mp3Tag and MediaMonkey; they give identical results as follows::

File No Genres list
File #1 Ballad
File #2 Ragtime/Honky Tonk/98/116/83/Piano Blues/28/Dixieland/Country Blues/78/Space-Age/96
File #3 Vocal
File #4 Psychedelic Rock
File #5 Disco

In four of the files, the application is only picking up the first genre but for File #2, they pick up all the tags and delimit them except that like Windows Explorer, some of them are displayed as text and others as index numbers!

There is a fairly easy workaround for this, just by saving all the genres into a single string separated by either forward slashes or commas as applications like MediaMonkey can handle that ok but I'm intrigued as to what is causing the actual problem. It's not even clear to me whether it's a TagLib issue or whether it has to do with applications not properly handling the ID3V2 tags. I see, for example, in the TagLib Changelog that the decision was made back in 2007 to stick with IDV2.3 as "the number of applications that hiccup on ID3v2.4 is too astounding" though that shouldn't be a factor here.

Can anyone shed any light on this?`

MartinHarran commented 5 years ago

BTW, I am using the exact same approach for Artists[] and Performers[] and both work perfectly!

Spiker985 commented 5 years ago

So, I'm actually in the process of switching from saving my songs into wav format because I found out that mp3's only store the first genre in the metadata, meanwhile wav stores multiple. Mp3 is also a compressed format, and wav is not, leading to a more lossless audio quality

image

Source

J-P- commented 5 years ago

@Spiker985 You may want to read the specs at id3.org before going further. What you wrote and intimated is incorrect. The specs allow writing 1 genre, 1 genre and a sub, and multiple genres including associated subs. Your problem may be with your player as some only report the first genre or concatenates the genres into one value.

@MartinHarran You may want to check the delimiter used to separate the values. Use Mp3tag (free, GUI) to verify if the tags are written as you want it. Note that it abstracts the delimiter as a double-backslash (\) so a track with R&B and Jazz genres would display as "R&B\Jazz."

Also note that it is OK and normal for a tag writing app to replace known genres with the numerical equivalent. I think that there are 40 such genres but could be more or less.

Spiker985 commented 5 years ago

@J-P- It's not an issue with my player, I made the switch because of Windows. I concede that the mp3 format may accept more than one genre, however, Windows will never display more than one genre on mp3 files. It has no problem showing multiple genres on other formats, however.