From 9f8e6919247357cfafed085088ebc6ad00312359 Mon Sep 17 00:00:00 2001 From: krateng Date: Sun, 27 Mar 2022 20:08:41 +0200 Subject: [PATCH] Moved image handling to top level module --- README.md | 1 - maloja/apis/native_v1.py | 4 ++-- maloja/cleanup.py | 2 +- maloja/database/__init__.py | 2 +- maloja/globalconf.py | 7 +++++-- maloja/{utilities => }/images.py | 6 +++--- maloja/jinjaenv/context.py | 4 ++-- maloja/proccontrol/tasks/import_scrobbles.py | 2 +- maloja/server.py | 2 +- maloja/utilities/__init__.py | 1 - maloja/web/jinja/artist.jinja | 4 ++-- maloja/web/jinja/charts_artists.jinja | 2 +- maloja/web/jinja/charts_tracks.jinja | 2 +- maloja/web/jinja/partials/charts_artists_tiles.jinja | 2 +- maloja/web/jinja/partials/charts_tracks_tiles.jinja | 2 +- maloja/web/jinja/performance.jinja | 4 ++-- maloja/web/jinja/pulse.jinja | 4 ++-- maloja/web/jinja/scrobbles.jinja | 6 +++--- maloja/web/jinja/snippets/entityrow.jinja | 4 ++-- maloja/web/jinja/top_artists.jinja | 2 +- maloja/web/jinja/top_tracks.jinja | 2 +- maloja/web/jinja/track.jinja | 4 ++-- 22 files changed, 35 insertions(+), 34 deletions(-) rename maloja/{utilities => }/images.py (98%) delete mode 100644 maloja/utilities/__init__.py diff --git a/README.md b/README.md index 6a82797..f90742f 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,6 @@ These solutions allow you to directly setup scrobbling to your Maloja server: * [Multi Scrobbler](https://github.com/FoxxMD/multi-scrobbler) Desktop Application * [Cmus-maloja-scrobbler](https://git.sr.ht/~xyank/cmus-maloja-scrobbler) Script * [OngakuKiroku](https://github.com/Atelier-Shiori/OngakuKiroku) Desktop Application (Mac) -* [Albula](https://github.com/krateng/albula) Music Server * [Maloja Scrobbler](https://chrome.google.com/webstore/detail/maloja-scrobbler/cfnbifdmgbnaalphodcbandoopgbfeeh) Chromium Extension (also included in the repository) for Plex Web, Spotify, Bandcamp, Soundcloud or Youtube Music ### Native API diff --git a/maloja/apis/native_v1.py b/maloja/apis/native_v1.py index d554731..4a53219 100644 --- a/maloja/apis/native_v1.py +++ b/maloja/apis/native_v1.py @@ -17,7 +17,7 @@ from ..globalconf import malojaconfig, data_dir from ..__pkginfo__ import VERSION from ..malojauri import uri_to_internal, compose_querystring, internal_to_uri -from .. import utilities +from .. import images from ._apikeys import api_key_correct, checkAPIkey from . import apikeystore @@ -343,7 +343,7 @@ def add_picture(b64,artist:Multi=[],title=None): if title is not None: keys.append("title",title) k_filter, _, _, _, _ = uri_to_internal(keys) if "track" in k_filter: k_filter = k_filter["track"] - utilities.set_image(b64,**k_filter) + images.set_image(b64,**k_filter) @api.post("newrule") diff --git a/maloja/cleanup.py b/maloja/cleanup.py index ff313f9..18420ea 100644 --- a/maloja/cleanup.py +++ b/maloja/cleanup.py @@ -1,5 +1,5 @@ import re -#from . import utilities +#from . import images from doreah import tsv from .globalconf import data_dir, malojaconfig diff --git a/maloja/database/__init__.py b/maloja/database/__init__.py index 41d1e26..dbd4211 100644 --- a/maloja/database/__init__.py +++ b/maloja/database/__init__.py @@ -3,7 +3,7 @@ from bottle import request, response, FormsDict, HTTPError # rest of the project from ..cleanup import CleanerAgent, CollectorAgent -from .. import utilities +from .. import images from ..malojatime import register_scrobbletime, time_stamps, ranges, alltime from ..malojauri import uri_to_internal, internal_to_uri, compose_querystring from ..thirdparty import proxy_scrobble_all diff --git a/maloja/globalconf.py b/maloja/globalconf.py index 895944d..135da01 100644 --- a/maloja/globalconf.py +++ b/maloja/globalconf.py @@ -272,8 +272,11 @@ data_directories = { "clients":pthj(dir_settings['config']), "settings":pthj(dir_settings['config']), "css":pthj(dir_settings['config'],"custom_css"), - "logs":pthj(dir_settings['logs']), - "cache":pthj(dir_settings['cache']), + + "config":dir_settings['config'], + "state":dir_settings['state'], + "logs":dir_settings['logs'], + "cache":dir_settings['cache'], } diff --git a/maloja/utilities/images.py b/maloja/images.py similarity index 98% rename from maloja/utilities/images.py rename to maloja/images.py index d0603a0..bb39ac7 100644 --- a/maloja/utilities/images.py +++ b/maloja/images.py @@ -1,6 +1,6 @@ -from ..globalconf import data_dir, malojaconfig -from .. import thirdparty -from .. import database +from .globalconf import data_dir, malojaconfig +from . import thirdparty +from . import database from doreah import caching from doreah.logging import log diff --git a/maloja/jinjaenv/context.py b/maloja/jinjaenv/context.py index 08e38f7..b818dde 100644 --- a/maloja/jinjaenv/context.py +++ b/maloja/jinjaenv/context.py @@ -1,7 +1,7 @@ from . import filters from ..globalconf import malojaconfig -from .. import database, malojatime, utilities, malojauri, thirdparty, __pkginfo__ +from .. import database, malojatime, images, malojauri, thirdparty, __pkginfo__ from ..database import jinjaview from doreah.regular import repeatdaily @@ -28,7 +28,7 @@ def update_jinja_environment(): "db": database, #TODO: move these to connection manager as well #"dbp":dbp, "malojatime": malojatime, - "utilities": utilities, + "images": images, "mlj_uri": malojauri, "settings": malojaconfig, "thirdparty": thirdparty, diff --git a/maloja/proccontrol/tasks/import_scrobbles.py b/maloja/proccontrol/tasks/import_scrobbles.py index 7a9a2a2..8520e1c 100644 --- a/maloja/proccontrol/tasks/import_scrobbles.py +++ b/maloja/proccontrol/tasks/import_scrobbles.py @@ -7,7 +7,7 @@ from doreah.io import col, ask from ...globalconf import data_dir from ...database.sqldb import add_scrobbles -#from ...utilities import * +#from ...images import * diff --git a/maloja/server.py b/maloja/server.py index 7eaaf03..2a16cff 100644 --- a/maloja/server.py +++ b/maloja/server.py @@ -19,7 +19,7 @@ from doreah import auth # rest of the project from . import database from .database.jinjaview import JinjaDBConnection -from .utilities import resolve_track_image, resolve_artist_image +from .images import resolve_track_image, resolve_artist_image from .malojauri import uri_to_internal, remove_identical from .globalconf import malojaconfig, data_dir from .jinjaenv.context import jinja_environment diff --git a/maloja/utilities/__init__.py b/maloja/utilities/__init__.py deleted file mode 100644 index a3bce12..0000000 --- a/maloja/utilities/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .images import * diff --git a/maloja/web/jinja/artist.jinja b/maloja/web/jinja/artist.jinja index 10439d7..f738c8b 100644 --- a/maloja/web/jinja/artist.jinja +++ b/maloja/web/jinja/artist.jinja @@ -39,10 +39,10 @@ {% if adminmode %}
{% else %} -
+
{% endif %} diff --git a/maloja/web/jinja/charts_artists.jinja b/maloja/web/jinja/charts_artists.jinja index df50007..87f51ff 100644 --- a/maloja/web/jinja/charts_artists.jinja +++ b/maloja/web/jinja/charts_artists.jinja @@ -9,7 +9,7 @@ {% set pages = math.ceil(charts.__len__() / amountkeys.perpage) %} {% if charts[0] is defined %} {% set topartist = charts[0].artist %} - {% set img = utilities.get_artist_image(topartist) %} + {% set img = images.get_artist_image(topartist) %} {% else %} {% set img = "/favicon.png" %} {% endif %} diff --git a/maloja/web/jinja/charts_tracks.jinja b/maloja/web/jinja/charts_tracks.jinja index 84339c2..17b2f20 100644 --- a/maloja/web/jinja/charts_tracks.jinja +++ b/maloja/web/jinja/charts_tracks.jinja @@ -11,7 +11,7 @@ {% set pages = math.ceil(charts.__len__() / amountkeys.perpage) %} {% if charts[0] is defined %} {% set toptrack = charts[0].track %} - {% set img = utilities.get_track_image(toptrack) %} + {% set img = images.get_track_image(toptrack) %} {% else %} {% set img = "/favicon.png" %} {% endif %} diff --git a/maloja/web/jinja/partials/charts_artists_tiles.jinja b/maloja/web/jinja/partials/charts_artists_tiles.jinja index 502c29f..78599ab 100644 --- a/maloja/web/jinja/partials/charts_artists_tiles.jinja +++ b/maloja/web/jinja/partials/charts_artists_tiles.jinja @@ -23,7 +23,7 @@ {% set rank = entry.rank %} -
+
#{{ rank }} {{ artist }}
diff --git a/maloja/web/jinja/partials/charts_tracks_tiles.jinja b/maloja/web/jinja/partials/charts_tracks_tiles.jinja index 87c754a..6d597e7 100644 --- a/maloja/web/jinja/partials/charts_tracks_tiles.jinja +++ b/maloja/web/jinja/partials/charts_tracks_tiles.jinja @@ -23,7 +23,7 @@ {% set rank = entry.rank %} -
+
#{{ rank }} {{ track.title }}
diff --git a/maloja/web/jinja/performance.jinja b/maloja/web/jinja/performance.jinja index 27aaf66..5ab281d 100644 --- a/maloja/web/jinja/performance.jinja +++ b/maloja/web/jinja/performance.jinja @@ -4,9 +4,9 @@ {% import 'snippets/filterdescription.jinja' as filterdesc %} {% if filterkeys.get('track') is not none %} - {% set img = utilities.get_track_image(filterkeys.track) %} + {% set img = images.get_track_image(filterkeys.track) %} {% elif filterkeys.get('artist') is not none %} - {% set img = utilities.get_artist_image(filterkeys.artist) %} + {% set img = images.get_artist_image(filterkeys.artist) %} {% else %} {% set img = "/favicon.png" %} {% endif %} diff --git a/maloja/web/jinja/pulse.jinja b/maloja/web/jinja/pulse.jinja index f556753..79df94a 100644 --- a/maloja/web/jinja/pulse.jinja +++ b/maloja/web/jinja/pulse.jinja @@ -4,9 +4,9 @@ {% import 'snippets/filterdescription.jinja' as filterdesc %} {% if filterkeys.get('track') is not none %} - {% set img = utilities.get_track_image(filterkeys.track) %} + {% set img = images.get_track_image(filterkeys.track) %} {% elif filterkeys.get('artist') is not none %} - {% set img = utilities.get_artist_image(filterkeys.artist) %} + {% set img = images.get_artist_image(filterkeys.artist) %} {% else %} {% set img = "/favicon.png" %} {% endif %} diff --git a/maloja/web/jinja/scrobbles.jinja b/maloja/web/jinja/scrobbles.jinja index 00df8cc..0331bb9 100644 --- a/maloja/web/jinja/scrobbles.jinja +++ b/maloja/web/jinja/scrobbles.jinja @@ -8,11 +8,11 @@ {% set pages = math.ceil(scrobbles.__len__() / amountkeys.perpage) %} {% if filterkeys.get('track') is not none %} - {% set img = utilities.get_track_image(filterkeys.track) %} + {% set img = images.get_track_image(filterkeys.track) %} {% elif filterkeys.get('artist') is not none %} - {% set img = utilities.get_artist_image(filterkeys.artist) %} + {% set img = images.get_artist_image(filterkeys.artist) %} {% elif scrobbles.__len__() > 0 %} - {% set img = utilities.get_track_image(scrobbles[0].track) %} + {% set img = images.get_track_image(scrobbles[0].track) %} {% else %} {% set img = "/favicon.png" %} {% endif %} diff --git a/maloja/web/jinja/snippets/entityrow.jinja b/maloja/web/jinja/snippets/entityrow.jinja index d8e866f..e44f7fd 100644 --- a/maloja/web/jinja/snippets/entityrow.jinja +++ b/maloja/web/jinja/snippets/entityrow.jinja @@ -3,9 +3,9 @@ {% import 'snippets/links.jinja' as links %} {% if 'artists' in entity %} - {% set img = utilities.get_track_image(entity) %} + {% set img = images.get_track_image(entity) %} {% else %} - {% set img = utilities.get_artist_image(entity) %} + {% set img = images.get_artist_image(entity) %} {% endif %}
diff --git a/maloja/web/jinja/top_artists.jinja b/maloja/web/jinja/top_artists.jinja index d696093..175d213 100644 --- a/maloja/web/jinja/top_artists.jinja +++ b/maloja/web/jinja/top_artists.jinja @@ -6,7 +6,7 @@ {% set entries = dbc.get_top_artists(limitkeys,delimitkeys) %} {% set repr = entries | find_representative('artist','scrobbles') %} -{% set img = "/favicon.png" if repr is none else utilities.get_artist_image(repr.artist) %} +{% set img = "/favicon.png" if repr is none else images.get_artist_image(repr.artist) %} {% block content %} diff --git a/maloja/web/jinja/top_tracks.jinja b/maloja/web/jinja/top_tracks.jinja index cc867f7..42ae78d 100644 --- a/maloja/web/jinja/top_tracks.jinja +++ b/maloja/web/jinja/top_tracks.jinja @@ -6,7 +6,7 @@ {% set entries = dbc.get_top_tracks(filterkeys,limitkeys,delimitkeys) %} {% set repr = entries | find_representative('track','scrobbles') %} -{% set img = "/favicon.png" if repr is none else utilities.get_track_image(repr.track) %} +{% set img = "/favicon.png" if repr is none else images.get_track_image(repr.track) %} {% block content %} diff --git a/maloja/web/jinja/track.jinja b/maloja/web/jinja/track.jinja index b2681e6..03762c6 100644 --- a/maloja/web/jinja/track.jinja +++ b/maloja/web/jinja/track.jinja @@ -33,10 +33,10 @@ {% if adminmode %}
{% else %} -
+
{% endif %}