File: mediafile.rst

package info (click to toggle)
beets 2.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,016 kB
  • sloc: python: 46,429; javascript: 8,018; xml: 334; sh: 261; makefile: 125
file content (32 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Extend MediaFile
================

MediaFile_ is the file tag abstraction layer that beets uses to make
cross-format metadata manipulation simple. Plugins can add fields to MediaFile
to extend the kinds of metadata that they can easily manage.

The ``MediaFile`` class uses ``MediaField`` descriptors to provide access to
file tags. If you have created a descriptor you can add it through your plugins
:py:meth:`beets.plugins.BeetsPlugin.add_media_field` method.

.. _mediafile: https://mediafile.readthedocs.io/en/latest/

Here's an example plugin that provides a meaningless new field "foo":

.. code-block:: python

    class FooPlugin(BeetsPlugin):
        def __init__(self):
            field = mediafile.MediaField(
                mediafile.MP3DescStorageStyle("foo"), mediafile.StorageStyle("foo")
            )
            self.add_media_field("foo", field)


    FooPlugin()
    item = Item.from_path("/path/to/foo/tag.mp3")
    assert item["foo"] == "spam"

    item["foo"] == "ham"
    item.write()
    # The "foo" tag of the file is now "ham"