How to use the mediafile.MediaFile.add_field function in mediafile

To help you get started, we’ve selected a few mediafile examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beetbox / beets / test / test_plugin_mediafield.py View on Github external
def test_invalid_descriptor(self):
        with self.assertRaises(ValueError) as cm:
            mediafile.MediaFile.add_field('somekey', True)
        self.assertIn(u'must be an instance of MediaField',
                      six.text_type(cm.exception))
github beetbox / beets / test / test_plugin_mediafield.py View on Github external
def test_overwrite_property(self):
        with self.assertRaises(ValueError) as cm:
            mediafile.MediaFile.add_field('artist', mediafile.MediaField())
        self.assertIn(u'property "artist" already exists',
                      six.text_type(cm.exception))
github beetbox / mediafile / test / test_mediafile_edge.py View on Github external
def setUp(self):
        self.create_temp_dir()
        self.key = "READ_ONLY_TEST"
        self.field = mediafile.MediaField(
            mediafile.MP3StorageStyle(self.key, read_only=True),
            mediafile.MP4StorageStyle(
                "----:com.apple.iTunes:" + self.key, read_only=True),
            mediafile.StorageStyle(self.key, read_only=True),
            mediafile.ASFStorageStyle(self.key, read_only=True),
        )

        if "read_only_test" not in mediafile.MediaFile.fields():
            mediafile.MediaFile.add_field("read_only_test", self.field)
github beetbox / beets / beets / plugins.py View on Github external
def add_media_field(self, name, descriptor):
        """Add a field that is synchronized between media files and items.

        When a media field is added ``item.write()`` will set the name
        property of the item's MediaFile to ``item[name]`` and save the
        changes. Similarly ``item.read()`` will set ``item[name]`` to
        the value of the name property of the media file.

        ``descriptor`` must be an instance of ``mediafile.MediaField``.
        """
        # Defer import to prevent circular dependency
        from beets import library
        mediafile.MediaFile.add_field(name, descriptor)
        library.Item._media_fields.add(name)