def __init__(self, *args, **kwargs): super(CanonicalPlugin, self).__init__(*args, **kwargs) self.config.add({ 'artist_credit': False, 'albumartist_credit': False, 'original_date': False, 'album_disambig': False }) self.register_listener('album_imported', self.album_imported) self.register_listener('write', self.write) for field in self.artists_fields: canonical = field + u'_canonical' canonical_desc = ' '.join(s.capitalize() for s in canonical.split(u'_')) media_field = mediafile.MediaField( mediafile.MP3DescStorageStyle(canonical_desc), mediafile.MP4StorageStyle( u"----:com.apple.iTunes:{}".format(canonical_desc)), mediafile.StorageStyle(canonical.upper()), mediafile.ASFStorageStyle('beets/{}'.format(canonical_desc)), ) self.add_media_field(canonical, media_field) date_canonical = mediafile.DateField( mediafile.MP3DescStorageStyle(u'Date Canonical'), mediafile.MP4StorageStyle('----:com.apple.iTunes:Date Canonical'), mediafile.StorageStyle('DATE_CANONICAL'), mediafile.ASFStorageStyle('WM/Date Canonical')) for df in ('year', 'month', 'day'): self.add_media_field( '{}_canonical'.format(df), getattr(date_canonical, '{}_field'.format(df))())
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)
def __init__(self): super(iTunesAdvisoryPlugin, self).__init__() self.config.add({ 'auto': True, }) field = mediafile.MediaField( mediafile.MP3DescStorageStyle(u'ITUNESADVISORY'), mediafile.MP4StorageStyle(u'rtng'), mediafile.StorageStyle(u'ITUNESADVISORY'), mediafile.ASFStorageStyle(u'ITUNESADVISORY'), out_type=int, ) mediafile.MediaFile.add_field('itunesadvisory', field) if self.config['auto'].get(): self.import_stages = [self.imported]
import os import six import shutil import unittest from test import _common from beets.library import Item import mediafile from beets.plugins import BeetsPlugin from beets.util import bytestring_path field_extension = mediafile.MediaField( mediafile.MP3DescStorageStyle(u'customtag'), mediafile.MP4StorageStyle('----:com.apple.iTunes:customtag'), mediafile.StorageStyle('customtag'), mediafile.ASFStorageStyle('customtag'), ) class ExtendedFieldTestMixin(_common.TestCase): def _mediafile_fixture(self, name, extension='mp3'): name = bytestring_path(name + '.' + extension) src = os.path.join(_common.RSRC, name) target = os.path.join(self.temp_dir, name) shutil.copy(src, target) return mediafile.MediaFile(target) def test_extended_field_write(self): plugin = BeetsPlugin() plugin.add_media_field('customtag', field_extension)