本文整理汇总了Python中mutagen.File.add方法的典型用法代码示例。如果您正苦于以下问题:Python File.add方法的具体用法?Python File.add怎么用?Python File.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.File
的用法示例。
在下文中一共展示了File.add方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_track_metadata
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import add [as 别名]
def set_track_metadata(self, track = None, filename = None, url = None):
"""Find and set all metadata for a track"""
if url == None or track == None:
return None
if filename == None:
filename = get_track_filename(url)
# id3 is only for mp3
if not filename.endswith(".mp3"):
if filename.endswith(".wav"):
filename = self.convert_wav_to_mp3(filename)
else:
return None
# Set title
try:
meta = ID3(filename)
except ID3NoHeaderError:
try:
meta = File(filename, easy=True)
meta.add_tags()
meta.save()
meta = ID3(filename)
except:
return
except IOError:
return
try:
meta.add(TIT2(encoding=3, text=track.title))
meta.add(TCON(encoding=3, text=track.genre))
meta.add(TCOM(encoding=3, text=track.user["username"]))
meta.save()
artwork_filename = wget.download(track.artwork_url)
audio = MP3(filename, ID3=ID3)
# add ID3 tag if it doesn't exist
try:
audio.add_tags()
except error:
pass
audio.tags.add(
APIC(
encoding=3, # 3 is for utf-8
mime='image/jpeg', # image/jpeg or image/png
type=3, # 3 is for the cover image
desc=u'Cover',
data=open(artwork_filename).read()
)
)
audio.save()
except:
return