Python - 从Last.fm API检索所有类型标记

时间:2016-11-15 22:06:52

标签: python api last.fm

我有一个使用get_top_tags()方法获取last.fm API中的热门标记的函数:

def lastfm_tags(tag):
        tag_weight = {}

        result = last.get_top_tags()

        for tag in result:
            tag_weight[str(tag.item.get_name())] = str(tag.weight) 

        tag_weight = {k: int(v) for k, v in tag_weight.items()}


        return tag_weight

    print lastfm_tags('pop') 

打印:

{'industrial': 533792, 'punk': 849254, 'indie': 1972289, 'metal': 1214142, 'heavy metal': 652768, 'japanese': 428483, 'pop': 1874644, 'new wave': 399642, 'black metal': 772854, 'rap': 513369, 'ambient': 1030860, 'alternative': 2059622, 'hard rock': 821047, 'electronic': 2289385, 'blues': 531227, 'folk': 882684, 'classic rock': 1123889, 'alternative rock': 1123671, '90s': 447817, 'Progressive metal': 407423, 'indie rock': 850647, 'electronica': 614612, 'female vocalists': 1558073, 'Soundtrack': 529623, 'dance': 769325, 'psychedelic': 458873, '80s': 752035, 'piano': 410036, 'chillout': 636262, 'post-rock': 426621, 'punk rock': 518635, 'jazz': 1117396, 'seen live': 2098252, 'instrumental': 818216, 'singer-songwriter': 810484, 'acoustic': 461045, 'hardcore': 656385, 'funk': 399980, 'Classical': 539399, 'Hip-Hop': 814911, 'death metal': 671617, 'soul': 641317, 'british': 667770, 'thrash metal': 465438, 'hip hop': 395139, 'rock': 3879776, 'metalcore': 444620, 'german': 409117, 'Progressive rock': 693750, 'experimental': 1010752}

然后我还可以检索相对于艺术家的tags

def lastfm_artist_to_tags(artist):

    tag_weight = {}

    result = last.get_artist(artist).get_top_tags()

    for tag in result:
        tag_weight[str(tag.item.get_name())] = str(tag.weight) 

    tag_weight = {k: int(v) for k, v in tag_weight.items()}

    return sorted(tag_weight.items(), key=lambda x: x[1], reverse=True)

打印更具体的标记:

[('shoegaze', 100), ('experimental', 72), ('psychedelic', 70), ('seen live', 61), ('indie', 56), ('indie rock', 53), ('ambient', 14), ('post-rock', 12), ('noise rock', 11), ('dream pop', 9), ('Psychedelic Rock', 8), ('Neo-Psychedelia', 7), ('american', 7), ('rock', 7), ('post-punk', 6), ('Experimental Rock', 4), ('alternative', 4), ('art rock', 4), ('noise', 4), ('atlanta', 4), ('00s', 3), ('alternative rock', 3), ('Garage Rock', 3), ('ambient punk', 3), ('georgia', 3), ('noise pop', 3), ('USA', 2), ('Lo-Fi', 2), ('Avant-Garde', 2), ('Dreamy', 2), ('Psychedelia', 2), ('shoegazing', 2), ('psychedelic pop', 2), ('space rock', 2), ('kranky', 2), ('indie pop', 2), ('male vocalists', 1), ('10s', 1), ('deerhunter', 1), ('avantgarde', 1), ('4ad', 1)]

对于我来说,是否有方法或方法未知,以获取所有可能的标签?

1 个答案:

答案 0 :(得分:0)

根据LastFM API,没有。您只能找到与特定实体(艺术家,专辑,曲目等)相关联的标签

这实际上是大多数公司用于其提供的API的常见模式。想象一下,如果你可以免费获得所有相关专辑,艺术家和曲目的所有标签,并将它们存储在本地副本中。你会再回到他们的API /网站寻求帮助吗?