mirror of
https://github.com/jlu5/SupyPlugins.git
synced 2025-05-03 08:51:13 -05:00
LastFM: reduce the plugin to "np" and "profile" (#36)
LastFM's API breakages are making this hard to maintained, and the low demand for these commands make it not worth maintaining.
This commit is contained in:
parent
3564f0bd43
commit
02a2efffb2
@ -10,13 +10,15 @@ A Supybot plugin for LastFM.
|
|||||||
- Native Python 3 support.
|
- Native Python 3 support.
|
||||||
- Code cleanup and various bugfixes.
|
- Code cleanup and various bugfixes.
|
||||||
- Migration to a new LastFM API (v2).
|
- Migration to a new LastFM API (v2).
|
||||||
|
- Simpler DB implementation using pickle and hostmasks instead of nicks (requires DB reset).
|
||||||
|
- Only `np` and `profile` commands - the others have since been broken by LastFM API changes and removed.
|
||||||
|
|
||||||
The full diff can be found [here](https://github.com/GLolol/supybot-lastfm/compare/krf:master...devel).
|
The full diff can be found [here](https://github.com/GLolol/supybot-lastfm/compare/krf:master...devel).
|
||||||
|
|
||||||
### Support
|
### Support
|
||||||
You may find me on IRC at `irc.overdrive.pw #dev` ([webchat](http://webchat.overdrive.pw/?channels=dev)).
|
You may find me on IRC at `irc.overdrive.pw #dev` ([webchat](http://webchat.overdrive.pw/?channels=dev)).
|
||||||
|
|
||||||
Feel free to suggest enhancements on the [issue tracker](https://github.com/GLolol/supybot-lastfm/issues). Pull requests are welcome.
|
Feel free to suggest enhancements on the [issue tracker](https://github.com/GLolol/supybot-lastfm/issues). Pull requests are welcome.
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
@ -31,15 +33,3 @@ Showing profile information:
|
|||||||
[09:53:36] $profile
|
[09:53:36] $profile
|
||||||
[09:53:37] KRF (realname: Kevin Funk) registered on May 28, 2006; 23 years old / m; Country: Germany; Tracks played: 32870
|
[09:53:37] KRF (realname: Kevin Funk) registered on May 28, 2006; 23 years old / m; Country: Germany; Tracks played: 32870
|
||||||
```
|
```
|
||||||
|
|
||||||
Showing recent tracks:
|
|
||||||
```
|
|
||||||
[10:29:16] $lastfm recenttracks
|
|
||||||
[10:29:17] KRF’s recenttracks: Zebrahead – The Set-Up, Good Charlotte – Girls & Boys, The All-American Rejects – Another Heart Calls, Angels & Airwaves – Do It For Me Now, Bowling For Soup – The Bitch Song, Yellowcard – Down On My Head, Sum 41 – Confusion And Frustration In Modern Times, Sum 41 – With Me, Goldfinger – Bro, The Offspring – Americana (with a total number of 11 entries)
|
|
||||||
```
|
|
||||||
|
|
||||||
Showing help:
|
|
||||||
```
|
|
||||||
[10:28:29] $help lastfm
|
|
||||||
[10:28:29] (lastfm method [id]) — Lists LastFM info where method is in [friends, neighbours, profile, recenttracks, tags, topalbums, topartists, toptracks]. Set your LastFM ID with the set method (default is your current nick) or specify id to switch for one call.
|
|
||||||
```
|
|
||||||
|
103
LastFM/plugin.py
103
LastFM/plugin.py
@ -127,109 +127,6 @@ class LastFM(callbacks.Plugin):
|
|||||||
self.db.flush()
|
self.db.flush()
|
||||||
self.__parent.die()
|
self.__parent.die()
|
||||||
|
|
||||||
def lastfm(self, irc, msg, args, method, user):
|
|
||||||
"""<method> [<user>]
|
|
||||||
|
|
||||||
Lists LastFM info where <method> is in
|
|
||||||
[friends, neighbours, profile, recenttracks, tags, topalbums,
|
|
||||||
topartists, toptracks].
|
|
||||||
"""
|
|
||||||
if not self.apiKey:
|
|
||||||
irc.error("The API Key is not set. Please set it via "
|
|
||||||
"'config plugins.lastfm.apikey' and reload the plugin. "
|
|
||||||
"You can sign up for an API Key using "
|
|
||||||
"http://www.last.fm/api/account/create", Raise=True)
|
|
||||||
knownMethods = {'friends': 'user.getFriends',
|
|
||||||
'neighbours': 'user.getNeighbours',
|
|
||||||
'tags': 'user.getTopTags',
|
|
||||||
'topalbums': 'user.getTopAlbums',
|
|
||||||
'topartists': 'user.getTopArtists',
|
|
||||||
'toptracks': 'user.getTopTracks',
|
|
||||||
'recenttracks': 'user.getRecentTracks'}
|
|
||||||
user = (user or self.db.get(msg.prefix) or msg.nick)
|
|
||||||
channel = msg.args[0]
|
|
||||||
maxResults = self.registryValue("maxResults", channel)
|
|
||||||
|
|
||||||
url = "%sapi_key=%s&method=%s&user=%s" % (self.APIURL,
|
|
||||||
self.apiKey, knownMethods[method], user)
|
|
||||||
try:
|
|
||||||
f = utils.web.getUrlFd(url)
|
|
||||||
except utils.web.Error:
|
|
||||||
irc.error("Unknown user '%s'." % user, Raise=True)
|
|
||||||
|
|
||||||
xml = minidom.parse(f).getElementsByTagName("lfm")[0]
|
|
||||||
# Grab a list of item names
|
|
||||||
content = xml.childNodes[1].getElementsByTagName("name")
|
|
||||||
# Fetch their values, strip leading/trailing spaces, and add bolding
|
|
||||||
results = [ircutils.bold(res.firstChild.nodeValue.strip()) for res in
|
|
||||||
content[0:maxResults*2]]
|
|
||||||
if method in ('topalbums', 'toptracks', 'recenttracks'):
|
|
||||||
# Annoying, hackish way of grouping artist+album/track items
|
|
||||||
results = ["%s - %s" % (thing, artist) for thing, artist in
|
|
||||||
izip(results[1::2], results[::2])]
|
|
||||||
if len(content) < 1:
|
|
||||||
irc.error("%s doesn't seem to have any %s on LastFM." % (user,
|
|
||||||
method), Raise=True)
|
|
||||||
irc.reply("%s's %s: %s (with a total number of %i entries)"
|
|
||||||
% (ircutils.bold(user), method,
|
|
||||||
", ".join(results[0:maxResults]), len(content)))
|
|
||||||
|
|
||||||
@wrap([additional("something")])
|
|
||||||
def friends(self, irc, msg, args, user):
|
|
||||||
"""[<user>]
|
|
||||||
|
|
||||||
Shows friends for <user>. If <user> is not given, defaults
|
|
||||||
to the LastFM user configured for your current nick."""
|
|
||||||
self.lastfm(irc, msg, args, 'friends', user)
|
|
||||||
|
|
||||||
@wrap([additional("something")])
|
|
||||||
def neighbours(self, irc, msg, args, user):
|
|
||||||
"""[<user>]
|
|
||||||
|
|
||||||
Shows friends for <user>. If <user> is not given, defaults
|
|
||||||
to the LastFM user configured for your current nick."""
|
|
||||||
self.lastfm(irc, msg, args, 'neighbours', user)
|
|
||||||
|
|
||||||
@wrap([additional("something")])
|
|
||||||
def toptags(self, irc, msg, args, user):
|
|
||||||
"""[<user>]
|
|
||||||
|
|
||||||
Shows the top tags for <user>. If <user> is not given, defaults
|
|
||||||
to the LastFM user configured for your current nick."""
|
|
||||||
self.lastfm(irc, msg, args, 'tags', user)
|
|
||||||
|
|
||||||
@wrap([additional("something")])
|
|
||||||
def topalbums(self, irc, msg, args, user):
|
|
||||||
"""[<user>]
|
|
||||||
|
|
||||||
Shows the top albums for <user>. If <user> is not given, defaults
|
|
||||||
to the LastFM user configured for your current nick."""
|
|
||||||
self.lastfm(irc, msg, args, 'topalbums', user)
|
|
||||||
|
|
||||||
@wrap([additional("something")])
|
|
||||||
def toptracks(self, irc, msg, args, user):
|
|
||||||
"""[<user>]
|
|
||||||
|
|
||||||
Shows the top tracks for <user>. If <user> is not given, defaults
|
|
||||||
to the LastFM user configured for your current nick."""
|
|
||||||
self.lastfm(irc, msg, args, 'toptracks', user)
|
|
||||||
|
|
||||||
@wrap([additional("something")])
|
|
||||||
def topartists(self, irc, msg, args, user):
|
|
||||||
"""[<user>]
|
|
||||||
|
|
||||||
Shows the top artists for <user>. If <user> is not given, defaults
|
|
||||||
to the LastFM user configured for your current nick."""
|
|
||||||
self.lastfm(irc, msg, args, 'topartists', user)
|
|
||||||
|
|
||||||
@wrap([additional("something")])
|
|
||||||
def recenttracks(self, irc, msg, args, user):
|
|
||||||
"""[<user>]
|
|
||||||
|
|
||||||
Shows the recent tracks for <user>. If <user> is not given, defaults
|
|
||||||
to the LastFM user configured for your current nick."""
|
|
||||||
self.lastfm(irc, msg, args, 'recenttracks', user)
|
|
||||||
|
|
||||||
def nowPlaying(self, irc, msg, args, user):
|
def nowPlaying(self, irc, msg, args, user):
|
||||||
"""[<user>]
|
"""[<user>]
|
||||||
|
|
||||||
|
@ -52,10 +52,6 @@ class LastFMTestCase(PluginTestCase):
|
|||||||
raise callbacks.Error(e)
|
raise callbacks.Error(e)
|
||||||
conf.supybot.plugins.LastFM.apiKey.setValue(apiKey)
|
conf.supybot.plugins.LastFM.apiKey.setValue(apiKey)
|
||||||
|
|
||||||
def testRecentTracks(self):
|
|
||||||
self.assertNotError("recenttracks")
|
|
||||||
self.assertNotError("recenttracks czshadow")
|
|
||||||
|
|
||||||
def testNowPlaying(self):
|
def testNowPlaying(self):
|
||||||
self.assertNotError("np krf")
|
self.assertNotError("np krf")
|
||||||
|
|
||||||
@ -67,49 +63,4 @@ class LastFMTestCase(PluginTestCase):
|
|||||||
self.assertNotError("profile czshadow")
|
self.assertNotError("profile czshadow")
|
||||||
self.assertNotError("profile test")
|
self.assertNotError("profile test")
|
||||||
|
|
||||||
def testParseRecentTracks(self):
|
|
||||||
"""Parser tests"""
|
|
||||||
|
|
||||||
# noalbum, nowplaying
|
|
||||||
data1 = """<recenttracks user="USER" page="1" perPage="10" totalPages="3019">
|
|
||||||
<track nowplaying="true">
|
|
||||||
<artist mbid="2f9ecbed-27be-40e6-abca-6de49d50299e">ARTIST</artist>
|
|
||||||
<name>TRACK</name>
|
|
||||||
<mbid/>
|
|
||||||
<album mbid=""/>
|
|
||||||
<url>www.last.fm/music/Aretha+Franklin/_/Sisters+Are+Doing+It+For+Themselves</url>
|
|
||||||
<date uts="1213031819">9 Jun 2008, 17:16</date>
|
|
||||||
<streamable>1</streamable>
|
|
||||||
</track>
|
|
||||||
</recenttracks>"""
|
|
||||||
|
|
||||||
# album, not nowplaying
|
|
||||||
data2 = """<recenttracks user="USER" page="1" perPage="10" totalPages="3019">
|
|
||||||
<track nowplaying="false">
|
|
||||||
<artist mbid="2f9ecbed-27be-40e6-abca-6de49d50299e">ARTIST</artist>
|
|
||||||
<name>TRACK</name>
|
|
||||||
<mbid/>
|
|
||||||
<album mbid="">ALBUM</album>
|
|
||||||
<url>www.last.fm/music/Aretha+Franklin/_/Sisters+Are+Doing+It+For+Themselves</url>
|
|
||||||
<date uts="1213031819">9 Jun 2008, 17:16</date>
|
|
||||||
<streamable>1</streamable>
|
|
||||||
</track>
|
|
||||||
</recenttracks>"""
|
|
||||||
|
|
||||||
parser = LastFMParser()
|
|
||||||
(user, isNowPlaying, artist, track, album, time) = \
|
|
||||||
parser.parseRecentTracks(StringIO(data1))
|
|
||||||
self.assertEqual(user, "USER")
|
|
||||||
self.assertEqual(isNowPlaying, True)
|
|
||||||
self.assertEqual(artist, "ARTIST")
|
|
||||||
self.assertEqual(track, "TRACK")
|
|
||||||
self.assertEqual(album, None)
|
|
||||||
self.assertEqual(time, None)
|
|
||||||
|
|
||||||
(user, isNowPlaying, artist, track, album, time) = \
|
|
||||||
parser.parseRecentTracks(StringIO(data2))
|
|
||||||
self.assertEqual(album, "ALBUM")
|
|
||||||
self.assertEqual(time, 1213031819)
|
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user