diff --git a/LastFM/README.md b/LastFM/README.md index e30f79c..6591390 100644 --- a/LastFM/README.md +++ b/LastFM/README.md @@ -10,13 +10,15 @@ A Supybot plugin for LastFM. - Native Python 3 support. - Code cleanup and various bugfixes. - 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 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 @@ -31,15 +33,3 @@ Showing profile information: [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 ``` - -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. -``` diff --git a/LastFM/plugin.py b/LastFM/plugin.py index f8cfa56..1ed3f84 100644 --- a/LastFM/plugin.py +++ b/LastFM/plugin.py @@ -127,109 +127,6 @@ class LastFM(callbacks.Plugin): self.db.flush() self.__parent.die() - def lastfm(self, irc, msg, args, method, user): - """ [] - - Lists LastFM info where 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): - """[] - - Shows friends for . If 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): - """[] - - Shows friends for . If 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): - """[] - - Shows the top tags for . If 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): - """[] - - Shows the top albums for . If 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): - """[] - - Shows the top tracks for . If 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): - """[] - - Shows the top artists for . If 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): - """[] - - Shows the recent tracks for . If 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): """[] diff --git a/LastFM/test.py b/LastFM/test.py index 289dd73..bd9fe94 100644 --- a/LastFM/test.py +++ b/LastFM/test.py @@ -52,10 +52,6 @@ class LastFMTestCase(PluginTestCase): raise callbacks.Error(e) conf.supybot.plugins.LastFM.apiKey.setValue(apiKey) - def testRecentTracks(self): - self.assertNotError("recenttracks") - self.assertNotError("recenttracks czshadow") - def testNowPlaying(self): self.assertNotError("np krf") @@ -67,49 +63,4 @@ class LastFMTestCase(PluginTestCase): self.assertNotError("profile czshadow") self.assertNotError("profile test") - def testParseRecentTracks(self): - """Parser tests""" - - # noalbum, nowplaying - data1 = """ - - ARTIST - TRACK - - - www.last.fm/music/Aretha+Franklin/_/Sisters+Are+Doing+It+For+Themselves - 9 Jun 2008, 17:16 - 1 - -""" - - # album, not nowplaying - data2 = """ - - ARTIST - TRACK - - ALBUM - www.last.fm/music/Aretha+Franklin/_/Sisters+Are+Doing+It+For+Themselves - 9 Jun 2008, 17:16 - 1 - -""" - - 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: