本文整理匯總了Python中mutagen.id3.ID3屬性的典型用法代碼示例。如果您正苦於以下問題:Python id3.ID3屬性的具體用法?Python id3.ID3怎麽用?Python id3.ID3使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類mutagen.id3
的用法示例。
在下文中一共展示了id3.ID3屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: RegisterTextKey
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def RegisterTextKey(cls, key, frameid):
"""Register a text key.
If the key you need to register is a simple one-to-one mapping
of ID3 frame name to EasyID3 key, then you can use this
function::
EasyID3.RegisterTextKey("title", "TIT2")
"""
def getter(id3, key):
return list(id3[frameid])
def setter(id3, key, value):
try:
frame = id3[frameid]
except KeyError:
id3.add(mutagen.id3.Frames[frameid](encoding=3, text=value))
else:
frame.encoding = 3
frame.text = value
def deleter(id3, key):
del(id3[frameid])
cls.RegisterKey(key, getter, setter, deleter)
示例2: save
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def save(self, filething, v1=1, v2_version=4, v23_sep='/', padding=None):
"""save(filething=None, v1=1, v2_version=4, v23_sep='/', padding=None)
Save changes to a file.
See :meth:`mutagen.id3.ID3.save` for more info.
"""
if v2_version == 3:
# EasyID3 only works with v2.4 frames, so update_to_v23() would
# break things. We have to save a shallow copy of all tags
# and restore it after saving. Due to CHAP/CTOC copying has
# to be done recursively implemented in ID3Tags.
backup = self.__id3._copy()
try:
self.__id3.update_to_v23()
self.__id3.save(
filething, v1=v1, v2_version=v2_version, v23_sep=v23_sep,
padding=padding)
finally:
self.__id3._restore(backup)
else:
self.__id3.save(filething, v1=v1, v2_version=v2_version,
v23_sep=v23_sep, padding=padding)
示例3: modified_id3
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def modified_id3(self, file_name, info):
id3 = ID3()
id3.add(TRCK(encoding=3, text=str(info['track'])))
id3.add(TDRC(encoding=3, text=str(info['year'])))
id3.add(TIT2(encoding=3, text=info['song_name']))
id3.add(TALB(encoding=3, text=info['album_name']))
id3.add(TPE1(encoding=3, text=info['artist_name']))
id3.add(TPOS(encoding=3, text=str(info['cd_serial'])))
lyric_data = self.get_lyric(info)
id3.add(USLT(encoding=3, text=lyric_data)) if lyric_data else None
#id3.add(TCOM(encoding=3, text=info['composer']))
#id3.add(WXXX(encoding=3, desc=u'xiami_song_url', text=info['song_url']))
#id3.add(TCON(encoding=3, text=u'genre'))
#id3.add(TSST(encoding=3, text=info['sub_title']))
#id3.add(TSRC(encoding=3, text=info['disc_code']))
id3.add(COMM(encoding=3, desc=u'Comment', \
text=info['comment']))
id3.add(APIC(encoding=3, mime=u'image/jpeg', type=3, \
desc=u'Front Cover', data=self.get_cover(info)))
id3.save(file_name)
示例4: modified_id3
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def modified_id3(self, file_name, info):
id3 = ID3()
id3.add(TRCK(encoding=3, text=info['track']))
id3.add(TDRC(encoding=3, text=info['year']))
id3.add(TIT2(encoding=3, text=info['song_name']))
id3.add(TALB(encoding=3, text=info['album_name']))
id3.add(TPE1(encoding=3, text=info['artist_name']))
id3.add(TPOS(encoding=3, text=info['cd_serial']))
#id3.add(USLT(encoding=3, text=self.get_lyric(info['lyric_url'])))
#id3.add(TCOM(encoding=3, text=info['composer']))
#id3.add(TCON(encoding=3, text=u'genres'))
#id3.add(TSST(encoding=3, text=info['sub_title']))
#id3.add(TSRC(encoding=3, text=info['disc_code']))
id3.add(COMM(encoding=3, desc=u'Comment', \
text=info['song_url']))
#id3.add(APIC(encoding=3, mime=u'image/jpg', type=3, \
#desc=u'Front Cover', data=self.get_cover(info)))
id3.save(file_name)
示例5: setID3
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def setID3(self, lrc, info, path):
tags = ID3(path)
# remove old unsychronized lyrics
len(tags.getall("USLT")) != 0 and tags.delall("USLT")
for t in ['album', 'title', 'artist']:
t in info and tags.add(
tagMap[t](encoding=3, lang='', desc='', text=info[t][0]))
'cover' in info and tags.add(APIC(
encoding=3,
mime='image/png',
type=3,
desc='cover',
data=requests.get(info['cover'][0], stream=True,
headers=headers).raw.read()
))
tags.add(USLT(encoding=3, lang='eng', desc='aaa', text=lrc))
tags.save()
示例6: _generate_image_from_mp3
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def _generate_image_from_mp3(self, mp3Path):
# if we don't have the python module to
# extract image from mp3, we just return
# default file's icon
try:
from mutagen.id3 import ID3
except ImportError:
return MP3_ICON
try:
audio = ID3(mp3Path)
art = audio.getall("APIC")
return self._generate_image_from_art(
art,
mp3Path
)
except(IndexError, TypeError):
return MP3_ICON
示例7: add_details
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def add_details(file_name, title, artist, album, lyrics=""):
'''
Adds the details to song
'''
tags = EasyMP3(file_name)
tags["title"] = title
tags["artist"] = artist
tags["album"] = album
tags.save()
tags = ID3(file_name)
uslt_output = USLT(encoding=3, lang=u'eng', desc=u'desc', text=lyrics)
tags["USLT::'eng'"] = uslt_output
tags.save(file_name)
log.log("> Adding properties")
log.log_indented("[*] Title: %s" % title)
log.log_indented("[*] Artist: %s" % artist)
log.log_indented("[*] Album: %s " % album)
示例8: _pre_load_header
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def _pre_load_header(self, fileobj):
try:
fileobj.seek(IFFFile(fileobj)[u'ID3'].data_offset)
except (InvalidChunk, KeyError):
raise ID3NoHeaderError("No ID3 chunk")
示例9: save
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def save(self, filething, v2_version=4, v23_sep='/', padding=None):
"""Save ID3v2 data to the AIFF file"""
fileobj = filething.fileobj
iff_file = IFFFile(fileobj)
if u'ID3' not in iff_file:
iff_file.insert_chunk(u'ID3')
chunk = iff_file[u'ID3']
try:
data = self._prepare_data(
fileobj, chunk.data_offset, chunk.data_size, v2_version,
v23_sep, padding)
except ID3Error as e:
reraise(error, e, sys.exc_info()[2])
new_size = len(data)
new_size += new_size % 2 # pad byte
assert new_size % 2 == 0
chunk.resize(new_size)
data += (new_size - len(data)) * b'\x00'
assert new_size == len(data)
chunk.write(data)
示例10: delete
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def delete(self, filething):
"""Completely removes the ID3 chunk from the AIFF file"""
delete(filething)
self.clear()
示例11: add_tags
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def add_tags(self):
"""Add an empty ID3 tag to the file."""
if self.tags is None:
self.tags = _IFFID3()
else:
raise error("an ID3 tag already exists")
示例12: RegisterTXXXKey
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def RegisterTXXXKey(cls, key, desc):
"""Register a user-defined text frame key.
Some ID3 tags are stored in TXXX frames, which allow a
freeform 'description' which acts as a subkey,
e.g. TXXX:BARCODE.::
EasyID3.RegisterTXXXKey('barcode', 'BARCODE').
"""
frameid = "TXXX:" + desc
def getter(id3, key):
return list(id3[frameid])
def setter(id3, key, value):
enc = 0
# Store 8859-1 if we can, per MusicBrainz spec.
for v in value:
if v and max(v) > u'\x7f':
enc = 3
break
id3.add(mutagen.id3.TXXX(encoding=enc, text=value, desc=desc))
def deleter(id3, key):
del(id3[frameid])
cls.RegisterKey(key, getter, setter, deleter)
示例13: __init__
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def __init__(self, filename=None):
self.__id3 = ID3()
if filename is not None:
self.load(filename)
示例14: _pre_load_header
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def _pre_load_header(self, fileobj):
fileobj.seek(0)
id3_location = DSDChunk(fileobj).offset_metdata_chunk
if id3_location == 0:
raise ID3NoHeaderError("File has no existing ID3 tag")
fileobj.seek(id3_location)
示例15: add_tags
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import ID3 [as 別名]
def add_tags(self):
"""Add a DSF tag block to the file."""
if self.tags is None:
self.tags = _DSFID3()
else:
raise error("an ID3 tag already exists")