Initial support for ALAC encoded audio files

Both AAC and ALAC are normally embedded in an .m4a container. For
this reason I have split the m4a type into aac and alac types.

To distinguish between the two encodings I have taken advantage
of the fact that, in my collection, ALAC don't have a sample_rate
set. I could not find verification if this is always the case
or not. Would bitrate be a more reliable determining factor?
e.g. if bitrate > 320000: type = 'alac'

Signed-off-by: Simon Luijk <simon@simonluijk.com>
This commit is contained in:
Simon Luijk 2013-05-29 21:25:23 +02:00
parent e75718d196
commit 0309775a91

View file

@ -73,7 +73,8 @@ class FileTypeError(UnreadableFileError):
# Human-readable type names.
TYPES = {
'mp3': 'MP3',
'mp4': 'AAC',
'aac': 'AAC',
'alac': 'ALAC',
'ogg': 'OGG',
'flac': 'FLAC',
'ape': 'APE',
@ -532,8 +533,10 @@ class MediaField(object):
obj.mgfile[style.key] = out
def _styles(self, obj):
if obj.type in ('mp3', 'mp4', 'asf'):
if obj.type in ('mp3', 'asf'):
styles = self.styles[obj.type]
elif obj.type in ('aac', 'alac'):
styles = self.styles['mp4']
else:
styles = self.styles['etc'] # Sane styles.
@ -568,7 +571,7 @@ class MediaField(object):
out = out[:-len(style.suffix)]
# MPEG-4 freeform frames are (should be?) encoded as UTF-8.
if obj.type == 'mp4' and style.key.startswith('----:') and \
if obj.type in ('aac', 'alac') and style.key.startswith('----:') and \
isinstance(out, str):
out = out.decode('utf8')
@ -636,7 +639,7 @@ class MediaField(object):
# MPEG-4 "freeform" (----) frames must be encoded as UTF-8
# byte strings.
if obj.type == 'mp4' and style.key.startswith('----:') and \
if obj.type in ('aac', 'alac') and style.key.startswith('----:') and \
isinstance(out, unicode):
out = out.encode('utf8')
@ -723,7 +726,7 @@ class ImageField(object):
return picframe.data
elif obj.type == 'mp4':
elif obj.type in ('aac', 'alac'):
if 'covr' in obj.mgfile:
covers = obj.mgfile['covr']
if covers:
@ -795,7 +798,7 @@ class ImageField(object):
)
obj.mgfile['APIC'] = picframe
elif obj.type == 'mp4':
elif obj.type in ('aac', 'alac'):
if val is None:
if 'covr' in obj.mgfile:
del obj.mgfile['covr']
@ -880,7 +883,11 @@ class MediaFile(object):
raise FileTypeError('file type unsupported by Mutagen')
elif type(self.mgfile).__name__ == 'M4A' or \
type(self.mgfile).__name__ == 'MP4':
self.type = 'mp4'
if hasattr(self.mgfile.info, 'sample_rate') and \
self.mgfile.info.sample_rate > 0:
self.type = 'aac'
else:
self.type = 'alac'
elif type(self.mgfile).__name__ == 'ID3' or \
type(self.mgfile).__name__ == 'MP3':
self.type = 'mp3'