diff --git a/.gitignore b/.gitignore index 5db2268..50cc9d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # generic temporary / dev files *.pyc *.sh -*.txt +*.note *.xcf nohup.out /.dev diff --git a/README.md b/README.md index dd589c7..a9e75af 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/external.py b/external.py index eac30e5..c9c51fc 100644 --- a/external.py +++ b/external.py @@ -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)) diff --git a/maloja b/maloja index 0b3bf09..5fc9eab 100755 --- a/maloja +++ b/maloja @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b92a000 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,5 @@ +bottle>=0.12.16 +waitress>=1.3 +doreah>=0.7.2 +nimrodel>=0.4.4 +setproctitle>=1.1.10