Adding new fields for import & tagging

There are three “non-standard” fields that I have come to rely on in my metadata:

copyright
wwwsource
wwwfileinfo

The copyright field is just for that: copyright information (if found). The other two fields I map in my tagging software (puddle tag) to be used as:

wwwsource -> Release Page URL
wwwfileinfo -> License (Creative Commons, Artistic, Public Domain, etc.)

I did not find any plugin(s) that would make it easy to add support for handling these fields. So I’ve turned to the plugin writing documentation to see what it would take to implement these fields. Am I correct in believing the section on extending MediaFile is all I would need to follow to write a plugin that could read/write these fields? By adding these fields to the MediaFile class would they be read and stored by the importer?

George

Yep, that’s all you need!

Then, do I need to add them as the ID3v2.4 frames? IE:

wwwfileinfo -> WOAF
wwwsource -> WOAS
copyright -> TCOP

And is there some way to alias them? IE, TCOP would be stored under the field name ‘copyright’ so queries would reference copyright instead of TCOP?

George

I’m not entirely sure what you’re asking, but the way these things work is that you create an internal beets name for your field, which can be anything you want, and describe how to map those onto actual tags for various formats. Needless to say, the mapping for ID3 and for Vorbis Comments is going to be different. But within beets, you only use the internal name.

We are on the same page… It is the mapping of the ID3/Vorbis Comments to the beets name that I am trying to understand… The reason for the confusion is the documentation example uses “foo” for everything (and since I am not as familiar with the internals of beets and mutagen, this isn’t exactly clear). So, here’s the example, modified for one case:

class FooPlugin(BeetsPlugin):
def init(self):
field = mediafile.MediaField(
mediafile.MP3DescStorageStyle(u’WOAF’),
mediafile.StorageStyle(u’WOAF’)
)
self.add_media_field(‘license’, field)

Or would I do it like this:

class FooPlugin(BeetsPlugin):
def init(self):
field = mediafile.MediaField(
mediafile.MP3DescStorageStyle(u’wwwfileinfo’),
mediafile.StorageStyle(u’wwwfileinfo’)
)
self.add_media_field(‘license’, field)

Or do I completely misunderstand this mapping?

George

(Sorry, I forgot to mark the code as pre-formatted so it lost the indentations…)

More like the latter, but if you want to use a non-“TXXX” field for ID3, you’ll need a different StorageStyle. To make this work, I think you might want to spend a little while working with the MediaFile source code to understand what the options are.

So, even if mutagen treats the WXXX fields the same as TXXX fields? For example:

mutagen-inspect d01t08__Cousin_Silas__December_Falling.mp3
– d01t08__Cousin_Silas__December_Falling.mp3

  • MPEG 1 layer 3, 320000 bps (CBR, LAME 3.97.0, -b 320), 44100 Hz, 2 chn, 514.06 seconds (audio/mp3)
    APIC=cover back, (image/jpeg, 2775360 bytes)
    APIC=cover front, (image/jpeg, 2387290 bytes)
    POPM=Windows Media Player 9 Series=0 255/255
    TALB=Catharsis
    TCON=Other
    TCOP=CC BY-NC-ND 4.0
    TDRC=2016
    TENC=Lavf54.63.104
    TIT2=December Falling
    TPE1=Cousin Silas
    TPOS=01
    TPUB=Hortus Conclusus Records
    TRCK=08
    WOAF=CC BY-NC-ND 4.0
    WOAS=https://archive.org/details/CousinSilasCatharsis_HCR2016Catharsis

I’m kind of mis-using the WOAF field here (WXXX fields are text fields which are only supposed to contain URL’s, which I hadn’t realized until I dug into the Puddle Tag docs while researching this), but mutagen (and other tools) don’t choke on this misuse as they don’t appear to do any URL validation.

I will dig into the MediaFile source code – but given my surface level understanding of python it’s going to be an uphill struggle for me.