本文整理汇总了Python中mutagen.flac.FLAC.clear_pictures方法的典型用法代码示例。如果您正苦于以下问题:Python FLAC.clear_pictures方法的具体用法?Python FLAC.clear_pictures怎么用?Python FLAC.clear_pictures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.FLAC
的用法示例。
在下文中一共展示了FLAC.clear_pictures方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FlacStripper
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
class FlacStripper(MutagenStripper):
""" Represent a Flac audio file
"""
def _create_mfile(self):
self.mfile = FLAC(self.filename)
def remove_all(self):
""" Remove the "metadata" block from the file
"""
super(FlacStripper, self).remove_all()
self.mfile.clear_pictures()
self.mfile.save()
return True
def is_clean(self):
""" Check if the "metadata" block is present in the file
"""
return super(FlacStripper, self).is_clean() and not self.mfile.pictures
def get_meta(self):
""" Return the content of the metadata block if present
"""
metadata = super(FlacStripper, self).get_meta()
if self.mfile.pictures:
metadata['picture:'] = 'yes'
return metadata
示例2: on_save
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def on_save(self):
audio = FLAC(self.song.get("~filename", ""))
## if file has no images -> leave
if (audio.pictures is None) or (len(audio.pictures) <= 0):
return
## first,clear all pictures, then add the images in order
try:
audio.clear_pictures()
except:
self.printError()
return False
for row in self.liststore:
img = row[1]
try:
audio.add_picture(img)
except:
self.printError()
return False
audio.save()
count = 0
if (audio.pictures is None) or (len(audio.pictures) <= 0):
pass
else:
count = str(len(audio.pictures))
self.song["pictures"] = count
app.window.emit("artwork-changed", [self.song])
del self.coverlist[:]
self.liststore.clear()
self.start_search()
return True
示例3: test_clear_pictures
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def test_clear_pictures(self):
f = FLAC(self.NEW)
c1 = len(f.pictures)
c2 = len(f.metadata_blocks)
f.clear_pictures()
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(len(f.metadata_blocks), c2 - c1)
示例4: embed_cover_art
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def embed_cover_art(self, audio_file, cover_file):
"""Embeds cover art into an audio file.
Arguments:
audio_file (str): The path to the audio file to embed the artwork in.
cover_file (str): The path to the artwork file to embed.
"""
if path.isfile(audio_file) and path.isfile(cover_file):
mimetype = "image/png" if cover_file.endswith("png") else "image/jpeg"
artwork = open(cover_file, "rb").read()
desc = u"Cover Art"
# Determine which filetype we're handling
if audio_file.endswith("m4a"):
audio = MP4(audio_file)
covr = []
if cover_file.endswith("png"):
covr.append(MP4Cover(artwork, MP4Cover.FORMAT_PNG))
else:
covr.append(MP4Cover(artwork, MP4Cover.FORMAT_JPEG))
audio.tags["covr"] = covr
elif audio_file.endswith("mp3"):
audio = MP3(audio_file, ID3=ID3)
# Add ID3 tags if they don't exist
try:
audio.add_tags()
except error:
pass
audio.tags.add(
APIC(
encoding=3, # 3 is UTF-8
mime=mimetype,
type=3, # 3 is for cover artwork
desc=desc,
data=artwork,
)
)
elif audio_file.endswith("flac"):
audio = FLAC(audio_file)
image = Picture()
image.type = 3 # 3 is for cover artwork
image.mime = mimetype
image.desc = desc
image.data = artwork
audio.clear_pictures() # Clear existing pictures
audio.add_picture(image)
# Save the audio file
audio.save()
示例5: clear_images
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def clear_images(self):
"""Delete all embedded images"""
with translate_errors():
tag = FLAC(self["~filename"])
tag.clear_pictures()
tag.save()
# clear vcomment tags
super(FLACFile, self).clear_images()
self.has_images = False
示例6: remove_all
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def remove_all(self):
'''
Remove the "metadata" block from the file
'''
if self.backup is True:
shutil.copy2(self.filename, self.output)
self.filename = self.output
mfile = FLAC(self.filename)
mfile.delete()
mfile.clear_pictures()
mfile.save()
示例7: clear_images
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def clear_images(self):
"""Delete all embedded images"""
try:
tag = FLAC(self["~filename"])
except EnvironmentError:
return
tag.clear_pictures()
tag.save()
# clear vcomment tags
super(FLACFile, self).clear_images()
self.has_images = False
示例8: test_invalid_overflow_recover_and_save_back
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def test_invalid_overflow_recover_and_save_back(self):
# save a picture which is too large for flac, but still write it
# with a wrong block size
f = FLAC(self.filename)
f.clear_pictures()
pic = Picture()
pic.data = b"\x00" * (2 ** 24 - 32)
pic._invalid_overflow_size = 42
f.add_picture(pic)
f.save()
# make sure we can read it and save it again
f = FLAC(self.filename)
self.assertTrue(f.pictures)
self.assertEqual(len(f.pictures[0].data), 2 ** 24 - 32)
f.save()
示例9: removeImage
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def removeImage(self, song):
audio = FLAC(song.get("~filename", ""))
store = False
## if file has no images -> leave
if (audio.pictures is None) or (len(audio.pictures) <= 0):
return
images = list()
for img in audio.pictures:
if img.type == self.type \
and img.desc == self.desc:
store = True
else:
images.append(img)
if store:
## first,clear all pictures, then add the frontcover
try:
audio.clear_pictures()
except:
self.printError()
return False
## now add all other images
for img in images:
try:
audio.add_picture(img)
except:
self.printError()
return False
audio.save()
## and now count the images
count = "0"
## if file has no images -> set to 0
if (audio.pictures is None) or (len(audio.pictures) <= 0):
pass
else:
count = str(len(audio.pictures))
if not "pictures" in song:
song["pictures"] = count
if song["pictures"] <> count:
song["pictures"] = count
app.window.emit("artwork-changed", [song])
return
示例10: _FLACWrapper
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
class _FLACWrapper(_AbstractWrapper):
VALID_TAG_KEYS = ('artwork', 'artist', 'album', 'title', 'genre', )
def __init__(self, filename):
_AbstractWrapper.__init__(self)
self.audio = FLAC(filename)
def __getattr__(self, attr):
if attr in self.VALID_TAG_KEYS:
if attr == 'artwork':
if self.audio.pictures:
picture = self.audio.pictures[0]
return Artwork(picture.mime, picture.data)
else:
return None
else:
try:
return self.audio[attr][0]
except KeyError:
return None
raise TagError(self, attr)
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.clear_pictures()
self.audio.add_picture(picture)
elif isinstance(value, str):
self.audio[attr] = [value]
else:
raise TagValueError(value)
else:
object.__setattr__(self, attr, value)
def __repr__(self):
return repr(self.audio)
def save(self):
self.audio.save()
示例11: clearCoverArt
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def clearCoverArt(self):
for fileShortName in os.listdir(self.path):
fileName = os.path.join(self.path,fileShortName)
if os.path.isdir(fileName):
continue
try:
metadata = FLAC(fileName)
except FLACNoHeaderError as (strerror):
self.log.info("strerror=%s" % ( strerror))
continue
except error as E:
self.log.info("strerror=%s" % ( E))
continue
metadata.clear_pictures()
metadata.save()
del(metadata)
示例12: setImage
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def setImage(self, song):
audio = FLAC(song.get("~filename", ""))
## if file has no images -> leave
if (audio.pictures is None) or (len(audio.pictures) <= 0):
return
## if first image is frontcover -> leave
img = audio.pictures[0]
if img.type == 3:
return
## ok, we have to lookup the data...
images = list()
frontcover = None
for img in audio.pictures:
if img.type == 3:
frontcover = img
else:
images.append(img)
## if file has no frontcover -> leave
if (frontcover is None):
print(_("No frontcover found in {!s}.").format(song.get("~filename", "")))
return
## first,clear all pictures, then add the frontcover
try:
audio.clear_pictures()
audio.add_picture(frontcover)
except:
self.printError()
return False
## now add all other images
for img in images:
try:
audio.add_picture(img)
except:
self.printError()
return False
audio.save()
app.window.emit("artwork-changed", [song])
return
示例13: reset_flac_tags
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
def reset_flac_tags(full_path):
f = FLAC(full_path)
t = f.tags
# we need to save the 'vendor' string because calling mutagen's delete() removes it too
for block in list(f.metadata_blocks):
if isinstance(block, VCFLACDict):
vendor = block.vendor
f.clear_pictures()
f.delete()
for item in 'artist', 'album', 'tracknumber', 'tracktotal', 'title', 'date':
if item in t:
f[item] = t[item]
for block in list(f.metadata_blocks):
if isinstance(block, VCFLACDict):
block.vendor = vendor
f.save(deleteid3=True)
示例14: open
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import clear_pictures [as 别名]
print ["Sorry, i need piece of covert art labeled: ", picpath]
p_data = open(picpath).read()
# pic = Picture(
# encoding=3, # 3 is for utf-8
# mime='image/jpeg', # image/jpeg or image/png
# type=3, # 3 is for the cover image
# desc=u'Cover',
# data=p_data
# )
# apic = APIC(
# encoding=3, # 3 is for utf-8
# mime='image/jpeg', # image/jpeg or image/png
# type=3, # 3 is for the cover image
# desc=u'Cover',
# data=p_data
# )
pic = Picture()
pic.load(open(picpath))
flaccount = 0
flext = re.compile(".*\.flac")
for f in files:
if re.search(flext, f) != None:
flaccount = flaccount + 1
ftag = FLAC(f)
ftag.clear_pictures()
ftag.add_picture(pic)
ftag.save
exit(0)