本文整理汇总了Python中song.Song.tags["lyrics"]方法的典型用法代码示例。如果您正苦于以下问题:Python Song.tags["lyrics"]方法的具体用法?Python Song.tags["lyrics"]怎么用?Python Song.tags["lyrics"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类song.Song
的用法示例。
在下文中一共展示了Song.tags["lyrics"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tagSong
# 需要导入模块: from song import Song [as 别名]
# 或者: from song.Song import tags["lyrics"] [as 别名]
def tagSong(root, location):
try:
song = Song(location)
except mutagen.id3.ID3NoHeaderError:
return
info = {}
if song.tags["title"][0] and song.tags["artist"][0]:
trackInfo = lastfm.getTrackInfo(song.tags["title"][0], song.tags["artist"][0])
if trackInfo:
if "album" in trackInfo:
song.tags["album"] = trackInfo["album"]
song.tags.save()
info.update(trackInfo)
if song.tags["album"][0] and song.tags["artist"][0]:
albumInfo = lastfm.getAlbumInfo(song.tags["album"][0], song.tags["artist"][0])
if albumInfo:
info.update(albumInfo)
try:
info["tracknumber"] = "%s/%s" % (info["trackPosition"], info["totalTracks"])
except KeyError:
pass
for tag in ["trackPosition", "totalTracks"]:
if tag in info:
del info[tag]
print [(k, v) for (k, v) in info.items() if k != "picture"]
for tag in info:
if info[tag]:
song.tags[tag] = info[tag]
lyrics = pandora.getLyrics(song.tags["artist"][0], song.tags["title"][0])
if lyrics:
song.tags["lyrics"] = lyrics
artist = util.cleanPath(song.tags["artist"][0])
album = util.cleanPath(song.tags["album"][0])
title = util.cleanPath(song.tags["title"][0])
song.save()
# fixes for Unicode encoding in system filenames into UTF-8
# INFO: http://docs.python.org/library/sys.html
location = location.decode(sys.getfilesystemencoding())
root = root.decode(sys.getfilesystemencoding())
extension = os.path.splitext(location)[1]
newLocation = os.path.join(root, artist, album, title + extension)
# print(location)
# print(location + 'x')
# print(newLocation)
if (
os.path.exists(newLocation) is False
or os.path.abspath(location) == os.path.abspath(newLocation) is False
or location != newLocation
):
# workaround for inability to rename to already existing file (i.e. case-sensitiviy)
os.renames(location, location + "x")
os.renames(location + "x", newLocation)
def tagDirectory(root):
i = 1
for dir, subdirs, files in os.walk(root, topdown=False):
for name in files:
print (i)
tagSong(root, os.path.join(dir, name))
i += 1
# appears to be unneeded since os.renames does all this auto.
"""