def add_if_exist(obj, tag_key): if obj is None: return if isinstance(obj, str): ape_meta.tags[tag_key] = APEValue(obj, TEXT) elif isinstance(obj, bytes): ape_meta.tags[tag_key] = APEValue(obj, BINARY) else: raise ValueError("Unknown tag value type")
def test_invalid_coverart(self): metadata = { 'Cover Art (Front)': APEValue(b'filename.png\0NOTPNGDATA', BINARY) } save_raw(self.filename, metadata) loaded_metadata = load_metadata(self.filename) self.assertEqual(0, len(loaded_metadata.images))
def test_binary_ignore(self): m = mutagen.apev2.APEv2(self.f) m["foo"] = APEValue(b"bar", BINARY) m.save() self.s.reload() self.failUnlessEqual(self.s.get("foo"), None) self.s.write() m = mutagen.apev2.APEv2(self.f) self.failUnless("foo" in m)
def pic_to_bin(pic): desc = pic[util.DESCRIPTION].encode('utf8') data = pic[util.DATA] covertype = pic[util.IMAGETYPE] key = 'Cover Art (Back)' if covertype == 4 else 'Cover Art (Front)' if data: return {key: APEValue(''.join((desc, '\x00', data)), BINARY)} return {}
def test_clear_tags_preserve_images_all(self): imagedata = APEValue(b'filename.png\0' + create_fake_png(b'a'), BINARY) save_raw( self.filename, { 'Cover Art (Front)': imagedata, 'Cover Art': imagedata, 'Cover Art (foo)': imagedata, 'cover art (bar)': imagedata, }) config.setting['clear_existing_tags'] = True config.setting['preserve_images'] = True metadata = save_and_load_metadata(self.filename, Metadata()) self.assertEqual(4, len(metadata.images)) config.setting['preserve_images'] = False metadata = save_and_load_metadata(self.filename, Metadata()) self.assertEqual(0, len(metadata.images))