Add compare by b0nk. And some minor fixes.
This commit is contained in:
parent
d4ec988566
commit
d04f84cb4b
|
|
@ -109,6 +109,11 @@ class LastFM(callbacks.Plugin):
|
|||
self.network = None
|
||||
self.prepend = "0,5last.fm"
|
||||
self.loved = "13<3 "
|
||||
self.pretty_bar = ["[04==== ]",
|
||||
"[04====07==== ]",
|
||||
"[04====07====08==== ]",
|
||||
"[04====07====08====09====]",
|
||||
"[ ]"]
|
||||
|
||||
def die(self):
|
||||
self.__parent.die()
|
||||
|
|
@ -133,8 +138,13 @@ class LastFM(callbacks.Plugin):
|
|||
def setuser(self, irc, msg, args, channel, user):
|
||||
"""[<channel>] <last.fm user>
|
||||
|
||||
Assigns the <last.fm user> to the current nick, in [channel].
|
||||
Assigns the <last.fm account> to the current nick, in [channel].
|
||||
"""
|
||||
userinfo = self.network.get_user(user)
|
||||
if not userinfo:
|
||||
irc.error("User not found", prefixNick=False)
|
||||
return
|
||||
|
||||
self.db.set_user(channel, msg.nick.lower(), user)
|
||||
irc.reply("{} User set as {} for {}".format(
|
||||
self.prepend,
|
||||
|
|
@ -143,6 +153,65 @@ class LastFM(callbacks.Plugin):
|
|||
), prefixNick=False)
|
||||
setuser = wrap(setuser, ['channel', 'anything'])
|
||||
|
||||
def compare(self, irc, msg, args, channel, user):
|
||||
"""[<channel>] <last.fm account/nick>
|
||||
|
||||
Compares your account with the <last.fm account/nick> account, in [channel].
|
||||
"""
|
||||
if self.connect() is False:
|
||||
return
|
||||
|
||||
user1 = msg.nick.lower()
|
||||
user2 = user.lower()
|
||||
|
||||
username1 = self.db.get_user(channel, user1)
|
||||
if not username1:
|
||||
username1 = user1
|
||||
username2 = self.db.get_user(channel, user2)
|
||||
if not username2:
|
||||
username2 = user2
|
||||
|
||||
try:
|
||||
user1_favs = self.network.get_user(username1).get_top_artists('overall', 100)
|
||||
user2_favs = self.network.get_user(username2).get_top_artists('overall', 100)
|
||||
except pylast.WSError as e:
|
||||
irc.error(str(e), prefixNick=False)
|
||||
return
|
||||
|
||||
n_artists1 = len(user1_favs)
|
||||
n_artists2 = len(user2_favs)
|
||||
|
||||
user1_favs = [str(i.item) for i in user1_favs]
|
||||
user2_favs = [str(i.item) for i in user2_favs]
|
||||
|
||||
intersection = [artist for artist in user1_favs if artist in user2_favs]
|
||||
artist_list = intersection[:5]
|
||||
|
||||
comparison_index = round(200.0 * len(intersection) / (n_artists1 + n_artists2), 2)
|
||||
|
||||
if comparison_index < 1.0:
|
||||
bar = self.pretty_bar[4]
|
||||
else:
|
||||
bar = self.pretty_bar[int(comparison_index / 25.01)]
|
||||
|
||||
if artist_list:
|
||||
parsed_list = [str(item) for item in artist_list]
|
||||
chart_text = ", ".join(parsed_list)
|
||||
else:
|
||||
chart_text = "N/A"
|
||||
|
||||
|
||||
message = "{} Comparison: {} {} {}: Similarity: {}% - Common Artists: {}".format(
|
||||
self.prepend,
|
||||
user1,
|
||||
bar,
|
||||
user2,
|
||||
comparison_index,
|
||||
chart_text
|
||||
)
|
||||
irc.reply(message, prefixNick=False)
|
||||
compare = wrap(compare, ['channel', 'anything'])
|
||||
|
||||
def nowplaying(self, irc, msg, args, channel, user):
|
||||
"""[<channel>] [<last.fm user>]
|
||||
|
||||
|
|
@ -157,6 +226,10 @@ class LastFM(callbacks.Plugin):
|
|||
username = self.db.get_user(channel, msg.nick.lower())
|
||||
|
||||
userinfo = self.network.get_user(username)
|
||||
if not userinfo:
|
||||
irc.error("User not found", prefixNick=False)
|
||||
return
|
||||
|
||||
track = userinfo.get_now_playing()
|
||||
|
||||
if not track:
|
||||
|
|
|
|||
Loading…
Reference in New Issue