本文整理汇总了Python中mutagen.flac.FLAC.keys方法的典型用法代码示例。如果您正苦于以下问题:Python FLAC.keys方法的具体用法?Python FLAC.keys怎么用?Python FLAC.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.flac.FLAC
的用法示例。
在下文中一共展示了FLAC.keys方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getsubmission
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def getsubmission(tfile):
data = open(tfile).read()
torrent = decode(data)
tname = torrent['info']['name']
for file in torrent["info"]["files"]:
name = "/".join(file["path"])
flac_re = re.compile(".flac")
if flac_re.search(name) != None:
flacname=name
log_re = re.compile(".log")
if log_re.search(name) !=None:
logname=name
fpath = os.path.join(tname,flacname)
lpath = os.path.join(tname,logname)
audio = FLAC(fpath)
print audio.keys()
if not audio.has_key('musicbrainz_albumid'):
print "ReleaseID tag is not set. Has this flac been tagged by picard?"
return(-1)
albumid = audio['musicbrainz_albumid'][0]
print albumid
q = ws.Query()
try:
inc = ws.ReleaseIncludes(artist=True, releaseEvents=True, labels=True,
discs=True, tracks=True)
release = q.getReleaseById(albumid, inc)
except ws.WebServiceError, e:
print 'Error:', e
return(-1)
示例2: get_album_and_artist
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def get_album_and_artist(self):
""" Return FLAC tags for album and artist"""
self.audio_files.sort()
for file in self.audio_files:
try:
tags = FLAC(file)
if tags:
if "album" in tags.keys() and "artist" in tags.keys():
return (tags["album"][0], tags["artist"][0])
break # If we found ID3 tag info from a file, no reason to query the rest in a directory.
except mutagen.flac.FLACNoHeaderError:
continue
return (None, None)
示例3: check_flac_tags
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def check_flac_tags(full_path, e):
t = {} # "proper" tags
tags = FLAC(full_path)
unallowed = set(tags.keys()).difference(flac_allow)
if unallowed:
for item in unallowed:
e.append("Unallowed tag: '" + item + "' - remove")
# "minimal" tags
for item in 'album', 'tracknumber', 'title', 'date':
t[item] = tags[item][0]
# Handle multiple artist tags in single track
if len(tags['artist']) > 1:
t['artist'] = ", ".join(tags['artist'])
else:
t['artist'] = tags['artist'][0]
# "optional" tags
for item in 'tracktotal', 'genre', 'albumartist', 'discnumber', 'disctotal':
if item in tags:
t[item] = tags[item][0]
else:
t[item] = None
return t, e
示例4: media_info
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def media_info(f):
aid_re = re.compile("brainz.*album.*id",re.I)
has_info = 0
ext = os.path.splitext(f)[-1]
if ext == ".mp3":
has_info = 1
info = ID3(f)
format = "MP3"
if ext == ".flac":
has_info = 1
info = FLAC(f)
format = "FLAC"
if ext == ".ogg":
has_info = 1
info = OggVorbis(f)
format = "OGG"
if not has_info:
return {}
for k in info.keys():
if re.search(aid_re,k) != None:
aid = info[k]
if type(aid) ==mutagen.id3.TXXX:
aid = aid.__unicode__()
if type(aid) == type([0]):
aid = aid[0]
info_d = {}
info_d['mbid'] = aid
return info_d
示例5: get_album_and_artist
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def get_album_and_artist(self):
""" Return FLAC tags for album and artist"""
self.audio_files.sort()
for file in self.audio_files:
try:
tags = FLAC(file)
if tags:
if "album" in tags.keys() and "artist" in tags.keys():
logger.debug(u'album -> {album}, artist -> {artist}'.format(album=tags["album"][0], artist=tags["artist"][0]))
return (tags["album"][0], tags["artist"][0])
break # If we found ID3 tag info from a file, no reason to query the rest in a directory.
except mutagen.flac.FLACNoHeaderError:
logger.error(u'No FLAC Header data')
continue
return (None, None)
示例6: copy_id3tag
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def copy_id3tag(src, des):
from subprocess import call
f = FLAC(src)
args = ["neroAacTag", des]
for key in f.keys():
args.extend([_rectify(key) + "=" + f[key][0],])
print args
call(args)
示例7: extract_taginfo
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def extract_taginfo(self):
taginfo = { }
try :
tagproxy = FLAC(self.filename)
except ValueError :
return { }
for key in tagproxy.keys():
taginfo[key.lower()] = tagproxy[key][0]
return taginfo
示例8: get_artwork
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def get_artwork(filename):
if not filename.endswith(".flac"):
print "This program is strictly intended for use with flac files"
exit(1)
flacinfo = FLAC(filename)
if 'album' not in flacinfo.keys() or 'album' not in flacinfo.keys():
print("Missing album or artist" + filename)
artist=flacinfo["artist"][0].encode('utf-8')
album=flacinfo["album"][0].encode('utf-8')
print artist,album
folder = os.path.dirname(os.path.realpath(filename))
coverpath = "".join([folder, os.path.sep, "cover.jpg"])
if os.path.isfile(coverpath): return
cmd = "glyrc cover --artist \'{0}\' --album \'{1}\' --write \'{2}\'".format(artist, album, coverpath)
out = get_shell_cmd_output(cmd)
print(out)
示例9: printFLAC
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def printFLAC(flacFile):
from mutagen.flac import FLAC, Picture
audio = FLAC(flacFile)
print "--FLAC--------------------------------------------"
for tag in audio.keys():
for text in audio[tag]:
if 'APIC' in tag:
print("Tag %s" % (tag) )
else:
print("Tag %s: %s" % (tag, text) )
pics = audio.pictures
for p in pics:
print("Bild gefunden. Typ %s: %s" % (p.type, p.desc) )
示例10: TFLAC
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
class TFLAC(TestCase):
SAMPLE = os.path.join("tests", "data", "silence-44-s.flac")
NEW = SAMPLE + ".new"
def setUp(self):
shutil.copy(self.SAMPLE, self.NEW)
self.failUnlessEqual(open(self.SAMPLE).read(), open(self.NEW).read())
self.flac = FLAC(self.NEW)
def test_delete(self):
self.failUnless(self.flac.tags)
self.flac.delete()
self.failIf(self.flac.tags)
flac = FLAC(self.NEW)
self.failIf(flac.tags)
def test_module_delete(self):
delete(self.NEW)
flac = FLAC(self.NEW)
self.failIf(flac.tags)
def test_info(self):
self.failUnlessAlmostEqual(FLAC(self.NEW).info.length, 3.7, 1)
def test_keys(self):
self.failUnlessEqual(self.flac.keys(), self.flac.tags.keys())
def test_values(self):
self.failUnlessEqual(self.flac.values(), self.flac.tags.values())
def test_items(self):
self.failUnlessEqual(self.flac.items(), self.flac.tags.items())
def test_vc(self):
self.failUnlessEqual(self.flac['title'][0], 'Silence')
def test_write_nochange(self):
f = FLAC(self.NEW)
f.save()
self.failUnlessEqual(open(self.SAMPLE).read(), open(self.NEW).read())
def test_write_changetitle(self):
f = FLAC(self.NEW)
f["title"] = "A New Title"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["title"][0], "A New Title")
def test_write_changetitle_unicode_value(self):
f = FLAC(self.NEW)
f["title"] = u"A Unicode Title \u2022"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["title"][0], u"A Unicode Title \u2022")
def test_write_changetitle_unicode_key(self):
f = FLAC(self.NEW)
f[u"title"] = "A New Title"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f[u"title"][0], "A New Title")
def test_write_changetitle_unicode_key_and_value(self):
f = FLAC(self.NEW)
f[u"title"] = u"A Unicode Title \u2022"
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f[u"title"][0], u"A Unicode Title \u2022")
def test_force_grow(self):
f = FLAC(self.NEW)
f["faketag"] = ["a" * 1000] * 1000
f.save()
f = FLAC(self.NEW)
self.failUnlessEqual(f["faketag"], ["a" * 1000] * 1000)
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"])
def test_add_vc(self):
f = FLAC(os.path.join("tests", "data", "no-tags.flac"))
self.failIf(f.tags)
f.add_tags()
self.failUnless(f.tags == [])
self.failUnlessRaises(ValueError, f.add_tags)
def test_add_vc_implicit(self):
f = FLAC(os.path.join("tests", "data", "no-tags.flac"))
self.failIf(f.tags)
f["foo"] = "bar"
self.failUnless(f.tags == [("foo", "bar")])
self.failUnlessRaises(ValueError, f.add_tags)
def test_ooming_vc_header(self):
# issue 112: Malformed FLAC Vorbis header causes out of memory error
# http://code.google.com/p/mutagen/issues/detail?id=112
#.........这里部分代码省略.........
示例11: TFLAC
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
class TFLAC(TestCase):
SAMPLE = os.path.join(DATA_DIR, "silence-44-s.flac")
def setUp(self):
self.NEW = get_temp_copy(self.SAMPLE)
self.flac = FLAC(self.NEW)
def tearDown(self):
os.unlink(self.NEW)
def test_zero_samples(self):
# write back zero sample count and load again
self.flac.info.total_samples = 0
self.flac.save()
new = FLAC(self.flac.filename)
assert new.info.total_samples == 0
assert new.info.bitrate == 0
assert new.info.length == 0.0
def test_bitrate(self):
assert self.flac.info.bitrate == 101430
old_file_size = os.path.getsize(self.flac.filename)
self.flac.save(padding=lambda x: 9999)
new_flac = FLAC(self.flac.filename)
assert os.path.getsize(new_flac.filename) > old_file_size
assert new_flac.info.bitrate == 101430
def test_padding(self):
for pad in [0, 42, 2**24 - 1, 2 ** 24]:
self.flac.save(padding=lambda x: pad)
new = FLAC(self.flac.filename)
expected = min(2**24 - 1, pad)
self.assertEqual(new.metadata_blocks[-1].length, expected)
def test_save_multiple_padding(self):
# we don't touch existing padding blocks on save, but will
# replace them in the file with one at the end
def num_padding(f):
blocks = f.metadata_blocks
return len([b for b in blocks if isinstance(b, Padding)])
num_blocks = num_padding(self.flac)
self.assertEqual(num_blocks, 1)
block = Padding()
block.length = 42
self.flac.metadata_blocks.append(block)
block = Padding()
block.length = 24
self.flac.metadata_blocks.append(block)
self.flac.save()
self.assertEqual(num_padding(self.flac), num_blocks + 2)
new = FLAC(self.flac.filename)
self.assertEqual(num_padding(new), 1)
self.assertTrue(isinstance(new.metadata_blocks[-1], Padding))
def test_increase_size_new_padding(self):
self.assertEqual(self.flac.metadata_blocks[-1].length, 3060)
value = u"foo" * 100
self.flac[u"foo"] = [value]
self.flac.save()
new = FLAC(self.NEW)
self.assertEqual(new.metadata_blocks[-1].length, 2752)
self.assertEqual(new[u"foo"], [value])
def test_delete(self):
self.failUnless(self.flac.tags)
self.flac.delete()
self.assertTrue(self.flac.tags is not None)
self.assertFalse(self.flac.tags)
flac = FLAC(self.NEW)
self.assertTrue(flac.tags is None)
def test_delete_change_reload(self):
self.flac.delete()
self.flac.tags["FOO"] = ["BAR"]
self.flac.save()
assert FLAC(self.flac.filename)["FOO"] == ["BAR"]
# same with delete failing due to IO etc.
with pytest.raises(MutagenError):
self.flac.delete(os.devnull)
self.flac.tags["FOO"] = ["QUUX"]
self.flac.save()
assert FLAC(self.flac.filename)["FOO"] == ["QUUX"]
def test_module_delete(self):
delete(self.NEW)
flac = FLAC(self.NEW)
self.failIf(flac.tags)
def test_info(self):
self.failUnlessAlmostEqual(FLAC(self.NEW).info.length, 3.7, 1)
def test_keys(self):
self.failUnlessEqual(
list(self.flac.keys()), list(self.flac.tags.keys()))
def test_values(self):
#.........这里部分代码省略.........
示例12: FlacFile
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
class FlacFile(audiofile.AudioFile):
def __init__(self, filename):
super(FlacFile, self).__init__(filename)
def loadFile(self):
try:
self.audio = FLAC(self.filename)
self.loadMetaData()
self.fileOpen = True
except BaseException:
self.fileOpen = False
logging.error("FEHLER bei %s" % (self.filename))
exc_type, exc_value, exc_traceback = sys.exc_info()
lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
for line in lines:
logging.error(line)
return
def loadMetaData(self):
"""
Die FLAC-metadata werden eingelesen.
Ursprünglich wurden die Daten einzeln
behandelt. Mitlerweile wird das alles
durch Ersatzvariablen in der Config-
Datei behandelt.
Für ein paar Sachen kann es aber
noch ganz nütlich sein, die Felder
einzeln aufzubereiten (z.B. TrackNr)
"""
for tag in self.audio.keys():
self.tags[tag] = self.audio[tag]
for text in self.audio[tag]:
if tag == 'title':
if self.debug: logging.debug('Title? {0}: {1}'.format(tag, text.encode('UTF-8')))
self.setTitle(text)
elif tag == 'artist':
if self.debug: logging.debug('Artist? {0}: {1}'.format(tag, text.encode('UTF-8')))
self.setArtist(text)
elif tag == 'album':
if self.debug: logging.debug('Album? {0}: {1}'.format(tag, text.encode('UTF-8')))
self.setAlbum(text)
elif tag == 'tracknumber':
if self.debug: logging.debug('Track? {0}: {1}'.format(tag, text.encode('UTF-8')))
self.setTrack(text)
elif tag == 'tracktotal':
if self.debug: logging.debug('Tracks? {0}: {1}'.format(tag, text.encode('UTF-8')))
self.setTrackTotal(text)
elif tag == 'discnumber':
if self.debug: logging.debug('Discnumber? {0}: {1}'.format(tag, text.encode('UTF-8')))
self.setDiscNo(text)
elif tag == 'cddb':
if self.debug: logging.debug('CDDB? {0}: {1}'.format(tag, text.encode('UTF-8')))
self.setCDDB(text)
elif tag == 'date':
if self.debug: logging.debug('Year? {0}: {1}'.format(tag, text.encode('UTF-8')))
self.setYear(text)
elif tag == 'lyrics':
if self.debug: logging.debug('Lyrics? {0}: {1}'.format(tag, text.encode('UTF-8')))
elif 'comment' in tag:
if self.debug: logging.debug('Comment? {0}: {1}'.format(tag, text.encode('UTF-8')))
self.setComments(text)
else:
if self.debug: logging.debug('Unhandled Tag {0}: {1}'.format(tag, text.encode('UTF-8')))
if self.debug: logging.debug("LENGTH? %s" % (self.audio.info.length))
def loadFrontCover(self):
pics = self.audio.pictures
if self.debug: logging.debug('Insgesamt %s Bilder' % (len(pics)))
datei = None
logo = None
if len(pics) > 0:
# Versuchen ein Frontcover laut Deklaration zu finden
# oder, wenn es nur ein Bild gibt, dieses nehmen
for p in pics:
if p.type == 3 or len(pics) == 1:
datei = self.getTempPic(p.data)
break
# Wenn nix gefunden wurde, nehmen wir das erste Bild
if not datei:
for p in pics:
datei = self.getTempPic(p.data)
break
if datei:
self.setCover(pygame.image.load(datei))
else:
self.setCover(pygame.image.load(self.LEERCD))
return
def loadLogo(self):
pics = self.audio.pictures
if self.debug: logging.debug('Insgesamt %s Bilder' % (len(pics)))
logo = None
#.........这里部分代码省略.........
示例13: copyFLAC
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
def copyFLAC(flacFile, mpgFile):
from mutagen.flac import FLAC, Picture
from mutagen.mp3 import MP3
from mutagen.id3 import ID3
bChange = False
# audioMP3 = MP3('smiley.mp3', ID3=EasyID3)
audioMP3 = MP3()
audioMP3.add_tags(ID3=CompatID3)
bNew = True
audioFLAC = FLAC(flacFile)
if audioFLAC.has_key('tracktotal'):
tracktotal = audioFLAC["tracktotal"][0]
else:
tracktotal = 0
if not audioFLAC.has_key('albumartist'):
audioFLAC["albumartist"] = audioFLAC["artist"]
if not audioFLAC.has_key('compilation'):
audioFLAC["compilation"] = 0
print "--FLAC--------------------------------------------"
for tag in audioFLAC.keys():
# print >> sys.stdout, "--> verarbeite Key: ", tag
# if 'APIC' in tag:
# print 'Tag {0}'.format(tag)
# else:
# print >> sys.stdout, "--> verarbeite Key: Tag {0}: {1}".format(tag, textTag.encode('UTF-8'))
if tag == "tracktotal": pass
else:
# id3.add(mutagen.id3.COMM(encoding=3,text=relationshipLink, lang="eng", desc="MusicGrabberSig"))
# Tag COMM:Kommentar:'DEU': von Vinyl
if tag == "tracknumber":
audioFLAC[tag]='{0}/{1}'.format(audioFLAC[tag][0], tracktotal)
# audioFLAC[tag]='{0}/{1}'.format(audioFLAC[tag], tracktotal)
searchTag = tag
if "comment" in tag: searchTag = 'COMMENTS'
if "description" in tag: searchTag = 'COMMENTS'
# if not str.upper(tag) in id3Trans.flacFrames:
if not hasFrame(searchTag):
if "replaygain" in tag: continue
print >> sys.stderr, "Key nicht gefunden: ", tag
continue
id3Frame = getFrame(searchTag)
# audioMP3[id3Frame] = audioFLAC[tag]
# for textTag in audioFLAC[tag]:
# print >> sys.stderr, "tag: %s frame: %s " % (tag, id3Frame.__name__)
if "comment" in tag:
# audioMP3.add(id3Frame(encoding=3, text= audioFLAC[tag], lang="DEU", desc="Kommentar"))
try: audioMP3[id3Frame.__name__] = id3Frame(3, text=audioFLAC[tag], lang="DEU", desc="Kommentar")
except: pass
else:
audioMP3[id3Frame.__name__] = id3Frame(3, text=audioFLAC[tag])
# audioMP3.add(id3Frame(encoding=3, text= audioFLAC[tag]))
bChange = True
# print u'Tag {0}: {1} --> MP3 zugefuegt'.format(id3Frame, audioFLAC[tag])
if bChange == True:
# print dir(audioMP3)
# if bNew : audioMP3.save(mpgFile,v1=2)
# else : audioMP3.save(v1=2)
audioMP3.tags.update_to_v23()
if bNew : audioMP3.tags.save(filename=mpgFile, v2=3)
else : audioMP3.tags.save(v2=3)
print '-'*40
示例14: FlacTrack
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
class FlacTrack(Track):
"""Expose canonical metadata from a single FLAC file"""
def __init__(self, path ):
super(FlacTrack, self).__init__(path)
""" Load metadata from path """
self._flac = FLAC( self.PathName )
@property
def Album(self):
return self._flac["album"][0]
@property
def AlbumArtist(self):
if "album artist" in self._flac.keys():
return self._flac["album artist"][0]
#print "No AlbumArtist"
return self.Artist
@property
def Artist(self):
return self._flac["artist"][0]
@property
def Title(self):
# print type( self._flac["title"][0].text ), self._flac["title"][0].text
return self._flac["title"][0]
@property
def TrackNumber(self):
return self._flac["tracknumber"][0]
@property
def AudioMD5(self):
md5 = unicode( hex(self._flac.info.md5_signature) )
#print md5
return md5
@property
def Wife(self):
return "custom1" in self._flac and self._flac["custom1"][0] == u'Wife'
@property
def IsPartOfCompilation(self):
artist = self.Artist.lower()
albumArtist = self.AlbumArtist.lower()
return ( artist == 'various' or
artist == 'various artists' or
albumArtist == 'various' or
albumArtist == 'various artists' or
not artist == albumArtist )
@property
def AlbumArtwork(self):
# should be a jpeg
#print "pictures", self._flac.pictures
if len( self._flac.pictures ) > 0:
cover = self._flac.pictures[0]
if cover.mime == "image/jpeg":
#print cover.data
return AlbumArtwork( io.BytesIO( cover.data ) )
# else:
# print "no jpeg cover"
# else:
# print "no cover"
#print type (self.Path), self.Path
#print type (self.Album), self.Album
path = None
if isinstance(self.Path, unicode):
path = self.Path.encode('utf-8')
else:
path = self.Path
artPath = os.path.join( path, self.Album.encode('utf-8') ) + ".jpg"
if os.path.isfile(artPath):
return AlbumArtwork( io.BytesIO( open(artPath).read() ) )
return None
示例15: flac
# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import keys [as 别名]
class flac(TagParser):
"""
Class for processing Ogg FLAC file tags
"""
def __init__(self, codec, path):
super(flac, self).__init__(codec, path, tag_map=FLAC_STANDARD_TAGS)
try:
self.entry = FLAC(path)
except IOError as e:
raise TagError('Error opening {}: {}'.format(path, str(e)))
except FLACNoHeaderError as e:
raise TagError('Error opening {}: {}'.format(path, str(e)))
self.albumart_obj = None
self.track_numbering = FLACNumberingTag(self, 'TRACKNUMBER')
self.disk_numbering = FLACNumberingTag(self, 'DISKNUMBER')
def __getitem__(self, item):
if item == 'tracknumber':
return [format_unicode_string_value('{:d}'.format(self.track_numbering.value))]
if item == 'totaltracks':
return [format_unicode_string_value('{:d}'.format(self.track_numbering.total))]
if item == 'disknumber':
return [format_unicode_string_value('{:d}'.format(self.disk_numbering.value))]
if item == 'totaldisks':
return [format_unicode_string_value('{:d}'.format(self.disk_numbering.total))]
return super(flac, self).__getitem__(item)
def __delitem__(self, item):
try:
item = item.split('=', 1)[0]
except ValueError:
pass
fields = self.__tag2fields__(item)
for tag in fields:
if tag not in self.entry.keys():
continue
del self.entry[tag]
self.modified = True
def __field2tag__(self, field):
return super(flac, self).__field2tag__(field.upper())
def keys(self):
"""
Return tag names sorted with self.sort_keys()
"""
keys = super(flac, self).keys()
if 'TOTALTRACKS' in keys:
keys.remove('TOTALTRACKS')
if 'TOTALDISKS' in keys:
keys.remove('TOTALDISKS')
if 'TRACKNUMBER' in [x.upper() for x in keys]:
if self.track_numbering.total is not None:
keys.append('totaltracks')
if 'DISKNUMBER' in [x.upper() for x in keys]:
if self.disk_numbering.total is not None:
keys.append('totaldisks')
if FLAC_ALBUMART_TAG in [x.upper() for x in keys]:
keys.remove(FLAC_ALBUMART_TAG)
for replaygain_tag_fields in FLAC_REPLAYGAIN_TAGS.values():
for tag in replaygain_tag_fields:
if tag in keys:
keys.remove(tag)
return [x.lower() for x in self.sort_keys(keys)]
def has_key(self, tag):
return tag.lower() in self.keys()
def set_tag(self, item, value):
"""
All flac tags are str strings, and there can be multiple
tags with same name.
We do special precessing for track and disk numbering.
"""
if item == 'tracknumber':
self.track_numbering.value = value
return
if item == 'totaltracks':
self.track_numbering.total = value
return
if item == 'disknumber':
self.disk_numbering.value = value
return
if item == 'totaldisks':
self.disk_numbering.total = value
return
if not isinstance(value, list):
value = [value]
tags = self.__tag2fields__(item)
#.........这里部分代码省略.........