mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Added thumbor support
This commit is contained in:
parent
091c86a7ce
commit
c0ecbfb28f
@ -7,7 +7,7 @@ author = {
|
|||||||
"email":"maloja@krateng.dev",
|
"email":"maloja@krateng.dev",
|
||||||
"github": "krateng"
|
"github": "krateng"
|
||||||
}
|
}
|
||||||
version = 2,1,3
|
version = 2,1,4
|
||||||
versionstr = ".".join(str(n) for n in version)
|
versionstr = ".".join(str(n) for n in version)
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ SPOTIFY_API_ID = "ASK"
|
|||||||
SPOTIFY_API_SECRET = "ASK"
|
SPOTIFY_API_SECRET = "ASK"
|
||||||
CACHE_EXPIRE_NEGATIVE = 30 # after how many days negative results should be tried again
|
CACHE_EXPIRE_NEGATIVE = 30 # after how many days negative results should be tried again
|
||||||
CACHE_EXPIRE_POSITIVE = 300 # after how many days positive results should be refreshed
|
CACHE_EXPIRE_POSITIVE = 300 # after how many days positive results should be refreshed
|
||||||
|
THUMBOR_SERVER = None
|
||||||
|
THUMBOR_SECRET = ""
|
||||||
|
|
||||||
# Can be 'YouTube', 'YouTube Music', 'Google Play Music', 'Spotify', 'Tidal', 'SoundCloud', 'Deezer', 'Amazon Music'
|
# Can be 'YouTube', 'YouTube Music', 'Google Play Music', 'Spotify', 'Tidal', 'SoundCloud', 'Deezer', 'Amazon Music'
|
||||||
# Omit or set to none to disable
|
# Omit or set to none to disable
|
||||||
|
13
maloja/globalconf.py
Normal file
13
maloja/globalconf.py
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
from doreah.settings import get_settings
|
||||||
|
|
||||||
|
THUMBOR_SERVER, THUMBOR_SECRET = get_settings("THUMBOR_SERVER","THUMBOR_SECRET")
|
||||||
|
try:
|
||||||
|
USE_THUMBOR = THUMBOR_SERVER is not None and THUMBOR_SECRET is not None
|
||||||
|
if USE_THUMBOR:
|
||||||
|
from libthumbor import CryptoURL
|
||||||
|
THUMBOR_GENERATOR = CryptoURL(key=THUMBOR_SECRET)
|
||||||
|
OWNURL = get_settings("PUBLIC_URL")
|
||||||
|
assert OWNURL is not None
|
||||||
|
except:
|
||||||
|
USE_THUMBOR = False
|
||||||
|
log("Thumbor could not be initialized. Is libthumbor installed?")
|
@ -18,6 +18,7 @@ from . import utilities
|
|||||||
from .utilities import resolveImage
|
from .utilities import resolveImage
|
||||||
from .urihandler import uri_to_internal, remove_identical
|
from .urihandler import uri_to_internal, remove_identical
|
||||||
from . import urihandler
|
from . import urihandler
|
||||||
|
from . import globalconf
|
||||||
# doreah toolkit
|
# doreah toolkit
|
||||||
from doreah import settings
|
from doreah import settings
|
||||||
from doreah.logging import log
|
from doreah.logging import log
|
||||||
@ -120,6 +121,10 @@ def dynamic_image():
|
|||||||
@webserver.route("/images/<pth:re:.*\\.png>")
|
@webserver.route("/images/<pth:re:.*\\.png>")
|
||||||
@webserver.route("/images/<pth:re:.*\\.gif>")
|
@webserver.route("/images/<pth:re:.*\\.gif>")
|
||||||
def static_image(pth):
|
def static_image(pth):
|
||||||
|
if globalconf.USE_THUMBOR:
|
||||||
|
return static_file("images/" + pth,root="")
|
||||||
|
|
||||||
|
type = pth.split(".")[-1]
|
||||||
small_pth = pth + "-small"
|
small_pth = pth + "-small"
|
||||||
if os.path.exists("images/" + small_pth):
|
if os.path.exists("images/" + small_pth):
|
||||||
response = static_file("images/" + small_pth,root="")
|
response = static_file("images/" + small_pth,root="")
|
||||||
@ -141,6 +146,7 @@ def static_image(pth):
|
|||||||
|
|
||||||
#response = static_file("images/" + pth,root="")
|
#response = static_file("images/" + pth,root="")
|
||||||
response.set_header("Cache-Control", "public, max-age=86400")
|
response.set_header("Cache-Control", "public, max-age=86400")
|
||||||
|
response.set_header("Content-Type", "image/" + type)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ from doreah.regular import yearly, daily
|
|||||||
|
|
||||||
from .external import api_request_track, api_request_artist
|
from .external import api_request_track, api_request_artist
|
||||||
from .__init__ import version
|
from .__init__ import version
|
||||||
|
from . import globalconf
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -126,10 +127,20 @@ def consistentRulestate(folder,checksums):
|
|||||||
#####
|
#####
|
||||||
|
|
||||||
|
|
||||||
|
if globalconf.USE_THUMBOR:
|
||||||
|
def thumborize(url):
|
||||||
|
if url.startswith("/"): url = globalconf.OWNURL + url
|
||||||
|
encrypted_url = globalconf.THUMBOR_GENERATOR.generate(
|
||||||
|
width=300,
|
||||||
|
height=300,
|
||||||
|
smart=True,
|
||||||
|
image_url=url
|
||||||
|
)
|
||||||
|
return globalconf.THUMBOR_SERVER + encrypted_url
|
||||||
|
|
||||||
|
else:
|
||||||
|
def thumborize(url):
|
||||||
|
return url
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -297,7 +308,7 @@ def getArtistImage(artist,fast=False):
|
|||||||
if settings.get_settings("USE_LOCAL_IMAGES"):
|
if settings.get_settings("USE_LOCAL_IMAGES"):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return local_artist_cache.get(artist)
|
return thumborize(local_artist_cache.get(artist))
|
||||||
# Local cached image
|
# Local cached image
|
||||||
except:
|
except:
|
||||||
# Get all local images, select one if present
|
# Get all local images, select one if present
|
||||||
@ -306,14 +317,14 @@ def getArtistImage(artist,fast=False):
|
|||||||
#return random.choice(images)
|
#return random.choice(images)
|
||||||
res = random.choice(images)
|
res = random.choice(images)
|
||||||
local_artist_cache.add(artist,res)
|
local_artist_cache.add(artist,res)
|
||||||
return urllib.parse.quote(res)
|
return thumborize(urllib.parse.quote(res))
|
||||||
|
|
||||||
|
|
||||||
# if no local images (or setting to not use them)
|
# if no local images (or setting to not use them)
|
||||||
try:
|
try:
|
||||||
# check cache for foreign image
|
# check cache for foreign image
|
||||||
result = artist_cache.get(artist)
|
result = artist_cache.get(artist)
|
||||||
if result is not None: return result
|
if result is not None: return thumborize(result)
|
||||||
else: return ""
|
else: return ""
|
||||||
# none means non-existence is cached, return empty
|
# none means non-existence is cached, return empty
|
||||||
except:
|
except:
|
||||||
@ -337,7 +348,7 @@ def getArtistImage(artist,fast=False):
|
|||||||
#cachedArtists[artist] = result
|
#cachedArtists[artist] = result
|
||||||
artist_cache.add(artist,result) #cache_artist(artist,result)
|
artist_cache.add(artist,result) #cache_artist(artist,result)
|
||||||
|
|
||||||
if result is not None: return result
|
if result is not None: return thumborize(result)
|
||||||
else: return ""
|
else: return ""
|
||||||
|
|
||||||
def getTrackImages(trackobjectlist,fast=False):
|
def getTrackImages(trackobjectlist,fast=False):
|
||||||
|
Loading…
Reference in New Issue
Block a user