本文整理汇总了Python中mutagen.id3.add函数的典型用法代码示例。如果您正苦于以下问题:Python add函数的具体用法?Python add怎么用?Python add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_tyer_tdat
def test_tyer_tdat(self):
id3 = ID3()
id3.version = (2, 3)
id3.add(TYER(encoding=0, text="2006"))
id3.add(TDAT(encoding=0, text="0603"))
id3.update_to_v24()
self.failUnlessEqual(id3["TDRC"], "2006-03-06")
示例2: setter
def setter(id3, key, value):
try:
frame = id3[frameid]
except KeyError:
id3.add(mutagen.id3.Frames[frameid](encoding=3, text=value))
else:
frame.text = value
示例3: test_chap_subframes
def test_chap_subframes(self):
id3 = ID3()
id3.version = (2, 3)
id3.add(CHAP(element_id="foo", start_time=0, end_time=0,
start_offset=0, end_offset=0,
sub_frames=[TYER(encoding=0, text="2006")]))
id3.update_to_v24()
chap = id3.getall("CHAP:foo")[0]
self.assertEqual(chap.sub_frames.getall("TDRC")[0], u"2006")
示例4: gain_set
def gain_set(id3, key, value):
if len(value) != 1:
raise ValueError("there must be exactly one gain value, not %r.", value)
gain = float(value[0].split()[0])
try:
frame = id3["RVA2:" + key[11:-5]]
except KeyError:
frame = mutagen.id3.RVA2(desc=key[11:-5], gain=0, peak=0, channel=1)
id3.add(frame)
frame.gain = gain
示例5: performer_set
def performer_set(id3, key, value):
wanted_role = key.split(":", 1)[1]
try: mcl = id3["TMCL"]
except KeyError:
mcl = mutagen.id3.TMCL(encoding=3, people=[])
id3.add(mcl)
people = [p for p in mcl.people if p[0] != wanted_role]
for v in value:
people.append((wanted_role, v))
mcl.people = people
示例6: test_ctoc_subframes
def test_ctoc_subframes(self):
id3 = ID3()
id3.version = (2, 3)
id3.add(CTOC(sub_frames=[TYER(encoding=0, text="2006")]))
id3.update_to_v24()
ctoc = id3.getall("CTOC")[0]
self.assertEqual(ctoc.sub_frames.getall("TDRC")[0], u"2006")
self.assertFalse(ctoc.sub_frames.getall("TYER"))
id3.update_to_v23()
self.assertEqual(ctoc.sub_frames.getall("TYER")[0], u"2006")
示例7: musicbrainz_trackid_set
def musicbrainz_trackid_set(id3, key, value):
if len(value) != 1:
raise ValueError("only one track ID may be set per song")
value = value[0].encode('ascii')
try:
frame = id3["UFID:http://musicbrainz.org"]
except KeyError:
frame = mutagen.id3.UFID(owner="http://musicbrainz.org", data=value)
id3.add(frame)
else:
frame.data = value
示例8: peak_set
def peak_set(id3, key, value):
if len(value) != 1:
raise ValueError("there must be exactly one peak value, not %r.", value)
peak = float(value[0])
if peak >= 2 or peak < 0:
raise ValueError("peak must be => 0 and < 2.")
try:
frame = id3["RVA2:" + key[11:-5]]
except KeyError:
frame = mutagen.id3.RVA2(desc=key[11:-5], gain=0, peak=0, channel=1)
id3.add(frame)
frame.peak = peak
示例9: write_tags
def write_tags(self):
"""Write all ID3v2.4 tags by mapping dub2id3_dict dictionnary with the
respect of mutagen classes and methods"""
from mutagen import id3
id3 = id3.ID3(self.dest)
for tag in self.metadata.keys():
if tag in self.dub2id3_dict.keys():
frame_text = self.dub2id3_dict[tag]
value = self.metadata[tag]
frame = mutagen.id3.Frames[frame_text](3,value)
id3.add(frame)
id3.save()
示例10: peak_set_with_txxx
def peak_set_with_txxx(id3, key, value):
frameid = 'TXXX:' + key
try:
frame = id3[frameid]
except KeyError:
enc = get_best_txxx_encoding(value)
id3.add(mutagen.id3.TXXX(encoding=enc, text=value, desc=key))
else:
frame.text = value
return peak_set(id3, key, value)
示例11: write_metadata
def write_metadata(self):
"""Write all ID3v2.4 tags to file from self.metadata"""
from mutagen import id3
id3 = id3.ID3(self.filename)
for tag in self.metadata.keys():
value = self.metadata[tag]
frame = mutagen.id3.Frames[tag](3,value)
try:
id3.add(frame)
except:
raise IOError('EncoderError: cannot tag "'+tag+'"')
try:
id3.save()
except:
raise IOError('EncoderError: cannot write tags')
示例12: setter
def setter(id3, key, value):
try:
frame = id3[frameid]
except KeyError:
enc = 0
# Store 8859-1 if we can, per MusicBrainz spec.
try:
for v in value:
v.encode('latin_1')
except UnicodeError:
enc = 3
id3.add(mutagen.id3.TXXX(encoding=enc, text=value, desc=desc))
else:
frame.text = value
示例13: test_unknown_chap
def test_unknown_chap(self):
# add ctoc
id3 = ID3(self.filename)
id3.add(CTOC(element_id="foo", flags=3, child_element_ids=["ch0"],
sub_frames=[TIT2(encoding=3, text=["bla"])]))
id3.save()
# pretend we don't know ctoc and save
id3 = ID3(self.filename, known_frames={"CTOC": CTOC})
ctoc = id3.getall("CTOC")[0]
self.assertFalse(ctoc.sub_frames)
self.assertTrue(ctoc.sub_frames.unknown_frames)
id3.save()
# make sure we wrote all sub frames back
id3 = ID3(self.filename)
self.assertEqual(
id3.getall("CTOC")[0].sub_frames.getall("TIT2")[0].text, ["bla"])
示例14: test_merge
def test_merge(self):
id3 = ID3(self.filename)
id3.delete()
id3.add(mutagen.id3.TALB(text=[u"foo"]))
id3.save(v2_version=3)
target = ID3()
target.add(mutagen.id3.TPE1(text=[u"bar", u"quux"]))
target.save(self.blank_file, v2_version=4)
res, out, err = self.call2(
self.filename, self.blank_file, fsn(u"--merge"))
assert not any([res, out, err])
result = ID3(self.blank_file)
assert result.version == (2, 4, 0)
assert result.getall("TALB")[0].text == [u"foo"]
assert result.getall("TPE1")[0].text == [u"bar", u"quux"]
示例15: write_tags
def write_tags(self):
"""Write all ID3v2.4 tags by mapping dub2id3_dict dictionnary with the
respect of mutagen classes and methods"""
from mutagen import id3
id3 = id3.ID3(self.dest)
for tag in self.metadata.keys():
if tag in self.dub2id3_dict.keys():
frame_text = self.dub2id3_dict[tag]
value = self.metadata[tag]
frame = mutagen.id3.Frames[frame_text](3,value)
try:
id3.add(frame)
except:
raise IOError('EncoderError: cannot tag "'+tag+'"')
try:
id3.save()
except:
raise IOError('EncoderError: cannot write tags')