1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Increase play count and update now playing on /scrobble rather than /stream

This commit is contained in:
Alban Féron 2024-06-02 12:33:08 +02:00
parent 88997d5984
commit f178410001
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
5 changed files with 23 additions and 16 deletions

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2013-2022 Alban 'spl0k' Féron # Copyright (C) 2013-2024 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -12,6 +12,7 @@ from flask import current_app, request
from ..db import Track, Album, Artist, Folder from ..db import Track, Album, Artist, Folder
from ..db import StarredTrack, StarredAlbum, StarredArtist, StarredFolder from ..db import StarredTrack, StarredAlbum, StarredArtist, StarredFolder
from ..db import RatingTrack, RatingFolder from ..db import RatingTrack, RatingFolder
from ..db import now
from ..lastfm import LastFm from ..lastfm import LastFm
from ..listenbrainz import ListenBrainz from ..listenbrainz import ListenBrainz
@ -175,6 +176,17 @@ def scrobble():
t, submission = map(request.values.get, ("time", "submission")) t, submission = map(request.values.get, ("time", "submission"))
t = int(t) / 1000 if t else int(time.time()) t = int(t) / 1000 if t else int(time.time())
if not submission or submission not in (True, "true", "True", 1, "1"):
date = now()
res.play_count = res.play_count + 1
res.last_play = date
res.save()
user = request.user
user.last_play = res
user.last_play_date = date
user.save()
lfm = LastFm(current_app.config["LASTFM"], request.user) lfm = LastFm(current_app.config["LASTFM"], request.user)
lbz = ListenBrainz(current_app.config["LISTENBRAINZ"], request.user) lbz = ListenBrainz(current_app.config["LISTENBRAINZ"], request.user)

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2013-2022 Alban 'spl0k' Féron # Copyright (C) 2013-2024 Alban 'spl0k' Féron
# 2018-2019 Carey 'pR0Ps' Metcalfe # 2018-2019 Carey 'pR0Ps' Metcalfe
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -24,7 +24,7 @@ from xml.etree import ElementTree
from zipstream import ZipStream from zipstream import ZipStream
from ..cache import CacheMiss from ..cache import CacheMiss
from ..db import Track, Album, Artist, Folder, now from ..db import Track, Album, Artist, Folder
from ..covers import EXTENSIONS from ..covers import EXTENSIONS
from . import get_entity, get_entity_id, api_routing from . import get_entity, get_entity_id, api_routing
@ -208,15 +208,6 @@ def stream_media():
else: else:
response = send_file(res.path, mimetype=dst_mimetype, conditional=True) response = send_file(res.path, mimetype=dst_mimetype, conditional=True)
res.play_count = res.play_count + 1
res.last_play = now()
res.save()
user = request.user
user.last_play = res
user.last_play_date = now()
user.save()
return response return response

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2017-2022 Alban 'spl0k' Féron # Copyright (C) 2017-2024 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -184,6 +184,9 @@ class AnnotationTestCase(ApiTestBase):
self._make_request("scrobble", {"id": str(self.trackid)}) self._make_request("scrobble", {"id": str(self.trackid)})
self._make_request("scrobble", {"id": str(self.trackid), "submission": True}) self._make_request("scrobble", {"id": str(self.trackid), "submission": True})
self._make_request("scrobble", {"id": str(self.trackid), "submission": False}) self._make_request("scrobble", {"id": str(self.trackid), "submission": False})
self.assertEqual(
Track[self.trackid].play_count, 4
) # (GET+POST) * (missing submission + submission False)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2017-2022 Alban 'spl0k' Féron # Copyright (C) 2017-2024 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -94,7 +94,7 @@ class MediaTestCase(ApiTestBase):
) as rv: ) as rv:
self.assertEqual(rv.status_code, 200) self.assertEqual(rv.status_code, 200)
self.assertEqual(len(rv.data), 23) self.assertEqual(len(rv.data), 23)
self.assertEqual(Track[self.trackid].play_count, 1) self.assertEqual(Track[self.trackid].play_count, 0)
def test_download(self): def test_download(self):
self._make_request("download", error=10) self._make_request("download", error=10)

View File

@ -422,10 +422,11 @@ class SearchTestCase(ApiTestBase):
# empty query # empty query
rv, child = self._make_request("search3", {"query": ""}, tag="searchResult3") rv, child = self._make_request("search3", {"query": ""}, tag="searchResult3")
self.assertEqual(len(child), 27) # 3 + 3*2 + 3*2*3 self.assertEqual(len(child), 27) # 3 + 3*2 + 3*2*3
self.assertEqual(len(self._xpath(child, "./artist")), 3) self.assertEqual(len(self._xpath(child, "./artist")), 3)
self.assertEqual(len(self._xpath(child, "./album")), 6) self.assertEqual(len(self._xpath(child, "./album")), 6)
self.assertEqual(len(self._xpath(child, "./song")), 18) self.assertEqual(len(self._xpath(child, "./song")), 18)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()