1

I've crawled a tracklist of 36.000 songs, which have been played on the Danish national radio station P3. I want to do some statistics on how frequently each of the genres have been played within this period, so I figured the discogs API might help labeling each track with genre. However, the documentation for the API doesent seem to include an example for querying the genre of a particular song.

I have a CSV-file with with 3 columns: Artist, Title & Test(Test where i want the API to label each song with the genre).

Here's a sample of the script i've built so far:

import json
import pandas as pd
import requests
import discogs_client
d = discogs_client.Client('ExampleApplication/0.1')
d.set_consumer_key('key-here', 'secret-here')

input = pd.read_csv('Desktop/TEST.csv', encoding='utf-8',error_bad_lines=False)

df = input[['Artist', 'Title', 'Test']]
df.columns = ['Artist', 'Title','Test']

for i in range(0, len(list(df.Artist))):
x = df.Artist[i]
g = d.artist(x)
df.Test[i] = str(g)

df.to_csv('Desktop/TEST2.csv', encoding='utf-8', index=False)

This script has been working with a dummy file with 3 records in it so far, for mapping the artist of a given ID#. But as soon as the file gets larger(ex. 2000), it returns a HTTPerror when it cannot find the artist.

I have some questions regarding this approach:

1) Would you recommend using the search query function in the API for retrieving a variable as 'Genre'. Or do you think it is possible to retrieve Genre with a 'd.' function from the API?

2) Will I need to aquire an API-key? I have succesfully mapped the 3 records without an API-key so far. Looks like the key is free though.

Here's the guide I have been following: https://github.com/discogs/discogs_client

And here's the documentation for the API: https://www.discogs.com/developers/#page:home,header:home-quickstart

4

3 回答 3

1

也许您需要重新阅读 discogs_client 示例,我自己不是专家,而是尝试使用此 API 的新手。

AFAIK, g = d.artist(x) 失败,因为 x 必须是整数而不是字符串。

所以你必须先进行搜索,然后获取艺术家 id,然后 d.artist(artist_id)

抱歉没有提供示例,我现在是 python 新手;)

你也检查过acousid

于 2015-05-18T18:07:16.657 回答
0

这可能是一个速率限制。阅读响应的状态码,您应该会发现 429 Too Many Requests

不幸的是,如果是这种情况,唯一的解决方案是在代码中添加睡眠以每秒发出一个请求。

查看 api 文档: http ://www.discogs.com/developers/#page:home,header:home-rate-limiting

于 2015-05-01T22:24:50.877 回答
0

我找到了这个指南:

https://github.com/neutralino1/discogs_client.

使用您的密钥访问 api 并尝试以下操作:

d = discogs_client.Client('something.py', user_token=auth_token)
release = d.release(774004)
genre = release.genres

如果您找到更好的解决方案,请分享。

于 2021-06-02T10:04:39.280 回答