本文整理汇总了Python中mutagen.flac.FLAC.save方法的典型用法代码示例。如果您正苦于以下问题:Python FLAC.save方法的具体用法?Python FLAC.save怎么用?Python FLAC.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.FLAC
的用法示例。
在下文中一共展示了FLAC.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_two_invalid
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def test_two_invalid(tmpdir):
"""Test when two FLAC files have invalid tags."""
flac_dir = tmpdir.mkdir('flac')
flac_files = []
# One.
flac = flac_dir.join('Artist2 - 202 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title'))
tags.save()
flac_files.append(str(flac.realpath()))
# Two.
flac = flac_dir.join('Artist - 2014 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2014', album='Album', tracknumber='01', title='Title'))
tags.save()
flac_files.append(str(flac.realpath()))
# Test.
a_messages = find_inconsistent_tags(flac_files, True, True)
e_messages = {
flac_files[0]: ["Filename date not four digits."],
flac_files[1]: ["Artist mismatch: Artist != Artist2"],
}
assert e_messages == a_messages
示例2: test_one_valid_two_invalid
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def test_one_valid_two_invalid(tmpdir):
"""Test when one FLAC file is fully valid and another one isn't."""
flac_dir = tmpdir.mkdir('flac')
flac_files = []
# Valid.
flac = flac_dir.join('Artist2 - 2012 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title'))
tags.save()
flac_files.append(str(flac.realpath()))
# Invalid.
flac = flac_dir.join('Artist - 2014 - Album - 01 - Title.flac').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
tags = FLAC(str(flac.realpath()))
tags.update(dict(artist='Artist2', date='2014', album='Album', tracknumber='01', title='Title'))
tags.save()
flac_files.append(str(flac.realpath()))
# Test.
a_messages = find_inconsistent_tags(flac_files, True, True)
e_messages = {flac_files[1]: [
"Artist mismatch: Artist != Artist2",
]}
assert e_messages == a_messages
示例3: _tag_flac
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def _tag_flac(self, trackno):
""" Calls the mutagen library to perform metadata changes for FLAC files """
logging.debug("Tagging '%s'" % os.path.join(self.dest_dir_name,
self.file_tag_map[trackno][1]))
audio = FLAC(os.path.join(self.dest_dir_name,
self.file_tag_map[trackno][1]))
try:
encoding = audio["ENCODING"]
except:
encoding = ""
audio.delete()
# add FLAC tag data
audio["TITLE"] = self.tracks[trackno][1]
audio["ARTIST"] = self.tracks[trackno][0]
audio["ALBUM"] = self.title
audio["COMPOSER"] = self.artist
audio["ORGANIZATION"] = self.label
audio["CATALOGNUM"] = self.catno
audio["GENRE"] = self.genre
audio["YEAR"] = self.year
audio["TRACKNUMBER"] = str(trackno)
audio["TRACKTOTAL"] = str(len(self.tracks))
audio["DESCRIPTION"] = '::> Don\'t believe the hype! <::'
if(len(encoding) != 0):
audio["ENCODING"] = encoding
audio.pprint()
try:
audio.save()
except:
logging.error("Unable to tag '%s'" % self.file_tag_map[trackno][1])
raise DiscogsTaggerError, "Unable to write tag '%s'" % \
self.file_tag_map[trackno][1]
示例4: test_write_tags
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def test_write_tags(tmpdir):
"""Test writing tags from a FLAC to mp3 file."""
# Prepare.
flac = tmpdir.mkdir('flac').join('song.flac').ensure(file=True)
mp3 = tmpdir.mkdir('mp3').join('song.mp3').ensure(file=True)
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
flac.write(f.read(), 'wb')
with open(os.path.join(os.path.dirname(__file__), '1khz_sine.mp3'), 'rb') as f:
mp3.write(f.read(), 'wb')
flac, mp3 = str(flac.realpath()), str(mp3.realpath())
tags = FLAC(flac)
tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title', unsyncedlyrics='L'))
image = Picture()
image.type, image.mime = 3, 'image/jpeg'
with open(os.path.join(os.path.dirname(__file__), '1_album_art.jpg'), 'rb') as f:
image.data = f.read()
tags.add_picture(image)
tags.save()
# Test.
ConvertFiles.write_tags(flac, mp3)
# Check.
id3 = ID3(mp3)
assert 'Artist2' == id3['TPE1']
assert '2012' == id3['TDRC']
assert 'Album' == id3['TALB']
assert '01' == id3['TRCK']
assert 'Title' == id3['TIT2']
assert 'L' == id3["USLT:Lyrics:'eng'"].text
with open(os.path.join(os.path.dirname(__file__), '1_album_art.jpg'), 'rb') as f:
assert f.read() == id3['APIC:'].data
assert ({}, [], [], []) == find_files(str(tmpdir.join('flac')), str(tmpdir.join('mp3')))
示例5: __init__
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
class Id3tool:
''' class to read/write mp3 tags '''
def __init__(self, fn):
''' allow throw if file not supported '''
if fnmatch.fnmatch(fn, '*.ogg'):
self.tag_obj = OggVorbis(fn)
elif fnmatch.fnmatch(fn, '*.flac'):
self.tag_obj = FLAC(fn)
else:
self.tag_obj = EasyID3(fn)
def save(self):
self.tag_obj.save()
def readTag(self, tag):
if self.tag_obj:
tmp = self.tag_obj.get(unicode(tag))
return tmp[0] if tmp else ''
else:
return ''
def writeTag(self, tag, val):
self.tag_obj[unicode(tag)] = unicode(val)
示例6: copy_tags
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def copy_tags(filejoin, filenames):
""" Copia los tags de filenames a join """
extension = os.path.splitext(filejoin)[1]
if extension == '.flac':
tags_ori = FLAC(filenames[0])
tags_joi = FLAC(filejoin)
elif extension == '.ogg':
tags_ori = OggVorbis(filenames[0])
tags_joi = OggVorbis(filejoin)
else:
return
for item in tags_ori.items():
tags_joi[item[0]] = item[1]
# falta añadir lo del título... pero primero lo borramos
for ori in filenames[1:]:
if extension == '.flac':
tags_ori = FLAC(ori)
elif extension == '.ogg':
tags_ori = OggVorbis(ori)
last_track = tags_ori['tracknumber']
last_discnumber = tags_ori['discnumber']
print tags_ori['title']
tags_joi['title'] = tags_joi['title'] + tags_ori['title']
tags_joi['gapless_join'] = str(len(filenames))
tags_joi['gapless_last_track'] = last_track
tags_joi['gapless_last_discnumber'] = last_discnumber
tags_joi.save()
示例7: setSortTags
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def setSortTags(path):
ext = os.path.splitext(path)[1].lower()
meta = None
try:
if ext == '.mp3':
meta = MP3(path)
elif ext == '.m4a':
meta = MP4(path)
elif ext == '.flac':
meta = FLAC(path)
else:
return
except:
pass
if meta:
tagsToProcess = ('ALBUM', 'ALBUMARTIST', 'ARTIST', 'TITLE')
save = False
try:
for tag in tagsToProcess:
processed = checkTagMakeSort(path, meta, tag)
if (processed):
save = True
if save:
meta.save()
except:
pass
示例8: setImage
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def setImage(self, song):
audio = FLAC(song.get("~filename", ""))
if len(self.imgFiles) <= 0:
return
for p in self.imgFiles:
try:
audio.add_picture(p)
except:
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
示例9: on_save
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [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
示例10: write_field
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def write_field(self, file, field, value, bypassdbwrite=False):
filename, extension = os.path.splitext(file)
if extension.upper() == '.MP3':
# Try to open the ID3 tags
try:
audio = ID3(file)
except mutagen.id3.ID3NoHeaderError:
# Save a blank ID3 header first
audio = ID3()
id3field = self.MAP_ID3_FIELDS[field]
fieldtype, unused, fieldname = id3field.partition(':')
gentag = getattr(mutagen.id3, fieldtype)
audio[id3field] = gentag(encoding=3, desc=u'%s' % fieldname, text=value)
#audio['TXXX:TAG'] = TXXX(encoding=3, desc=u'TAG', text=tags)
elif extension.upper() == '.FLAC':
audio = FLAC(file)
audio[self.MAP_FLAC_FIELDS[field]] = value
audio.save(file)
print "[LIBRARY] Field '%s' written in file %s" % (field, os.path.basename(file))
# Update DB if needed
if file in self.map_track_info:
self.map_track_info[file][field] = value
if not bypassdbwrite:
self.save_database()
示例11: test_largest_valid
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [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()
示例12: set_image
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def set_image(self, image):
"""Replaces all embedded images by the passed image"""
with translate_errors():
tag = FLAC(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
tag.add_picture(pic)
with translate_errors():
tag.save()
# clear vcomment tags
super(FLACFile, self).clear_images()
self.has_images = True
示例13: test_force_shrink
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def test_force_shrink(self):
self.test_force_grow()
f = FLAC(self.NEW)
f["faketag"] = "foo"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["faketag"], ["foo"])
示例14: test_add_picture
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def test_add_picture(self):
f = FLAC(self.NEW)
c = len(f.pictures)
f.add_picture(Picture())
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(len(f.pictures), c + 1)
示例15: tag
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import save [as 别名]
def tag(self):
if self.type == 'Free Lossless Audio Codec':
f = FLAC(self.name)
tags = CUE_META.flac_tags(self.track_nr)
for t in tags[0]:
f[t] = tags[0][t]
f.save()