Skip to content

Commit

Permalink
scrobbling restored (#133)
Browse files Browse the repository at this point in the history
* scrobbling restored

* Scrobble time fix.

* Honor 80 cols

* Use client tstamp or server time
  • Loading branch information
nicfit authored and redshodan committed Dec 25, 2018
1 parent 3021e43 commit bfcebe9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
14 changes: 14 additions & 0 deletions test/tests/rest/testscrobble.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import time

from unsonic.views.rest.scrobble import Scrobble
from . import buildCmd, checkResp


def testScrobble(session):
cmd = buildCmd(session, Scrobble, {"id": "tr-1"})
checkResp(cmd.req, cmd())


def testScrobbleSubmission(session):
cmd = buildCmd(session, Scrobble,
{"id": "tr-1", "time": str(int(time.time()) * 1000),
"submission":"True"})
checkResp(cmd.req, cmd())


def testScrobbleSubmissionNoTime(session):
cmd = buildCmd(session, Scrobble, {"id": "tr-1", "submission":"True"})
checkResp(cmd.req, cmd())
12 changes: 7 additions & 5 deletions unsonic/views/rest/scrobble.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import time
import datetime

from sqlalchemy.orm.exc import NoResultFound
Expand Down Expand Up @@ -37,9 +38,9 @@ def handleReq(self, session):

if lastfm.is_user:
log.info(
f"last.fm now playing: {track.artist} - {track.title}")
f"last.fm now playing: {track.artist.name} - {track.title}")
lastfm.update_now_playing(
track.artist, track.title,
track.artist.name, track.title,
album=track.album.title,
album_artist=track.album.artist.name,
duration=round(track.time_secs),
Expand Down Expand Up @@ -69,16 +70,17 @@ def handleReq(self, session):
if lastfm.is_user:
log.info(
f"last.fm scrobbling: {track.artist} - {track.title}")
lastfm.scrobble(track.artist.name, track.title,
self.params["time"] / 1000,
tstamp = self.params["time"]
tstamp = tstamp / 1000 if stamp else int(time.time())
lastfm.scrobble(track.artist.name, track.title, tstamp,
album=track.album.title,
album_artist=track.album.artist.name,
track_number=track.track_num,
duration=round(track.time_secs))
else:
log.info(f"No LastFM user, skipping LastFM")
except Exception as e:
log.error("Error talking to LastFM: " + str(e))
log.error("Error talking to LastFM: " + str(e), exc_info=e)
return self.makeResp(status=504)

return self.makeResp()

0 comments on commit bfcebe9

Please sign in to comment.