From 6bb81ce589ea3e0f25167687d101793bbafcb122 Mon Sep 17 00:00:00 2001 From: krateng Date: Fri, 3 Nov 2023 13:41:30 +0100 Subject: [PATCH] Fix GH-271 --- dev/releases/3.2.yml | 6 +++++- maloja/thirdparty/lastfm.py | 35 ++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/dev/releases/3.2.yml b/dev/releases/3.2.yml index cf75ee3..9d96402 100644 --- a/dev/releases/3.2.yml +++ b/dev/releases/3.2.yml @@ -21,6 +21,7 @@ minor_release_name: "Nicole" - "[Technical] Bumped Python and SQLAlchemy versions" - "[Distribution] Removed build of arm/v7 image" 3.2.1: + commit: "5495d6e38d95c0c2128e1de9a9553b55b6be945b" notes: - "[Feature] Added setting for custom week offset" - "[Feature] Added Musicbrainz album art fetching" @@ -29,4 +30,7 @@ minor_release_name: "Nicole" - "[Bugfix] Fixed Spotify import of multiple files" - "[Bugfix] Fixed process control on FreeBSD" - "[Bugfix] Fixed Spotify authentication thread blocking the process from terminating" - - "[Technical] Upgraded all third party modules to use requests module and send User Agent" \ No newline at end of file + - "[Technical] Upgraded all third party modules to use requests module and send User Agent" +3.2.2: + notes: + - "[Bugfix] Fixed Last.fm authentication" \ No newline at end of file diff --git a/maloja/thirdparty/lastfm.py b/maloja/thirdparty/lastfm.py index cfd79b0..897fef3 100644 --- a/maloja/thirdparty/lastfm.py +++ b/maloja/thirdparty/lastfm.py @@ -55,24 +55,25 @@ class LastFM(MetadataInterface, ProxyScrobbleInterface): }) def authorize(self): - try: - response = requests.post( - url=self.proxyscrobble['scrobbleurl'], - params=self.query_compose({ - "method":"auth.getMobileSession", - "username":self.settings["username"], - "password":self.settings["password"], - "api_key":self.settings["apikey"] - }), - headers={ - "User-Agent":self.useragent - } - ) + if all(self.settings[key] not in [None,"ASK",False] for key in ["username","password","apikey","secret"]): + try: + response = requests.post( + url=self.proxyscrobble['scrobbleurl'], + params=self.query_compose({ + "method":"auth.getMobileSession", + "username":self.settings["username"], + "password":self.settings["password"], + "api_key":self.settings["apikey"] + }), + headers={ + "User-Agent":self.useragent + } + ) - data = ElementTree.fromstring(response.text) - self.settings["sk"] = data.find("session").findtext("key") - except Exception as e: - log("Error while authenticating with LastFM: " + repr(e)) + data = ElementTree.fromstring(response.text) + self.settings["sk"] = data.find("session").findtext("key") + except Exception as e: + log("Error while authenticating with LastFM: " + repr(e)) # creates signature and returns full query