Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
funkwhale
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Baptiste Benti
funkwhale
Commits
54633ef5
Verified
Commit
54633ef5
authored
5 years ago
by
Eliot Berriot
Browse files
Options
Downloads
Patches
Plain Diff
Working audioscrobbler with last.fm!
parent
8e68e69f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/plugins/fw_scrobbler/hooks.py
+25
-1
25 additions, 1 deletion
api/plugins/fw_scrobbler/hooks.py
api/plugins/fw_scrobbler/scrobbler.py
+33
-11
33 additions, 11 deletions
api/plugins/fw_scrobbler/scrobbler.py
front/src/components/audio/Player.vue
+1
-1
1 addition, 1 deletion
front/src/components/audio/Player.vue
with
59 additions
and
13 deletions
api/plugins/fw_scrobbler/hooks.py
+
25
−
1
View file @
54633ef5
...
...
@@ -19,7 +19,7 @@ def forward_to_scrobblers(listening, plugin_conf, **kwargs):
if
username
and
password
:
plugin
.
logger
.
info
(
"
Forwarding scrobbler to %s
"
,
url
)
session
=
plugin
.
get_requests_session
()
session_key
,
scrobble_url
=
scrobbler
.
handshake_v1
(
session_key
,
_
,
scrobble_url
=
scrobbler
.
handshake_v1
(
session
=
session
,
url
=
url
,
username
=
username
,
password
=
password
)
scrobbler
.
submit_scrobble_v1
(
...
...
@@ -31,3 +31,27 @@ def forward_to_scrobblers(listening, plugin_conf, **kwargs):
)
else
:
plugin
.
logger
.
debug
(
"
No scrobbler configuration for user, skipping
"
)
@plugin.hooks.connect
(
"
history.listening.now
"
)
def
forward_to_now_playing
(
track
,
user
,
plugin_conf
,
**
kwargs
):
if
plugin_conf
[
"
user
"
]
is
None
:
raise
plugins
.
Skip
()
username
=
plugin_conf
[
"
user
"
][
"
settings
"
].
get
(
"
service__username
"
)
password
=
plugin_conf
[
"
user
"
][
"
settings
"
].
get
(
"
service__password
"
)
url
=
plugin_conf
[
"
user
"
][
"
settings
"
].
get
(
"
service__url
"
,
DEFAULT_SCROBBLER_URL
)
if
username
and
password
:
plugin
.
logger
.
info
(
"
Forwarding scrobbler to %s
"
,
url
)
session
=
plugin
.
get_requests_session
()
session_key
,
now_playing_url
,
_
=
scrobbler
.
handshake_v1
(
session
=
session
,
url
=
url
,
username
=
username
,
password
=
password
)
scrobbler
.
submit_now_playing_v1
(
session
=
session
,
track
=
track
,
session_key
=
session_key
,
now_playing_url
=
now_playing_url
,
)
else
:
plugin
.
logger
.
debug
(
"
No scrobbler configuration for user, skipping
"
)
This diff is collapsed.
Click to expand it.
api/plugins/fw_scrobbler/scrobbler.py
+
33
−
11
View file @
54633ef5
...
...
@@ -38,7 +38,7 @@ def handshake_v1(session, url, username, password):
result
=
handshake_response
.
text
.
split
(
"
\n
"
)
if
len
(
result
)
>=
4
and
result
[
0
]
==
"
OK
"
:
session_key
=
result
[
1
]
#
nowplaying_url = result[2]
nowplaying_url
=
result
[
2
]
scrobble_url
=
result
[
3
]
elif
result
[
0
]
==
"
BANNED
"
:
raise
ScrobblerException
(
"
BANNED
"
)
...
...
@@ -50,7 +50,7 @@ def handshake_v1(session, url, username, password):
raise
ScrobblerException
(
handshake_response
.
text
)
plugin
.
logger
.
debug
(
"
Handshake successful, scrobble url: %s
"
,
scrobble_url
)
return
session_key
,
scrobble_url
return
session_key
,
nowplaying_url
,
scrobble_url
def
submit_scrobble_v1
(
session
,
scrobble_time
,
track
,
session_key
,
scrobble_url
):
...
...
@@ -69,14 +69,36 @@ def submit_scrobble_v1(session, scrobble_time, track, session_key, scrobble_url)
plugin
.
logger
.
debug
(
"
Scrobble successfull!
"
)
def
get_scrobble_payload
(
track
,
scrobble_time
):
def
submit_now_playing_v1
(
session
,
track
,
session_key
,
now_playing_url
):
payload
=
get_scrobble_payload
(
track
,
date
=
None
,
suffix
=
""
)
plugin
.
logger
.
debug
(
"
Sending now playing with payload %s
"
,
payload
)
payload
[
"
s
"
]
=
session_key
response
=
session
.
post
(
now_playing_url
,
payload
)
response
.
raise_for_status
()
if
response
.
text
.
startswith
(
"
OK
"
):
return
elif
response
.
text
.
startswith
(
"
BADSESSION
"
):
raise
ScrobblerException
(
"
Remote server says the session is invalid
"
)
else
:
raise
ScrobblerException
(
response
.
text
)
plugin
.
logger
.
debug
(
"
Now playing successfull!
"
)
def
get_scrobble_payload
(
track
,
date
,
suffix
=
"
[0]
"
):
"""
Documentation available at https://web.archive.org/web/20190531021725/https://www.last.fm/api/submissions
"""
upload
=
track
.
uploads
.
filter
(
duration__gte
=
0
).
first
()
return
{
"
a
[0]
"
:
track
.
artist
.
name
,
"
t
[0]
"
:
track
.
title
,
"
i[0]
"
:
int
(
scrobble_time
.
timestamp
())
,
"
l[0]
"
:
upload
.
duration
if
upload
else
0
,
"
b[0]
"
:
track
.
album
.
title
or
""
,
"
n[0]
"
:
track
.
position
or
""
,
"
m[0]
"
:
str
(
track
.
mbid
)
or
""
,
data
=
{
"
a
{}
"
.
format
(
suffix
)
:
track
.
artist
.
name
,
"
t
{}
"
.
format
(
suffix
)
:
track
.
title
,
"
l{}
"
.
format
(
suffix
):
upload
.
duration
if
upload
else
0
,
"
b{}
"
.
format
(
suffix
):
track
.
album
.
title
or
""
,
"
n{}
"
.
format
(
suffix
):
track
.
position
or
""
,
"
m{}
"
.
format
(
suffix
):
str
(
track
.
mbid
)
or
""
,
"
o{}
"
.
format
(
suffix
):
"
P
"
,
# Source: P = chosen by user
}
if
date
:
data
[
"
i{}
"
.
format
(
suffix
)]
=
int
(
date
.
timestamp
())
return
data
This diff is collapsed.
Click to expand it.
front/src/components/audio/Player.vue
+
1
−
1
View file @
54633ef5
...
...
@@ -395,7 +395,7 @@ export default {
},
onunlock
:
function
()
{
if
(
self
.
$store
.
state
.
player
.
playing
)
{
self
.
soundId
=
self
.
sound
.
play
(
self
.
soundId
)
self
.
soundId
=
sound
.
play
(
self
.
soundId
)
}
},
onload
:
function
()
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment