Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Platypush
platypush
Commits
3d22d6b0
Verified
Commit
3d22d6b0
authored
Jun 05, 2022
by
Fabio Manganiello
Browse files
Added get_track and get_similar_tracks methods on `lastfm` plugin
parent
5971ec32
Pipeline
#252
passed with stages
in 5 minutes and 33 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
platypush/plugins/lastfm/__init__.py
View file @
3d22d6b0
...
...
@@ -137,5 +137,80 @@ class LastfmPlugin(Plugin):
)
]
@
action
def
get_track
(
self
,
artist
:
str
,
title
:
str
)
->
Optional
[
dict
]:
"""
Get the information about a track.
:param artist: Track artist.
:param title: Track title.
:return: The retrieved track, with the title corrected if required, if
it exists on Last.FM. Example:
.. code-block:: json
{
"artist": "Led Zeppelin",
"title": "Stairway to Heaven",
"tags": ["rock", "hard rock", "70s"]
}
"""
track
=
self
.
lastfm
.
get_track
(
artist
,
title
)
return
{
'title'
:
track
.
get_correction
(),
'tags'
:
track
.
get_tags
(),
**
({
'artist'
:
track
.
artist
.
name
}
if
track
.
artist
else
{
'artist'
:
None
}),
}
@
action
def
get_similar_tracks
(
self
,
artist
:
str
,
title
:
str
)
->
List
[
dict
]:
"""
Get the tracks that are similar to a specific track.
:param artist: Track artist.
:param title: Track title.
:return: A list of similar tracks, each with a ``match`` score between
0 and 1. Example:
.. code-block:: json
[
{
"artist": "Led Zeppelin",
"title": "Black Dog",
"score": 1.0
},
{
"artist": "Led Zeppelin",
"title": "Rock and Roll",
"score": 0.89
},
{
"artist": "Eagles",
"title": "Hotel California",
"score": 0.471
},
{
"artist": "Deep Purple",
"title": "Smoke on the Water",
"score": 0.393
}
]
"""
track
=
self
.
lastfm
.
get_track
(
artist
,
title
)
if
not
track
:
return
[]
return
[
{
'artist'
:
t
.
item
.
artist
.
name
,
'title'
:
t
.
item
.
title
,
'score'
:
t
.
match
,
}
for
t
in
track
.
get_similar
()
]
# vim:sw=4:ts=4:et:
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment