diff --git a/picard/formats/__init__.py b/picard/formats/__init__.py index d007fee75..17cc6bbc1 100644 --- a/picard/formats/__init__.py +++ b/picard/formats/__init__.py @@ -140,3 +140,6 @@ register_format(WAVFile) from picard.formats.midi import MIDIFile register_format(MIDIFile) + +from picard.formats.aac import AACFile +register_format(AACFile) diff --git a/picard/formats/aac.py b/picard/formats/aac.py new file mode 100644 index 000000000..bfd949a4a --- /dev/null +++ b/picard/formats/aac.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- +# +# Picard, the next-generation MusicBrainz tagger +# Copyright (C) 2018 Philipp Wolfer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +from mutagen.aac import AAC +from mutagen.apev2 import ( + APENoHeaderError, + APEv2, + error as APEError, +) + +from picard.formats.apev2 import APEv2File + + +class AACAPEv2(AAC): + def load(self, filething): + super().load(filething) + try: + self.tags = APEv2(filething) + except APENoHeaderError: + self.tags = None + + def add_tags(self): + if self.tags is None: + self.tags = APEv2() + else: + raise APEError("%r already has tags: %r" % (self, self.tags)) + + +class AACFile(APEv2File): + EXTENSIONS = [".aac"] + NAME = "AAC" + _File = AACAPEv2 + + def _info(self, metadata, file): + super()._info(metadata, file) + if file.tags: + metadata['~format'] = "%s (APEv2)" % self.NAME diff --git a/test/data/test-apev2.aac b/test/data/test-apev2.aac new file mode 100644 index 000000000..2a5926f0f Binary files /dev/null and b/test/data/test-apev2.aac differ diff --git a/test/data/test.aac b/test/data/test.aac new file mode 100644 index 000000000..2a5926f0f Binary files /dev/null and b/test/data/test.aac differ diff --git a/test/test_formats.py b/test/test_formats.py index 9c6a00965..892e98cc1 100644 --- a/test/test_formats.py +++ b/test/test_formats.py @@ -907,6 +907,23 @@ class TestCoverArt(PicardTestCase): self._tear_down() +class AACTest(PicardTestCase): + filename = os.path.join('test', 'data', 'test.aac') + + def setUp(self): + super().setUp() + config.setting = settings.copy() + + def test_can_open_and_save(self): + metadata = Metadata() + save_and_load_metadata(self.filename, metadata) + + +class AACWithAPETest(CommonTests.FormatsTest): + testfile = 'test-apev2.aac' + supports_ratings = False + + class WAVTest(PicardTestCase): filename = os.path.join('test', 'data', 'test.wav')