Any appetite for a 'normalisation' layer over non-std tags?

Adam Szmigin adam.szmigin at xsco.net
Mon Apr 10 20:45:18 UTC 2017


Hi Michael,

On 10/04/17 08:36, michaelhelmling at posteo.de wrote:
> Dear Adam,
>
> sorry, I've made a few typos in the haste. :-) The following should work:
>
> auto file = FileRef::create("/path/to/file.mp3"); // create() gives you
> a full-featured File object
> auto props = file.tag().properties();
> for (auto &composer : props["COMPOSER"])
>   std::cout << "composer: " << composer << std::endl;

The FileRef::create() function is useful for guessing the file type - 
thanks for pointing me towards this.  However, the resulting File object 
does not contain all properties under tag()->properties().  There does 
not appear to be a way to get fields like COMPOSER, ALBUMARTIST, etc. 
from tag()->properties().  Here is a minimal example that you can run to 
see what I mean:

$ cat taglib_tag_test.cpp
#include <iostream>
#include <string>
#include <fileref.h>
#include <tpropertymap.h>
#include <mpegfile.h>

int main(int argc, char **argv)
{
     using std::cout;
     using std::endl;
     using std::string;

     string path{"example.mp3"};
     cout << "Props using FileRef::tag()->properties():" << endl;
     TagLib::FileRef fr{path.c_str()};
     for (auto &prop_kvp : fr.tag()->properties()) {
         for (auto &val : prop_kvp.second) {
             cout << "Prop: " << prop_kvp.first << " -> " << val << endl;
         }
     }
     cout << endl;

     cout << "Props using MPEG::File::properties():" << endl;
     TagLib::MPEG::File f{path.c_str()};
     for (auto &prop_kvp : f.properties()) {
         for (auto &val : prop_kvp.second) {
             cout << "Prop: " << prop_kvp.first << " -> " << val << endl;
         }
     }
     return 0;
}
$ g++ -std=c++14 -I/usr/include/taglib taglib_tag_test.cpp -ltag
$ ./a.out
Props using FileRef::tag()->properties():
Prop: ALBUM -> Album field
Prop: ARTIST -> Artist field
Prop: COMMENT -> Comment field
Prop: DATE -> 2017
Prop: GENRE -> Pop
Prop: TITLE -> Title field
Prop: TRACKNUMBER -> 3

Props using MPEG::File::properties():
Prop: ALBUM -> Album field
Prop: ALBUMARTIST -> Album artist field
Prop: ARTIST -> Artist field
Prop: COMMENT -> Comment field
Prop: COMPOSER -> Composer field
Prop: COPYRIGHT -> Copyright field
Prop: DATE -> 2017
Prop: DISCNUMBER -> 1/2
Prop: ENCODEDBY -> Encoded by field
Prop: GENRE -> Pop
Prop: ORIGINALARTIST -> Original artist field
Prop: TITLE -> Title field
Prop: TRACKNUMBER -> 03/04
Prop: URL -> URL field

(For example.mp3, I took any old file and populated all available fields 
in EasyTag 2.4.2 with sample values)

For clarity, the output above is using version 1.9.1-2.4ubuntu1 of 
TagLib.  From what I can see, the tag() method only offers an approach 
for accessing only the 7 'standard' tags, and not any of the 'exotic' 
ones.  This was my original reason for having to write a normalisation 
layer.

Please let me know if you're able to reproduce the above behaviour.

Many thanks,

--
Adam


More information about the taglib-devel mailing list