mirror of
https://github.com/krateng/maloja.git
synced 2025-04-19 18:17:36 +03:00
Added username/pw authentication for last.fm
This commit is contained in:
parent
37bac06735
commit
fe1ed955cd
@ -166,6 +166,8 @@ malojaconfig = Configuration(
|
||||
"lastfm_api_key":(tp.String(), "Last.fm API Key", None),
|
||||
"lastfm_api_secret":(tp.String(), "Last.fm API Secret", None),
|
||||
"lastfm_api_sk":(tp.String(), "Last.fm API Session Key", None),
|
||||
"lastfm_username":(tp.String(), "Last.fm Username", None),
|
||||
"lastfm_password":(tp.String(), "Last.fm Password", None),
|
||||
"spotify_api_id":(tp.String(), "Spotify API ID", None),
|
||||
"spotify_api_secret":(tp.String(), "Spotify API Secret", None),
|
||||
"audiodb_api_key":(tp.String(), "TheAudioDB API Key", None),
|
||||
|
11
maloja/thirdparty/__init__.py
vendored
11
maloja/thirdparty/__init__.py
vendored
@ -92,6 +92,17 @@ class GenericInterface:
|
||||
return True
|
||||
# per default. no authorization is necessary
|
||||
|
||||
# wrapper method
|
||||
def request(self,url,data,responsetype):
|
||||
response = urllib.request.urlopen(
|
||||
url,
|
||||
data=utf(data)
|
||||
)
|
||||
responsedata = response.read()
|
||||
if responsetype == "xml":
|
||||
data = ElementTree.fromstring(responsedata)
|
||||
return data
|
||||
|
||||
# proxy scrobbler
|
||||
class ProxyScrobbleInterface(GenericInterface,abstract=True):
|
||||
|
||||
|
23
maloja/thirdparty/lastfm.py
vendored
23
maloja/thirdparty/lastfm.py
vendored
@ -1,6 +1,7 @@
|
||||
from . import MetadataInterface, ProxyScrobbleInterface, utf
|
||||
import hashlib
|
||||
import urllib.parse, urllib.request
|
||||
from doreah.logging import log
|
||||
|
||||
class LastFM(MetadataInterface, ProxyScrobbleInterface):
|
||||
name = "LastFM"
|
||||
@ -9,7 +10,9 @@ class LastFM(MetadataInterface, ProxyScrobbleInterface):
|
||||
settings = {
|
||||
"apikey":"LASTFM_API_KEY",
|
||||
"sk":"LASTFM_API_SK",
|
||||
"secret":"LASTFM_API_SECRET"
|
||||
"secret":"LASTFM_API_SECRET",
|
||||
"username":"LASTFM_USERNAME",
|
||||
"password":"LASTFM_PASSWORD"
|
||||
}
|
||||
|
||||
proxyscrobble = {
|
||||
@ -42,6 +45,24 @@ class LastFM(MetadataInterface, ProxyScrobbleInterface):
|
||||
"sk":self.settings["sk"]
|
||||
})
|
||||
|
||||
def authorize(self):
|
||||
try:
|
||||
result = self.request(
|
||||
self.proxyscrobble['scrobbleurl'],
|
||||
self.query_compose({
|
||||
"method":"auth.getMobileSession",
|
||||
"username":self.settings["username"],
|
||||
"password":self.settings["password"],
|
||||
"api_key":self.settings["apikey"]
|
||||
}),
|
||||
responsetype="xml"
|
||||
)
|
||||
self.settings["sk"] = result.find("session").findtext("key")
|
||||
except Exception as e:
|
||||
pass
|
||||
#log("Error while authenticating with LastFM: " + repr(e))
|
||||
|
||||
|
||||
# creates signature and returns full query string
|
||||
def query_compose(self,parameters):
|
||||
m = hashlib.md5()
|
||||
|
Loading…
x
Reference in New Issue
Block a user