当前位置: 首页>>代码示例>>Python>>正文


Python Song.tags["lyrics"]方法代码示例

本文整理汇总了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.
    """
开发者ID:jiaweihli,项目名称:neptune,代码行数:76,代码来源:tagging.py


注:本文中的song.Song.tags["lyrics"]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。