本文整理匯總了Python中mutagen.id3.error方法的典型用法代碼示例。如果您正苦於以下問題:Python id3.error方法的具體用法?Python id3.error怎麽用?Python id3.error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mutagen.id3
的用法示例。
在下文中一共展示了id3.error方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: add_metadata_to_song
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import error [as 別名]
def add_metadata_to_song(file_path, cover_path, song):
# If no ID3 tags in mp3 file
try:
audio = MP3(file_path, ID3=ID3)
except HeaderNotFoundError:
print('Can\'t sync to MPEG frame, not an validate MP3 file!')
return
if audio.tags is None:
print('No ID3 tag, trying to add one!')
try:
audio.add_tags()
audio.save()
except error as e:
print('Error occur when add tags:', str(e))
return
# Modify ID3 tags
id3 = ID3(file_path)
# Remove old 'APIC' frame
# Because two 'APIC' may exist together with the different description
# For more information visit: http://mutagen.readthedocs.io/en/latest/user/id3.html
if id3.getall('APIC'):
id3.delall('APIC')
# add album cover
id3.add(
APIC(
encoding=0, # 3 is for UTF8, but here we use 0 (LATIN1) for 163, orz~~~
mime='image/jpeg', # image/jpeg or image/png
type=3, # 3 is for the cover(front) image
data=open(cover_path, 'rb').read()
)
)
# add artist name
id3.add(
TPE1(
encoding=3,
text=song['artists'][0]['name']
)
)
# add song name
id3.add(
TIT2(
encoding=3,
text=song['name']
)
)
# add album name
id3.add(
TALB(
encoding=3,
text=song['album']['name']
)
)
id3.save(v2_version=3)
示例2: add_tags
# 需要導入模塊: from mutagen import id3 [as 別名]
# 或者: from mutagen.id3 import error [as 別名]
def add_tags(self):
if self.tags is None:
self.tags = EasyID3()
else:
raise error("an ID3 tag already exists")