本文整理汇总了Python中mutagen.flac.Picture.write方法的典型用法代码示例。如果您正苦于以下问题:Python Picture.write方法的具体用法?Python Picture.write怎么用?Python Picture.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.Picture
的用法示例。
在下文中一共展示了Picture.write方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_handle_picture_block
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def test_handle_picture_block(self):
pic = Picture()
pic.data = _get_jpeg()
pic.type = APICType.COVER_FRONT
b64pic_cover = base64.b64encode(pic.write())
pic2 = Picture()
pic2.data = _get_jpeg(size=6)
pic2.type = APICType.COVER_BACK
b64pic_other = base64.b64encode(pic2.write())
song = self.MutagenType(self.filename)
song["metadata_block_picture"] = [b64pic_other, b64pic_cover]
song.save()
song = self.QLType(self.filename)
self.failUnlessEqual(song("~picture"), "y")
fn = song.get_primary_image().file
self.failUnlessEqual(pic.data, fn.read())
song.write()
song = self.MutagenType(self.filename)
self.failUnless(b64pic_other in song["metadata_block_picture"])
self.failUnless(b64pic_cover in song["metadata_block_picture"])
song["metadata_block_picture"] = [b64pic_other]
song.save()
song = self.QLType(self.filename)
fn = song.get_primary_image().file
self.failUnlessEqual(pic2.data, fn.read())
示例2: test_handle_picture_block
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def test_handle_picture_block(self):
pic = Picture()
pic.data = self.__get_jpeg()
pic.type = 3
b64pic_cover = base64.b64encode(pic.write())
pic2 = Picture()
pic2.data = self.__get_jpeg(size=6)
pic2.type = 4
b64pic_other= base64.b64encode(pic2.write())
song = self.MutagenType(self.filename)
song["metadata_block_picture"] = [b64pic_other, b64pic_cover]
song.save()
song = self.QLType(self.filename)
self.failUnlessEqual(song("~picture"), "y")
fn = song.find_cover()
self.failUnlessEqual(pic.data, fn.read())
song.write()
song = self.MutagenType(self.filename)
self.failUnless(b64pic_other in song["metadata_block_picture"])
self.failUnless(b64pic_cover in song["metadata_block_picture"])
song["metadata_block_picture"] = [b64pic_other]
song.save()
song = self.QLType(self.filename)
fn = song.find_cover()
self.failUnlessEqual(pic2.data, fn.read())
示例3: test_largest_valid
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def test_largest_valid(self):
f = FLAC(self.filename)
pic = Picture()
pic.data = b"\x00" * (2 ** 24 - 1 - 32)
self.assertEqual(len(pic.write()), 2 ** 24 - 1)
f.add_picture(pic)
f.save()
示例4: test_get_images
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def test_get_images(self):
pic = Picture()
pic.data = _get_jpeg()
pic.type = APICType.COVER_FRONT
b64pic_cover = base64.b64encode(pic.write())
# metadata_block_picture
song = FLAC(self.filename)
song["metadata_block_picture"] = [b64pic_cover]
song.save()
song = FLACFile(self.filename)
self.assertEqual(len(song.get_images()), 1)
self.assertEqual(song.get_images()[0].type, APICType.COVER_FRONT)
# flac Picture
song = FLAC(self.filename)
pic = Picture()
pic.data = _get_jpeg()
pic.type = APICType.COVER_BACK
song.add_picture(pic)
song.save()
song = FLACFile(self.filename)
self.assertEqual(len(song.get_images()), 2)
self.assertEqual(song.get_images()[-1].type, APICType.COVER_BACK)
示例5: set_image
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def set_image(self, image):
"""Replaces all embedded images by the passed image"""
with translate_errors():
audio = self.MutagenType(self["~filename"])
try:
data = image.read()
except EnvironmentError as e:
raise AudioFileError(e)
pic = Picture()
pic.data = data
pic.type = APICType.COVER_FRONT
pic.mime = image.mime_type
pic.width = image.width
pic.height = image.height
pic.depth = image.color_depth
audio.pop("coverart", None)
audio.pop("coverartmime", None)
audio["metadata_block_picture"] = base64.b64encode(
pic.write()).decode("ascii")
with translate_errors():
audio.save()
self.has_images = True
示例6: download_and_fix_ogg
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def download_and_fix_ogg(ogg, audio_metadata, cover_art_file):
global DRY_RUN
if DRY_RUN:
print "This is a dry run. So pretending to download the ogg..."
return "/tmp/ogg"
print "Now downloading the ogg in order to set the metadata in it..."
if not LIVE and len(sys.argv) >= 6 and os.path.exists(sys.argv[5]):
ogg_local_fn = sys.argv[5]
print "(using presupplied file %s)" % ogg_local_fn
else:
f, metadata = client.get_file_and_metadata(ogg)
ogg_local_fn = fetch_file(f, metadata)
print "Successfully downloaded (to %s): now editing metadata..." % ogg_local_fn
audio = OggVorbis(ogg_local_fn)
for k in audio_metadata.keys():
audio[k] = audio_metadata[k]
# add cover art
im=Image.open(cover_art_file)
w,h=im.size
p=Picture()
imdata=open(cover_art_file,'rb').read()
p.data=imdata
p.type=3
p.desc=''
p.mime='image/jpeg';
p.width=w; p.height=h
p.depth=24
dt=p.write();
enc=base64.b64encode(dt).decode('ascii');
audio['metadata_block_picture']=[enc];
audio.save()
print "Successfully updated metadata."
return ogg_local_fn
示例7: _set_tag
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def _set_tag(self, raw, tag, value):
if tag == 'metadata_block_picture':
new_value = []
for v in value:
picture = Picture()
picture.type = v.type
picture.desc = v.desc
picture.mime = v.mime
picture.data = v.data
new_value.append(base64.b64encode(picture.write()))
value = new_value
else:
# vorbis has text based attributes, so convert everything to unicode
value = [xl.unicode.to_unicode(v) for v in value]
CaseInsensitveBaseFormat._set_tag(self, raw, tag, value)
示例8: __setattr__
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def __setattr__(self, attr, value):
if attr in self.VALID_TAG_KEYS:
if isinstance(value, Artwork):
picture = Picture()
picture.type = 3
picture.mime = value.mime
picture.data = value.data
self.audio['metadata_block_picture'] = [
b64encode(picture.write()).decode('utf-8')
]
elif isinstance(value, str):
self.audio[attr] = [value]
else:
raise TagValueError(value)
else:
object.__setattr__(self, attr, value)
示例9: ogg_coverart
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def ogg_coverart(config):
print("Adding " + config.coverart_mime + " cover art to " + config.ogg_file)
coverart = config.coverart
imgdata = open(coverart,'rb').read()
im = Image.open(coverart)
w,h = im.size
p = Picture()
p.data = imgdata
p.type = 3
p.desc = 'Cover'
p.mime = config.coverart_mime
p.width = w
p.height = h
p.depth = 24
dt=p.write()
enc=base64.b64encode(dt).decode('ascii')
audio = OggVorbis(config.ogg_file)
audio['metadata_block_picture']=[enc]
audio.save()
示例10: set_image
# 需要导入模块: from mutagen.flac import Picture [as 别名]
# 或者: from mutagen.flac.Picture import write [as 别名]
def set_image(self, image):
"""Replaces all embedded images by the passed image"""
try:
audio = self.MutagenType(self["~filename"])
data = image.file.read()
except EnvironmentError:
return
pic = Picture()
pic.data = data
pic.type = APICType.COVER_FRONT
pic.mime = image.mime_type
pic.width = image.width
pic.height = image.height
pic.depth = image.color_depth
audio.pop("coverart", None)
audio.pop("coverartmime", None)
audio["metadata_block_picture"] = base64.b64encode(pic.write())
audio.save()
self.has_images = True