Beispiel #1
0
class TASFSave(TestCase):
    # https://github.com/quodlibet/mutagen/issues/81#issuecomment-207014936

    original = os.path.join(DATA_DIR, "silence-1.wma")

    def setUp(self):
        self.filename = get_temp_copy(self.original)
        self.audio = ASF(self.filename)

    def tearDown(self):
        os.unlink(self.filename)

    def test_save_filename(self):
        self.audio.save(self.audio.filename)

    def test_multiple_delete(self):
        self.audio["large_value1"] = "#" * 50000
        self.audio.save()

        audio = ASF(self.filename)
        for tag in audio.keys():
            del (audio[tag])
            audio.save()

    def test_readd_objects(self):
        header = self.audio._header
        del header.objects[:]
        self.audio.save()
        self.assertTrue(header.get_child(ContentDescriptionObject.GUID))
        self.assertTrue(header.get_child(
            ExtendedContentDescriptionObject.GUID))
        self.assertTrue(header.get_child(HeaderExtensionObject.GUID))
        ext = header.get_child(HeaderExtensionObject.GUID)
        self.assertTrue(ext.get_child(MetadataObject.GUID))
        self.assertTrue(ext.get_child(MetadataLibraryObject.GUID))

    def test_keep_others(self):
        self.audio.save()
        new = ASF(self.filename)
        self.assertTrue(new._header.get_child(CodecListObject.GUID))

    def test_padding(self):
        old_tags = sorted(self.audio.items())

        def get_padding(fn):
            header = ASF(fn)._header
            return len(header.get_child(PaddingObject.GUID).data)

        for i in [0, 1, 2, 3, 42, 100, 5000, 30432, 1]:

            def padding_cb(info):
                self.assertEqual(info.size, 30432)
                return i

            self.audio.save(padding=padding_cb)
            self.assertEqual(get_padding(self.filename), i)

        last = ASF(self.filename)
        self.assertEqual(sorted(last.items()), old_tags)
Beispiel #2
0
class TASFSave(TestCase):
    # https://github.com/quodlibet/mutagen/issues/81#issuecomment-207014936

    original = os.path.join(DATA_DIR, "silence-1.wma")

    def setUp(self):
        self.filename = get_temp_copy(self.original)
        self.audio = ASF(self.filename)

    def tearDown(self):
        os.unlink(self.filename)

    def test_save_filename(self):
        self.audio.save(self.audio.filename)

    def test_multiple_delete(self):
        self.audio["large_value1"] = "#" * 50000
        self.audio.save()

        audio = ASF(self.filename)
        for tag in audio.keys():
            del(audio[tag])
            audio.save()

    def test_readd_objects(self):
        header = self.audio._header
        del header.objects[:]
        self.audio.save()
        self.assertTrue(header.get_child(ContentDescriptionObject.GUID))
        self.assertTrue(
            header.get_child(ExtendedContentDescriptionObject.GUID))
        self.assertTrue(header.get_child(HeaderExtensionObject.GUID))
        ext = header.get_child(HeaderExtensionObject.GUID)
        self.assertTrue(ext.get_child(MetadataObject.GUID))
        self.assertTrue(ext.get_child(MetadataLibraryObject.GUID))

    def test_keep_others(self):
        self.audio.save()
        new = ASF(self.filename)
        self.assertTrue(new._header.get_child(CodecListObject.GUID))

    def test_padding(self):
        old_tags = sorted(self.audio.items())

        def get_padding(fn):
            header = ASF(fn)._header
            return len(header.get_child(PaddingObject.GUID).data)

        for i in [0, 1, 2, 3, 42, 100, 5000, 30432, 1]:

            def padding_cb(info):
                self.assertEqual(info.size, 30432)
                return i

            self.audio.save(padding=padding_cb)
            self.assertEqual(get_padding(self.filename), i)

        last = ASF(self.filename)
        self.assertEqual(sorted(last.items()), old_tags)
Beispiel #3
0
    def test_padding(self):
        old_tags = sorted(self.audio.items())

        def get_padding(fn):
            header = ASF(fn)._header
            return len(header.get_child(PaddingObject.GUID).data)

        for i in [0, 1, 2, 3, 42, 100, 5000, 30432, 1]:

            def padding_cb(info):
                self.assertEqual(info.size, 30432)
                return i

            self.audio.save(padding=padding_cb)
            self.assertEqual(get_padding(self.filename), i)

        last = ASF(self.filename)
        self.assertEqual(sorted(last.items()), old_tags)
Beispiel #4
0
    def test_padding(self):
        old_tags = sorted(self.audio.items())

        def get_padding(fn):
            header = ASF(fn)._header
            return len(header.get_child(PaddingObject.GUID).data)

        for i in [0, 1, 2, 3, 42, 100, 5000, 30432, 1]:

            def padding_cb(info):
                self.assertEqual(info.size, 30432)
                return i

            self.audio.save(padding=padding_cb)
            self.assertEqual(get_padding(self.filename), i)

        last = ASF(self.filename)
        self.assertEqual(sorted(last.items()), old_tags)
Beispiel #5
0
def addTagsToMP3(file_path, mp3_file_path, file_ext):
    """Gets the existing tags from the mp4 file and saves them to the mp3

    Arguments:
        mp4_file_path {str} -- Path for MP4 file
        mp3_file_path {str} -- Path for MP3 file
    """

    original_file_tags = None
    mp3_tags = EasyID3(mp3_file_path)
    if file_ext == "m4a":
        original_file_tags = EasyMP4(file_path)
        for k, v in original_file_tags.items():
            found_tag = EXTENSION_MAPPING.get(k, None)
            if found_tag is not None:
                resulting_tag = CONVERSION_TABLE[found_tag]["mp3"]
                mp3_tags[resulting_tag] = [v]
                print("Added tag {0}:{1} to mp3 {2}".format(
                    resulting_tag, v, mp3_file_path))
    elif file_ext in ["wma", "wmv"]:
        original_file_tags = ASF(file_path).tags
        for k, v in original_file_tags.items():
            found_tag = EXTENSION_MAPPING.get(k, None)
            if found_tag is not None:
                resulting_tag = CONVERSION_TABLE[found_tag]["mp3"]
                if file_ext in ["wma", "wmv"]:
                    if resulting_tag == "composer":
                        if mp3_tags.get(resulting_tag, None):
                            mp3_tags[resulting_tag] = ["{0}, {1}"].format(
                                mp3_tags[resulting_tag][0], v[0].value)
                        else:
                            mp3_tags[resulting_tag] = [v[0].value]
                    else:
                        mp3_tags[resulting_tag] = [v[0].value]
                print("Added tag {0}:{1} to mp3 {2}".format(
                    resulting_tag, v[0], mp3_file_path))
    else:
        return
    mp3_tags.save(mp3_file_path)
    print("MP3 tags saved to {0}".format(mp3_file_path))