mirror of
https://github.com/beetbox/beets.git
synced 2025-12-07 17:16:07 +01:00
Implement ImageListField for WMA
This commit is contained in:
parent
806d3cc6e9
commit
63def728dc
3 changed files with 18 additions and 15 deletions
|
|
@ -691,7 +691,6 @@ class ASFImageStorageStyle(ListStorageStyle):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(ASFImageStorageStyle, self).__init__(key='WM/Picture')
|
super(ASFImageStorageStyle, self).__init__(key='WM/Picture')
|
||||||
self.as_type = str
|
|
||||||
|
|
||||||
def fetch(self, mutagen_file):
|
def fetch(self, mutagen_file):
|
||||||
if 'WM/Picture' not in mutagen_file:
|
if 'WM/Picture' not in mutagen_file:
|
||||||
|
|
@ -700,19 +699,18 @@ class ASFImageStorageStyle(ListStorageStyle):
|
||||||
pictures = []
|
pictures = []
|
||||||
for picture in mutagen_file['WM/Picture']:
|
for picture in mutagen_file['WM/Picture']:
|
||||||
try:
|
try:
|
||||||
pictures.append(_unpack_asf_image(picture.value)[1])
|
mime, data, type, desc = _unpack_asf_image(picture.value)
|
||||||
except:
|
except:
|
||||||
pass
|
continue
|
||||||
|
pictures.append(TagImage(data, desc=desc, type=type))
|
||||||
return pictures
|
return pictures
|
||||||
|
|
||||||
def store(self, mutagen_file, images):
|
def serialize(self, image):
|
||||||
if 'WM/Picture' in mutagen_file:
|
pic = mutagen.asf.ASFByteArrayAttribute()
|
||||||
del mutagen_file['WM/Picture']
|
pic.value = _pack_asf_image(image.mime_type, image.data,
|
||||||
|
type=image.type_index or 3,
|
||||||
for image in images:
|
description=image.desc or u'')
|
||||||
pic = mutagen.asf.ASFByteArrayAttribute()
|
return pic
|
||||||
pic.value = _pack_asf_image(_image_mime_type(image), image)
|
|
||||||
mutagen_file['WM/Picture'] = [pic]
|
|
||||||
|
|
||||||
|
|
||||||
class VorbisImageStorageStyle(ListStorageStyle):
|
class VorbisImageStorageStyle(ListStorageStyle):
|
||||||
|
|
@ -971,7 +969,7 @@ class CoverArtField(MediaField):
|
||||||
)
|
)
|
||||||
|
|
||||||
def __get__(self, mediafile, _):
|
def __get__(self, mediafile, _):
|
||||||
if mediafile.type in ['mp3', 'flac'] + VorbisImageStorageStyle.formats:
|
if mediafile.type in ['mp3', 'flac', 'asf'] + VorbisImageStorageStyle.formats:
|
||||||
try:
|
try:
|
||||||
return mediafile.images[0].data
|
return mediafile.images[0].data
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|
@ -980,7 +978,7 @@ class CoverArtField(MediaField):
|
||||||
return style.get(mediafile.mgfile)
|
return style.get(mediafile.mgfile)
|
||||||
|
|
||||||
def __set__(self, mediafile, data):
|
def __set__(self, mediafile, data):
|
||||||
if mediafile.type in ['mp3', 'flac'] + VorbisImageStorageStyle.formats:
|
if mediafile.type in ['mp3', 'flac', 'asf'] + VorbisImageStorageStyle.formats:
|
||||||
if data:
|
if data:
|
||||||
mediafile.images = [TagImage(data=data)]
|
mediafile.images = [TagImage(data=data)]
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
BIN
test/rsrc/image.wma
Normal file
BIN
test/rsrc/image.wma
Normal file
Binary file not shown.
|
|
@ -115,7 +115,11 @@ class ImageStructureTestMixin(object):
|
||||||
|
|
||||||
mediafile = MediaFile(mediafile.path)
|
mediafile = MediaFile(mediafile.path)
|
||||||
self.assertEqual(len(mediafile.images), 3)
|
self.assertEqual(len(mediafile.images), 3)
|
||||||
self.assertExtendedImageAttributes(mediafile.images[2],
|
|
||||||
|
# WMA does not preserve the order, so we have to work around this
|
||||||
|
image = filter(lambda i: i.desc == 'the composer',
|
||||||
|
mediafile.images)[0]
|
||||||
|
self.assertExtendedImageAttributes(image,
|
||||||
desc='the composer', type=TagImage.TYPES.composer)
|
desc='the composer', type=TagImage.TYPES.composer)
|
||||||
|
|
||||||
@unittest.skip('editing list by reference is not implemented yet')
|
@unittest.skip('editing list by reference is not implemented yet')
|
||||||
|
|
@ -590,7 +594,8 @@ class MusepackTest(ReadWriteTestBase, GenreListTestMixin, unittest.TestCase):
|
||||||
'bitdepth': 0,
|
'bitdepth': 0,
|
||||||
'channels': 2,
|
'channels': 2,
|
||||||
}
|
}
|
||||||
class WMATest(ReadWriteTestBase, unittest.TestCase):
|
class WMATest(ReadWriteTestBase, ExtendedImageStructureTestMixin,
|
||||||
|
unittest.TestCase):
|
||||||
extension = 'wma'
|
extension = 'wma'
|
||||||
audio_properties = {
|
audio_properties = {
|
||||||
'length': 1.0,
|
'length': 1.0,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue