Plugins can't extend MediaFile anymore

Backported from #607.
See https://github.com/sampsyo/beets/pull/607#issuecomment-38387100

This will be return in #644.
This commit is contained in:
Thomas Scholtes 2014-04-04 14:26:29 +02:00
parent 1d815b3734
commit ee2cf0df8e
2 changed files with 0 additions and 52 deletions

View file

@ -19,7 +19,6 @@ import traceback
from collections import defaultdict
import beets
from beets import mediafile
PLUGIN_NAMESPACE = 'beetsplug'
@ -40,7 +39,6 @@ class BeetsPlugin(object):
def __init__(self, name=None):
"""Perform one-time plugin setup.
"""
_add_media_fields(self.item_fields())
self.import_stages = []
self.name = name or self.__module__.split('.')[-1]
self.config = beets.config[self.name]
@ -86,14 +84,6 @@ class BeetsPlugin(object):
"""
return ()
def item_fields(self):
"""Returns field descriptors to be added to the MediaFile class,
in the form of a dictionary whose keys are field names and whose
values are descriptor (e.g., MediaField) instances. The Library
database schema is not (currently) extended.
"""
return {}
def album_for_id(self, album_id):
"""Return an AlbumInfo object or None if no matching release was
found.
@ -297,13 +287,6 @@ def template_funcs():
funcs.update(plugin.template_funcs)
return funcs
def _add_media_fields(fields):
"""Adds a {name: descriptor} dictionary of fields to the MediaFile
class. Called during the plugin initialization.
"""
for key, value in fields.iteritems():
setattr(mediafile.MediaFile, key, value)
def import_stages():
"""Get a list of import stage functions defined by plugins."""
stages = []

View file

@ -297,41 +297,6 @@ This field works for *item* templates. Similarly, you can register *album*
template fields by adding a function accepting an ``Album`` argument to the
``album_template_fields`` dict.
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 ``item_fields`` method on plugins should be overridden to return a
dictionary whose keys are field names and whose values are descriptor objects
that provide the field in question. The descriptors should probably be
``MediaField`` instances (defined in ``beets.mediafile``). Here's an example
plugin that provides a meaningless new field "foo"::
from beets import mediafile, plugins, ui
class FooPlugin(plugins.BeetsPlugin):
def item_fields(self):
return {
'foo': mediafile.MediaField(
mp3 = mediafile.StorageStyle(
'TXXX', id3_desc=u'Foo Field'),
mp4 = mediafile.StorageStyle(
'----:com.apple.iTunes:Foo Field'),
etc = mediafile.StorageStyle('FOO FIELD')
),
}
Later, the plugin can manipulate this new field by saying something like
``mf.foo = 'bar'`` where ``mf`` is a ``MediaFile`` instance.
Note that, currently, these additional fields are *only* applied to
``MediaFile`` itself. The beets library database schema and the ``Item`` class
are not extended, so the fields are second-class citizens. This may change
eventually.
.. _MediaFile: https://github.com/sampsyo/beets/wiki/MediaFile
Add Import Pipeline Stages
^^^^^^^^^^^^^^^^^^^^^^^^^^