本文整理汇总了Python中mutagen.asf.ASF类的典型用法代码示例。如果您正苦于以下问题:Python ASF类的具体用法?Python ASF怎么用?Python ASF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ASF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _save
def _save(self, filename, metadata, settings):
self.log.debug("Saving file %r", filename)
file = ASF(encode_filename(filename))
if settings['clear_existing_tags']:
file.tags.clear()
if settings['save_images_to_tags']:
cover = []
for image in metadata.images:
if self.config.setting["save_only_front_images_to_tags"] and image["type"] != "front":
continue
imagetype = ID3_IMAGE_TYPE_MAP.get(image["type"], 0)
tag_data = pack_image(image["mime"], image["data"], imagetype,
image["description"])
cover.append(ASFByteArrayAttribute(tag_data))
if cover:
file.tags['WM/Picture'] = cover
for name, values in metadata.rawitems():
if name.startswith('lyrics:'):
name = 'lyrics'
elif name == '~rating':
values[0] = int(values[0]) * 99 / (settings['rating_steps'] - 1)
if name not in self.__TRANS:
continue
name = self.__TRANS[name]
file.tags[name] = map(unicode, values)
file.save()
示例2: setUp
def setUp(self):
fd, self.filename = mkstemp(suffix='wma')
os.close(fd)
shutil.copy(self.original, self.filename)
audio = ASF(self.filename)
audio["large_value1"] = "#" * 50000
audio.save()
示例3: test_save_large_bytearray
def test_save_large_bytearray(self):
audio = ASF(self.filename)
audio["QL/LargeObject"] = [ASFValue(b"." * (0xFFFF + 1), BYTEARRAY)]
audio.save()
self.failIf("QL/LargeObject" in audio.to_extended_content_description)
self.failIf("QL/LargeObject" in audio.to_metadata)
self.failIf("QL/LargeObject" not in dict(audio.to_metadata_library))
示例4: test_non_text_type
def test_non_text_type(self):
audio = ASF(self.filename)
audio["Author"] = [42]
audio.save()
self.assertFalse(audio.to_content_description)
new = ASF(self.filename)
self.assertEqual(new["Author"], [42])
示例5: TASFIssue29
class TASFIssue29(TestCase):
original = os.path.join("tests", "data", "issue_29.wma")
def setUp(self):
fd, self.filename = mkstemp(suffix='wma')
os.close(fd)
shutil.copy(self.original, self.filename)
self.audio = ASF(self.filename)
def tearDown(self):
os.unlink(self.filename)
def test_pprint(self):
self.audio.pprint()
def test_issue_29_description(self):
self.audio["Description"] = "Hello"
self.audio.save()
audio = ASF(self.filename)
self.failUnless("Description" in audio)
self.failUnlessEqual(audio["Description"], ["Hello"])
del(audio["Description"])
self.failIf("Description" in audio)
audio.save()
audio = ASF(self.filename)
self.failIf("Description" in audio)
示例6: _save
def _save(self, filename, metadata):
log.debug("Saving file %r", filename)
file = ASF(encode_filename(filename))
if config.setting['clear_existing_tags']:
file.tags.clear()
cover = []
for image in metadata.images_to_be_saved_to_tags:
tag_data = pack_image(image.mimetype, image.data,
image_type_as_id3_num(image.maintype),
image.comment)
cover.append(ASFByteArrayAttribute(tag_data))
if cover:
file.tags['WM/Picture'] = cover
for name, values in metadata.rawitems():
if name.startswith('lyrics:'):
name = 'lyrics'
elif name == '~rating':
values[0] = int(values[0]) * 99 / (config.setting['rating_steps'] - 1)
elif name == 'discnumber' and 'totaldiscs' in metadata:
values[0] = '%s/%s' % (metadata['discnumber'], metadata['totaldiscs'])
if name not in self.__TRANS:
continue
name = self.__TRANS[name]
file.tags[name] = map(unicode, values)
file.save()
示例7: _save
def _save(self, filename, metadata):
log.debug("Saving file %r", filename)
file = ASF(encode_filename(filename))
if config.setting['clear_existing_tags']:
file.tags.clear()
if config.setting['save_images_to_tags']:
cover = []
for image in metadata.images:
if not save_this_image_to_tags(image):
continue
tag_data = pack_image(image.mimetype, image.data,
image_type_as_id3_num(image.maintype()),
image.description)
cover.append(ASFByteArrayAttribute(tag_data))
if cover:
file.tags['WM/Picture'] = cover
for name, values in metadata.rawitems():
if name.startswith('lyrics:'):
name = 'lyrics'
elif name == '~rating':
values[0] = int(values[0]) * 99 / (config.setting['rating_steps'] - 1)
if name not in self.__TRANS:
continue
name = self.__TRANS[name]
file.tags[name] = map(unicode, values)
file.save()
示例8: test_save_large_string
def test_save_large_string(self):
audio = ASF(self.filename)
audio["QL/LargeObject"] = [ASFValue("." * 0x7FFF, UNICODE)]
audio.save()
self.failIf("QL/LargeObject" in audio.to_extended_content_description)
self.failIf("QL/LargeObject" in audio.to_metadata)
self.failIf("QL/LargeObject" not in dict(audio.to_metadata_library))
示例9: _save
def _save(self, filename, metadata):
log.debug("Saving file %r", filename)
file = ASF(encode_filename(filename))
if config.setting["clear_existing_tags"]:
file.tags.clear()
if config.setting["save_images_to_tags"]:
cover = []
for image in metadata.images:
if not save_this_image_to_tags(image):
continue
tag_data = pack_image(image["mime"], image["data"], image_type_as_id3_num(image["type"]), image["desc"])
cover.append(ASFByteArrayAttribute(tag_data))
if cover:
file.tags["WM/Picture"] = cover
for name, values in metadata.rawitems():
if name.startswith("lyrics:"):
name = "lyrics"
elif name == "~rating":
values[0] = int(values[0]) * 99 / (config.setting["rating_steps"] - 1)
if name not in self.__TRANS:
continue
name = self.__TRANS[name]
file.tags[name] = map(unicode, values)
file.save()
示例10: test_multiple_delete
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()
示例11: test_save_guid
def test_save_guid(self):
# https://github.com/quodlibet/mutagen/issues/81
audio = ASF(self.filename)
audio["QL/GuidObject"] = [ASFValue(b" " * 16, GUID)]
audio.save()
self.failIf("QL/GuidObject" in audio.to_extended_content_description)
self.failIf("QL/GuidObject" in audio.to_metadata)
self.failIf("QL/GuidObject" not in dict(audio.to_metadata_library))
示例12: test_issue_29_description
def test_issue_29_description(self):
self.audio["Description"] = "Hello"
self.audio.save()
audio = ASF(self.filename)
self.failUnless("Description" in audio)
self.failUnlessEqual(audio["Description"], ["Hello"])
del(audio["Description"])
self.failIf("Description" in audio)
audio.save()
audio = ASF(self.filename)
self.failIf("Description" in audio)
示例13: test_empty
def test_empty(self):
audio = ASF(self.filename)
audio["Author"] = [u"", u""]
audio["Title"] = [u""]
audio["Copyright"] = []
audio.save()
new = ASF(self.filename)
self.assertEqual(new["Author"], [u"", u""])
self.assertEqual(new["Title"], [u""])
self.assertFalse("Copyright" in new)
示例14: test_author_long
def test_author_long(self):
audio = ASF(self.filename)
# 2 ** 16 - 2 bytes encoded text + 2 bytes termination
just_small_enough = u"a" * (((2 ** 16) // 2) - 2)
audio["Author"] = [just_small_enough]
audio.save()
self.assertTrue(audio.to_content_description)
self.assertFalse(audio.to_metadata_library)
audio["Author"] = [just_small_enough + u"a"]
audio.save()
self.assertFalse(audio.to_content_description)
self.assertTrue(audio.to_metadata_library)
示例15: test_author
def test_author(self):
audio = ASF(self.filename)
values = [u"Foo", u"Bar", u"Baz"]
audio["Author"] = values
audio.save()
self.assertEqual(
list(audio.to_content_description.items()), [(u"Author", u"Foo")])
self.assertEqual(
audio.to_metadata_library,
[(u"Author", u"Bar"), (u"Author", u"Baz")])
new = ASF(self.filename)
self.assertEqual(new["Author"], values)