本文整理汇总了Python中mutagen.File.tags方法的典型用法代码示例。如果您正苦于以下问题:Python File.tags方法的具体用法?Python File.tags怎么用?Python File.tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mutagen.File
的用法示例。
在下文中一共展示了File.tags方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tag
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import tags [as 别名]
def tag(self):
data = self.get_parent_instance().metadata()
with tempfile.NamedTemporaryFile(suffix='-musicdb.mp3') as f:
# Download
with default_storage.open(self.file.location) as g:
contents = g.read()
f.write(contents)
f.flush()
f.seek(0)
audio = MutagenFile(f.name)
audio.delete()
if isinstance(audio, mp3.MP3):
audio.tags = easyid3.EasyID3()
audio.update(data)
audio.save()
self.length = int(audio.info.length)
# Copy it back
default_storage.delete(self.file.location)
dst = default_storage.save(self.file.location, DjangoFile(f))
assert dst == self.file.location
示例2: tag
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import tags [as 别名]
def tag(filename, data):
audio = File(filename)
audio.delete()
if isinstance(audio, mp3.MP3):
audio.tags = easyid3.EasyID3()
audio.update(data)
audio.save()
示例3: tag
# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import tags [as 别名]
def tag(self):
try:
data = self.get_parent_instance().metadata()
filename = os.path.join(settings.MEDIA_LOCATION, self.file.location)
audio = MutagenFile(filename)
audio.delete()
if isinstance(audio, mp3.MP3):
audio.tags = easyid3.EasyID3()
audio.update(data)
audio.save()
except:
self.tags_dirty = None
self.save()
raise
finally:
self.tags_dirty = False
self.save()