Nova versão, ja mostra as tags e supostamente deveria mostrar a playcount. Abri uma issue no pylast.
This commit is contained in:
parent
56c44b87c6
commit
7e3d3b7805
|
|
@ -104,18 +104,40 @@ class LastFM(callbacks.Plugin):
|
|||
self.__parent = super(LastFM, self)
|
||||
self.__parent.__init__(irc)
|
||||
self.db = LastFMDB()
|
||||
self.network = None
|
||||
self.prepend = "0,5last.fm"
|
||||
|
||||
def die(self):
|
||||
self.__parent.die()
|
||||
self.db.close()
|
||||
|
||||
def connect(self):
|
||||
key = self.registryValue('apiKey')
|
||||
secret = self.registryValue('apiSecret')
|
||||
|
||||
if not key:
|
||||
irc.error("{} API key not set".format(self.prepend))
|
||||
return False
|
||||
if not secret:
|
||||
irc.error("{} API secret not set".format(self.prepend))
|
||||
return False
|
||||
|
||||
if self.network is None:
|
||||
self.network = pylast.LastFMNetwork(api_key=key, api_secret=secret)
|
||||
|
||||
return True
|
||||
|
||||
def setuser(self, irc, msg, args, channel, user):
|
||||
"""[<channel>] <last.fm user>
|
||||
|
||||
Assigns the last.fm user to the current nick.
|
||||
"""
|
||||
self.db.set_user(channel, msg.nick.lower(), user)
|
||||
irc.reply("Last.fm user set as {} for {}".format(user, msg.nick), prefixNick=False)
|
||||
irc.reply("{} User set as {} for {}".format(
|
||||
self.prepend,
|
||||
user,
|
||||
msg.nick
|
||||
), prefixNick=False)
|
||||
setuser = wrap(setuser, ['channel', 'anything'])
|
||||
|
||||
def nowplaying(self, irc, msg, args, channel, user):
|
||||
|
|
@ -123,14 +145,7 @@ class LastFM(callbacks.Plugin):
|
|||
|
||||
Show the currently playing song.
|
||||
"""
|
||||
key = self.registryValue('apiKey')
|
||||
secret = self.registryValue('apiSecret')
|
||||
|
||||
if not key:
|
||||
irc.error("Last.fm API key not set")
|
||||
return
|
||||
if not secret:
|
||||
irc.error("Last.fm API secret not set")
|
||||
if self.connect() is False:
|
||||
return
|
||||
|
||||
if user:
|
||||
|
|
@ -138,9 +153,37 @@ class LastFM(callbacks.Plugin):
|
|||
else:
|
||||
username = self.db.get_user(channel, msg.nick.lower())
|
||||
|
||||
network = pylast.LastFMNetwork(api_key=key, api_secret=secret)
|
||||
userinfo = network.get_user(username)
|
||||
irc.reply(userinfo.get_now_playing(), prefixNick=False)
|
||||
userinfo = self.network.get_user(username)
|
||||
track = userinfo.get_now_playing()
|
||||
playcount = userinfo.get_now_playing().get_userplaycount()
|
||||
#track_with_user = pylast.Track(artist=track.artist, title=track.title, network=self.network, username=username)
|
||||
|
||||
message = "{} {} is not playing anything right now".format(
|
||||
self.prepend,
|
||||
msg.nick
|
||||
)
|
||||
|
||||
if track:
|
||||
# Get all tags from track and create a string with ", tag1, tag2, tag3, "
|
||||
tags = track.get_top_tags()
|
||||
tagmsg = ""
|
||||
if len(tags) > 0:
|
||||
tagmsg = ", "
|
||||
for idx in range(len(tags)):
|
||||
if idx < 5:
|
||||
tagmsg += "{}, ".format(tags[idx][0])
|
||||
|
||||
# strip the last 2 chars from string
|
||||
tagmsg = tagmsg[:-2]
|
||||
|
||||
message = "{} {} is listening to: {} ({} plays{})".format(
|
||||
self.prepend,
|
||||
msg.nick,
|
||||
track,
|
||||
playcount,
|
||||
tagmsg
|
||||
)
|
||||
irc.reply(message, prefixNick=False)
|
||||
nowplaying = wrap(nowplaying, ['channel', optional('anything')])
|
||||
|
||||
Class = LastFM
|
||||
|
|
|
|||
Loading…
Reference in New Issue