mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-06 03:23:41 -05:00
LastFM: optionally show extended info (user play count + tags)
This commit is contained in:
parent
4cd8bc9354
commit
f88018a76f
@ -49,5 +49,10 @@ conf.registerChannelValue(LastFM, "fetchYouTubeLink",
|
||||
fetch a YouTube link for the track given in 'np'. This is an
|
||||
experimental feature, and requires the DDG plugin in this repository
|
||||
to be loaded."""))
|
||||
conf.registerChannelValue(LastFM, "showExtendedInfo",
|
||||
registry.Boolean(False, """Determines whether the bot will show extended info
|
||||
for tracks in 'np' (currently the track tags and user play count). Note:
|
||||
this requires a second API call to be made for each 'np' call, which may
|
||||
be expensive in high traffic situations."""))
|
||||
|
||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||
|
@ -185,8 +185,21 @@ class LastFM(callbacks.Plugin):
|
||||
# entire np request to fail.
|
||||
log.exception("LastFM: failed to get YouTube link for track %s - %s", artist, track)
|
||||
|
||||
s = '%s listened to %s by %s %s %s. %s' % (ircutils.bold(user), ircutils.bold(track),
|
||||
ircutils.bold(artist), album, time, public_url)
|
||||
ext_info = ''
|
||||
if self.registryValue("showExtendedInfo", msg.args[0]):
|
||||
# Get extended info via a separate API call.
|
||||
ext_info_url = "%sapi_key=%s&method=track.getinfo&user=%s&format=json&mbid=%s" % (self.APIURL, apiKey, user, trackdata['mbid'])
|
||||
ext_info_f = utils.web.getUrl(ext_info_url).decode("utf-8")
|
||||
self.log.debug("LastFM.nowPlaying: using url %s for extended info", ext_info_url)
|
||||
ext_data = json.loads(ext_info_f)['track']
|
||||
|
||||
# We currently show play count and tags - more could be added in the future...
|
||||
userplaycount = ext_data['userplaycount']
|
||||
tags = [tag['name'] for tag in ext_data['toptags']['tag']]
|
||||
ext_info = ' (Playcount: %s / Tags: %s)' % (userplaycount, ', '.join(tags))
|
||||
|
||||
s = '%s listened to %s by %s %s %s%s. %s' % (ircutils.bold(user), ircutils.bold(track),
|
||||
ircutils.bold(artist), album, time, ext_info, public_url)
|
||||
irc.reply(utils.str.normalizeWhitespace(s))
|
||||
|
||||
@wrap(["something"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user