forked from platypush/platypush
Merge branch 'master' into 191-support-for-general-entities-backend-and-plugin
This commit is contained in:
commit
0d0995d71d
2 changed files with 59 additions and 1 deletions
|
@ -1,4 +1,5 @@
|
||||||
import time
|
import time
|
||||||
|
from typing import Optional, List
|
||||||
|
|
||||||
from platypush.plugins import Plugin, action
|
from platypush.plugins import Plugin, action
|
||||||
|
|
||||||
|
@ -29,6 +30,7 @@ class LastfmPlugin(Plugin):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pylast
|
import pylast
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.api_key = api_key
|
self.api_key = api_key
|
||||||
|
@ -40,7 +42,8 @@ class LastfmPlugin(Plugin):
|
||||||
api_key=self.api_key,
|
api_key=self.api_key,
|
||||||
api_secret=self.api_secret,
|
api_secret=self.api_secret,
|
||||||
username=self.username,
|
username=self.username,
|
||||||
password_hash=pylast.md5(self.password))
|
password_hash=pylast.md5(self.password),
|
||||||
|
)
|
||||||
|
|
||||||
@action
|
@action
|
||||||
def scrobble(self, artist, title, album=None):
|
def scrobble(self, artist, title, album=None):
|
||||||
|
@ -81,4 +84,58 @@ class LastfmPlugin(Plugin):
|
||||||
album=album,
|
album=album,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@action
|
||||||
|
def get_recent_tracks(
|
||||||
|
self,
|
||||||
|
username: Optional[str] = None,
|
||||||
|
limit: int = 10,
|
||||||
|
time_from: Optional[int] = None,
|
||||||
|
time_to: Optional[int] = None,
|
||||||
|
) -> List[dict]:
|
||||||
|
"""
|
||||||
|
Get a list of recently played tracks.
|
||||||
|
|
||||||
|
:param username: Target username (default: the one registered to this
|
||||||
|
plugin).
|
||||||
|
:param limit: Maximum number of tracks to be returned (default: 10).
|
||||||
|
:param time_from: Return tracks starting from this time
|
||||||
|
(as a UNIX timestamp).
|
||||||
|
:param time_to: Return tracks starting up to this time
|
||||||
|
(as a UNIX timestamp).
|
||||||
|
:return: Example:
|
||||||
|
|
||||||
|
.. code-block:: json
|
||||||
|
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"artist": "Led Zeppelin",
|
||||||
|
"title": "Stairway to Heaven",
|
||||||
|
"album": "IV",
|
||||||
|
"timestamp": 1654196137
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
'title': track.track.title,
|
||||||
|
'album': track.album,
|
||||||
|
'timestamp': int(track.timestamp or 0),
|
||||||
|
**(
|
||||||
|
{'artist': track.track.artist.name}
|
||||||
|
if track.track.artist
|
||||||
|
else {'artist': None}
|
||||||
|
),
|
||||||
|
}
|
||||||
|
for track in self.lastfm.get_user(
|
||||||
|
username or self.username
|
||||||
|
).get_recent_tracks(
|
||||||
|
limit=limit,
|
||||||
|
time_from=time_from,
|
||||||
|
time_to=time_to,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# vim:sw=4:ts=4:et:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
|
@ -226,6 +226,7 @@ class NtfyPlugin(RunnablePlugin):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
method = requests.post
|
method = requests.post
|
||||||
|
click_url = url
|
||||||
url = server_url or self._server_url
|
url = server_url or self._server_url
|
||||||
args = {}
|
args = {}
|
||||||
if username and password:
|
if username and password:
|
||||||
|
|
Loading…
Reference in a new issue