Debian Codegraph @

docs/dev/plugins/other/mediafile.rst

raw
1 Extend MediaFile
2 ================
3
4 MediaFile_ is the file tag abstraction layer that beets uses to make
5 cross-format metadata manipulation simple. Plugins can add fields to MediaFile
6 to extend the kinds of metadata that they can easily manage.
7
8 The ``MediaFile`` class uses ``MediaField`` descriptors to provide access to
9 file tags. If you have created a descriptor you can add it through your plugins
10 :py:meth:`beets.plugins.BeetsPlugin.add_media_field` method.
11
12 .. _mediafile: https://mediafile.readthedocs.io/en/latest/
13
14 Here's an example plugin that provides a meaningless new field "foo":
15
16 .. code-block:: python
17
18 class FooPlugin(BeetsPlugin):
19 def __init__(self):
20 field = mediafile.MediaField(
21 mediafile.MP3DescStorageStyle("foo"), mediafile.StorageStyle("foo")
22 )
23 self.add_media_field("foo", field)
24
25
26 FooPlugin()
27 item = Item.from_path("/path/to/foo/tag.mp3")
28 assert item["foo"] == "spam"
29
30 item["foo"] == "ham"
31 item.write()
32 # The "foo" tag of the file is now "ham"