1
0
mirror of https://github.com/krateng/maloja.git synced 2023-08-10 21:12:55 +03:00

Added requirements.txt and fixed error when not using API keys

This commit is contained in:
Krateng 2019-05-23 13:45:19 +02:00
parent 410eee4a4d
commit dbba4ed671
5 changed files with 43 additions and 28 deletions

2
.gitignore vendored
View File

@ -1,7 +1,7 @@
# generic temporary / dev files
*.pyc
*.sh
*.txt
*.note
*.xcf
nohup.out
/.dev

View File

@ -21,6 +21,7 @@ Also neat: You can use your **custom artist or track images**.
* [waitress](https://docs.pylonsproject.org/projects/waitress/) - [GitHub](https://github.com/Pylons/waitress)
* [doreah](https://pypi.org/project/doreah/) - [GitHub](https://github.com/krateng/doreah) (at least Version 0.7.2)
* [nimrodel](https://pypi.org/project/nimrodel/) - [GitHub](https://github.com/krateng/nimrodel) (at least Version 0.4.4)
* [setproctitle](https://pypi.org/project/setproctitle/) - [GitHub](https://github.com/dvarrazzo/py-setproctitle)
* If you'd like to display images, you will need API keys for [Last.fm](https://www.last.fm/api/account/create) and [Fanart.tv](https://fanart.tv/get-an-api-key/). These are free of charge!
## How to install
@ -29,13 +30,15 @@ Also neat: You can use your **custom artist or track images**.
./maloja install
2) Start the server with
2) Install required packages with
pip3 install -r requirements.txt
3) Start the server with
maloja start
If you're missing packages, the console output will tell you so. Install them.
2) (Recommended) Put your server behind a reverse proxy for SSL encryption.
4) (Recommended) Put your server behind a reverse proxy for SSL encryption.
## How to use

View File

@ -5,53 +5,60 @@ from doreah.settings import get_settings
from doreah.logging import log
apis_artists = [
{
apis_artists = []
if get_settings("LASTFM_API_KEY") not in [None,"ASK"] and get_settings("FANARTTV_API_KEY") not in [None,"ASK"]:
apis_artists.append({
"name":"LastFM + Fanart.tv",
"check":get_settings("LASTFM_API_KEY") not in [None,"ASK"] and get_settings("FANARTTV_API_KEY") not in [None,"ASK"],
#"check":get_settings("LASTFM_API_KEY") not in [None,"ASK"] and get_settings("FANARTTV_API_KEY") not in [None,"ASK"],
"steps":[
("get","http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist={artiststring}&api_key=" + get_settings("LASTFM_API_KEY") + "&format=json"),
("get","http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist={artiststring}&api_key=" + str(get_settings("LASTFM_API_KEY")) + "&format=json"),
("parse",["artist","mbid"]),
("get","http://webservice.fanart.tv/v3/music/{var}?api_key=" + get_settings("FANARTTV_API_KEY")),
("get","http://webservice.fanart.tv/v3/music/{var}?api_key=" + str(get_settings("FANARTTV_API_KEY"))),
("parse",["artistthumb",0,"url"])
]
},
{
})
if get_settings("SPOTIFY_API_ID") not in [None,"ASK"] and get_settings("SPOTIFY_API_SECRET") not in [None,"ASK"]:
apis_artists.append({
"name":"Spotify",
"check":get_settings("SPOTIFY_API_ID") not in [None,"ASK"] and get_settings("SPOTIFY_API_SECRET") not in [None,"ASK"],
#"check":get_settings("SPOTIFY_API_ID") not in [None,"ASK"] and get_settings("SPOTIFY_API_SECRET") not in [None,"ASK"],
"steps":[
("post","https://accounts.spotify.com/api/token",{"Authorization":"Basic " + base64.b64encode(bytes(get_settings("SPOTIFY_API_ID") + ":" + get_settings("SPOTIFY_API_SECRET"),encoding="utf-8")).decode("utf-8")},{"grant_type":"client_credentials"}),
("parse",["access_token"]),
("get","https://api.spotify.com/v1/search?q={artiststring}&type=artist&access_token={var}"),
("parse",["artists","items",0,"images",0,"url"])
]
}
]
})
apis_tracks = [
{
apis_tracks = []
if get_settings("LASTFM_API_KEY") not in [None,"ASK"]:
apis_tracks.append({
"name":"LastFM",
"check":get_settings("LASTFM_API_KEY") not in [None,"ASK"],
#"check":get_settings("LASTFM_API_KEY") not in [None,"ASK"],
"steps":[
("get","https://ws.audioscrobbler.com/2.0/?method=track.getinfo&track={titlestring}&artist={artiststring}&api_key=" + get_settings("LASTFM_API_KEY") + "&format=json"),
("parse",["track","album","image",3,"#text"])
]
},
{
})
if get_settings("SPOTIFY_API_ID") not in [None,"ASK"] and get_settings("SPOTIFY_API_SECRET") not in [None,"ASK"]:
apis_tracks.append({
"name":"Spotify",
"check":get_settings("SPOTIFY_API_ID") not in [None,"ASK"] and get_settings("SPOTIFY_API_SECRET") not in [None,"ASK"],
#"check":get_settings("SPOTIFY_API_ID") not in [None,"ASK"] and get_settings("SPOTIFY_API_SECRET") not in [None,"ASK"],
"steps":[
("post","https://accounts.spotify.com/api/token",{"Authorization":"Basic " + base64.b64encode(bytes(get_settings("SPOTIFY_API_ID") + ":" + get_settings("SPOTIFY_API_SECRET"),encoding="utf-8")).decode("utf-8")},{"grant_type":"client_credentials"}),
("parse",["access_token"]),
("get","https://api.spotify.com/v1/search?q={artiststring}%20{titlestring}&type=track&access_token={var}"),
("parse",["tracks","items",0,"album","images",0,"url"])
]
}
]
})
def api_request_artist(artist):
for api in apis_artists:
if api["check"]:
if True:
log("API: " + api["name"] + "; Image request: " + artist,module="external")
try:
artiststring = urllib.parse.quote(artist)
@ -85,7 +92,7 @@ def api_request_artist(artist):
def api_request_track(track):
artists, title = track
for api in apis_tracks:
if api["check"]:
if True:
log("API: " + api["name"] + "; Image request: " + "/".join(artists) + " - " + title,module="external")
try:
artiststring = urllib.parse.quote(", ".join(artists))

6
maloja
View File

@ -118,10 +118,10 @@ def install():
if toinstall != [] or toinstallr != []:
if os.geteuid() != 0:
print("Installing python modules should be fairly straight-forward, but Maloja can try to install them automatically. For this, you need to run this script as a root user.")
print("You can install them with",yellow("pip install -r requirements.txt"),"or Maloja can try to install them automatically. For this, you need to run this script as a root user.")
return False
else:
print("Installing python modules should be fairly straight-forward, but Maloja can try to install them automatically, This might or might not work / bloat your system / cause a nuclear war.")
print("You can install them with",yellow("pip install -r requirements.txt"),"or Maloja can try to install them automatically, This might or might not work / bloat your system / cause a nuclear war.")
fail = False
if toinstall != []:
print("Attempt to install required modules? [Y/n]")
@ -284,7 +284,7 @@ def update():
os.chmod("./maloja",os.stat("./maloja").st_mode | stat.S_IXUSR)
print("Make sure to install the latest version of doreah! (" + yellow("pip3 install --upgrade --no-cache-dir doreah") + ")")
print("Make sure to update required modules! (" + yellow("pip3 install -r requirements.txt --upgrade --no-cache-dir") + ")")
if stop(): start() #stop returns whether it was running before, in which case we restart it

5
requirements.txt Normal file
View File

@ -0,0 +1,5 @@
bottle>=0.12.16
waitress>=1.3
doreah>=0.7.2
nimrodel>=0.4.4
setproctitle>=1.1.10