mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
Fix: All scrobbles were applied to the Last.fm account associated with user ID 1 (#434)
This commit is contained in:
committed by
GitHub
parent
7eb5c6bbc6
commit
ea76cf5dc2
@@ -78,7 +78,7 @@ def create_lastfm_session(body: LastFmSessionBody):
|
|||||||
if not body.token:
|
if not body.token:
|
||||||
return {"error": "Missing token"}, 400
|
return {"error": "Missing token"}, 400
|
||||||
|
|
||||||
lastfm = LastFmPlugin()
|
lastfm = LastFmPlugin(current_userid=get_current_userid())
|
||||||
session_key = lastfm.get_session_key(body.token)
|
session_key = lastfm.get_session_key(body.token)
|
||||||
|
|
||||||
if session_key:
|
if session_key:
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ from swingmusic.utils.stats import (
|
|||||||
get_artists_in_period,
|
get_artists_in_period,
|
||||||
get_tracks_in_period,
|
get_tracks_in_period,
|
||||||
)
|
)
|
||||||
|
from swingmusic.utils.auth import get_current_userid
|
||||||
|
|
||||||
|
|
||||||
bp_tag = Tag(name="Logger", description="Log item plays")
|
bp_tag = Tag(name="Logger", description="Log item plays")
|
||||||
api = APIBlueprint("logger", __name__, url_prefix="/logger", abp_tags=[bp_tag])
|
api = APIBlueprint("logger", __name__, url_prefix="/logger", abp_tags=[bp_tag])
|
||||||
@@ -101,7 +103,7 @@ def log_track(body: LogTrackBody):
|
|||||||
trackentry.increment_playcount(duration, timestamp)
|
trackentry.increment_playcount(duration, timestamp)
|
||||||
track = trackentry.tracks[0]
|
track = trackentry.tracks[0]
|
||||||
|
|
||||||
lastfm = LastFmPlugin()
|
lastfm = LastFmPlugin(current_userid=get_current_userid())
|
||||||
|
|
||||||
if (
|
if (
|
||||||
lastfm.enabled
|
lastfm.enabled
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from urllib.parse import quote_plus
|
|||||||
from swingmusic.config import UserConfig
|
from swingmusic.config import UserConfig
|
||||||
from swingmusic.models.track import Track
|
from swingmusic.models.track import Track
|
||||||
from swingmusic.settings import Paths
|
from swingmusic.settings import Paths
|
||||||
from swingmusic.utils.auth import get_current_userid
|
|
||||||
from swingmusic.utils.threading import background
|
from swingmusic.utils.threading import background
|
||||||
from swingmusic.plugins import Plugin, plugin_method
|
from swingmusic.plugins import Plugin, plugin_method
|
||||||
|
|
||||||
@@ -23,14 +22,15 @@ class LastFmPlugin(Plugin):
|
|||||||
|
|
||||||
UPLOADING_DUMPS = False
|
UPLOADING_DUMPS = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, current_userid: int):
|
||||||
self.config = UserConfig()
|
self.config = UserConfig()
|
||||||
|
self.current_userid = current_userid
|
||||||
super().__init__("lastfm", "Last.fm scrobbler")
|
super().__init__("lastfm", "Last.fm scrobbler")
|
||||||
self.set_active(
|
self.set_active(
|
||||||
bool(
|
bool(
|
||||||
self.config.lastfmApiKey
|
self.config.lastfmApiKey
|
||||||
and self.config.lastfmApiSecret
|
and self.config.lastfmApiSecret
|
||||||
and self.config.lastfmSessionKeys.get(str(get_current_userid()))
|
and self.config.lastfmSessionKeys.get(str(self.current_userid))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -46,7 +46,7 @@ class LastFmPlugin(Plugin):
|
|||||||
url = "http://ws.audioscrobbler.com/2.0/?format=json"
|
url = "http://ws.audioscrobbler.com/2.0/?format=json"
|
||||||
data["api_key"] = self.config.lastfmApiKey
|
data["api_key"] = self.config.lastfmApiKey
|
||||||
if useSessionKey:
|
if useSessionKey:
|
||||||
data["sk"] = self.config.lastfmSessionKeys.get(str(get_current_userid()))
|
data["sk"] = self.config.lastfmSessionKeys.get(str(self.current_userid))
|
||||||
|
|
||||||
data["api_sig"] = self.get_api_signature(data)
|
data["api_sig"] = self.get_api_signature(data)
|
||||||
|
|
||||||
@@ -113,7 +113,7 @@ class LastFmPlugin(Plugin):
|
|||||||
log.error("LAST.FM: Invalid session key")
|
log.error("LAST.FM: Invalid session key")
|
||||||
# Invalid session key
|
# Invalid session key
|
||||||
try:
|
try:
|
||||||
self.config.lastfmSessionKeys.pop(str(get_current_userid()))
|
self.config.lastfmSessionKeys.pop(str(self.current_userid))
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import hashlib
|
|||||||
from flask_jwt_extended import current_user
|
from flask_jwt_extended import current_user
|
||||||
|
|
||||||
from swingmusic.config import UserConfig
|
from swingmusic.config import UserConfig
|
||||||
|
from swingmusic.logger import log
|
||||||
|
|
||||||
|
|
||||||
def hash_password(password: str) -> str:
|
def hash_password(password: str) -> str:
|
||||||
@@ -38,6 +39,11 @@ def get_current_userid() -> int:
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return current_user["id"]
|
return current_user["id"]
|
||||||
except RuntimeError:
|
except RuntimeError as e:
|
||||||
# Catch this error raised during migration execution
|
# Catch this error raised during migration execution
|
||||||
|
if log:
|
||||||
|
log.error("get_current_userid: Unable to get current user id")
|
||||||
|
log.error(e)
|
||||||
|
# TODO: possible change to other than real userid,
|
||||||
|
# because it is really hard to debug when no fault but data goes to wrong user
|
||||||
return 1
|
return 1
|
||||||
|
|||||||
Reference in New Issue
Block a user