mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
More leniency on image filenames
This commit is contained in:
parent
4d96500644
commit
a7963ee679
@ -3,42 +3,41 @@ don't like the ones provided by Last.FM, you don't want to use Last.FM or it's
|
||||
missing some artists / tracks that are important to you.
|
||||
|
||||
For artists, you can use a .jpg, .jpeg, .png or .gif image that is named like
|
||||
the artist, but without whitespace and non-latin-alphabet characters (plus
|
||||
extension). In case you want to have multiple images of the same format, you may
|
||||
add any number from 0-9 to the name. If you need more images than that, create a
|
||||
folder named like the artist and add any images inside. So, for example, if your
|
||||
artist is "Dal★Shabet", all these files would be considered:
|
||||
the artist, but with all non-alphanumeric characters removed. You may also chose
|
||||
the safe route and omit everything but numbers and latin characters (except the
|
||||
dot separating the name and the extension). You can either capitalize exactly as
|
||||
the title or use only lower case, but not use arbitrary capizalization. In case
|
||||
you want to have multiple images of the same format, you may create a folder
|
||||
named like the artist and add any images inside. So, for example, if your artist
|
||||
is "Dal★Shabet", all these files would be considered:
|
||||
|
||||
DalShabet.jpg
|
||||
DalShabet4.png
|
||||
DalShabet0.gif
|
||||
dalshabet.png
|
||||
DalShabet/bestimage.jpeg
|
||||
DalShabet/serri_only.png
|
||||
dalshabet/serri_only.png
|
||||
|
||||
The following files would not be considered:
|
||||
|
||||
Dal Shabet.gif (Whitespace)
|
||||
Dal★Shabet.png (non-latin character)
|
||||
Dal★Shabet.png (non-alphanumeric character)
|
||||
Dalshabet.gif (wrong capitalization)
|
||||
DalShabet.webm (wrong extension)
|
||||
DalShabet23.jpg (to digit number)
|
||||
DalShabet/SomeoneLikeU_MV.mp4 (wrong extension)
|
||||
DalShabet3/party.png (wrong folder name)
|
||||
Dal★Shabet/party.png (non-alphanumeric character in folder)
|
||||
|
||||
|
||||
|
||||
The same concept applies to tracks, however their name consists of all artists in
|
||||
alphabetical order joined by a dash (-), then an underscore (_) and the track
|
||||
title. Rules as above apply, so if your track was named "Epic Crossover 파티 협동"
|
||||
and it was performed by HyunA, Dal★Shabet and Taylor Swift, the following files
|
||||
would be considered:
|
||||
The same concept applies to tracks, however their name consists of all artists
|
||||
joined by a dash (-), then an underscore (_) and the track title. Artists should
|
||||
be joined in alphabetical order, but filenames with the wrong order might still
|
||||
work for a low artist number. Rules as above apply, so if your track was named
|
||||
"Epic Crossover 파티 협동" and it was performed by HyunA, Dal★Shabet and Taylor
|
||||
Swift, the following files would be considered:
|
||||
|
||||
DalShabet-HyunA-TaylorSwift_EpicCrossover.jpg
|
||||
DalShabet-HyunA-TaylorSwift_EpicCrossover3.png
|
||||
DalShabet-HyunA-TaylorSwift_EpicCrossover/albumcover.png
|
||||
DalShabet-HyunA-TaylorSwift_EpicCrossover/dancing.gif
|
||||
DalShabet-TaylorSwift-HyunA_EpicCrossover파티협동.png
|
||||
dalshabet-hyuna-taylorswift_epiccrossover/albumcover.png
|
||||
DalShabet-HyunA-TaylorSwift_EpicCrossover파티협동/dancing.gif
|
||||
|
||||
Not accepted would be:
|
||||
|
||||
DalShabet-HyunA-Taylor Swift_EpicCrossover.jpg (Whitespace)
|
||||
DalShabet-HyunA-TaylorSwift_EpicCrossover파티협동.jpg (non-latin characters)
|
||||
HyunA-DalShabet-TaylorSwift_EpicCrossover.jpg (wrong artist order)
|
||||
DalShabet-HyunA-Taylor Swift_epiccrossover.jpg (wrong capitalization)
|
||||
|
@ -155,7 +155,9 @@ def static_html(name):
|
||||
|
||||
# add headers for server push
|
||||
for resource in resources:
|
||||
linkheaders.append("<" + resource["file"] + ">; rel=preload; as=" + resource["type"])
|
||||
if all(ord(c) < 128 for c in resource["file"]):
|
||||
# we can only put ascii stuff in the http header
|
||||
linkheaders.append("<" + resource["file"] + ">; rel=preload; as=" + resource["type"])
|
||||
|
||||
# apply key substitutions
|
||||
for k in txt_keys:
|
||||
|
125
utilities.py
125
utilities.py
@ -6,6 +6,7 @@ import pickle
|
||||
import urllib
|
||||
import datetime
|
||||
import random
|
||||
import itertools
|
||||
from doreah import settings
|
||||
from doreah import caching
|
||||
from doreah.logging import log
|
||||
@ -155,6 +156,89 @@ artist_cache = caching.Cache.create(name="artist_cache",maxage=cacheage,maxage_n
|
||||
track_cache = caching.Cache.create(name="track_cache",maxage=cacheage,maxage_negative=cacheage_neg)
|
||||
|
||||
|
||||
# removes emojis and weird shit from names
|
||||
def clean(name):
|
||||
return "".join(c for c in name if c.isalnum() or c in []).strip()
|
||||
|
||||
def local_files(artist=None,artists=None,title=None):
|
||||
|
||||
# check if we're dealing with a track or artist, then clean up names
|
||||
# (only remove non-alphanumeric, allow korean and stuff)
|
||||
if title is not None and artists is not None:
|
||||
track = True
|
||||
title, artists = clean(title), [clean(a) for a in artists]
|
||||
elif artist is not None:
|
||||
track = False
|
||||
artist = clean(artist)
|
||||
else: return []
|
||||
|
||||
|
||||
superfolder = "images/tracks/" if track else "images/artists/"
|
||||
|
||||
filenames = []
|
||||
|
||||
if track:
|
||||
#unsafeartists = [artist.translate(None,"-_./\\") for artist in artists]
|
||||
safeartists = [re.sub("[^a-zA-Z0-9]","",artist) for artist in artists]
|
||||
#unsafetitle = title.translate(None,"-_./\\")
|
||||
safetitle = re.sub("[^a-zA-Z0-9]","",title)
|
||||
|
||||
if len(artists) < 4:
|
||||
unsafeperms = itertools.permutations(artists)
|
||||
safeperms = itertools.permutations(safeartists)
|
||||
else:
|
||||
unsafeperms = [sorted(artists)]
|
||||
safeperms = [sorted(safeartists)]
|
||||
|
||||
|
||||
for unsafeartistlist in unsafeperms:
|
||||
filename = "-".join(unsafeartistlist) + "_" + title
|
||||
if filename != "":
|
||||
filenames.append(filename)
|
||||
filenames.append(filename.lower())
|
||||
for safeartistlist in safeperms:
|
||||
filename = "-".join(safeartistlist) + "_" + safetitle
|
||||
if filename != "":
|
||||
filenames.append(filename)
|
||||
filenames.append(filename.lower())
|
||||
filenames = list(set(filenames))
|
||||
if len(filenames) == 0: filenames.append(str(hash((frozenset(artists),title))))
|
||||
else:
|
||||
#unsafeartist = artist.translate(None,"-_./\\")
|
||||
safeartist = re.sub("[^a-zA-Z0-9]","",artist)
|
||||
|
||||
filename = artist
|
||||
if filename != "":
|
||||
filenames.append(filename)
|
||||
filenames.append(filename.lower())
|
||||
filename = safeartist
|
||||
if filename != "":
|
||||
filenames.append(filename)
|
||||
filenames.append(filename.lower())
|
||||
|
||||
filenames = list(set(filenames))
|
||||
if len(filenames) == 0: filenames.append(str(hash(artist)))
|
||||
|
||||
images = []
|
||||
|
||||
for purename in filenames:
|
||||
# direct files
|
||||
for ext in ["png","jpg","jpeg","gif"]:
|
||||
#for num in [""] + [str(n) for n in range(0,10)]:
|
||||
if os.path.exists(superfolder + purename + "." + ext):
|
||||
images.append("/" + superfolder + purename + "." + ext)
|
||||
|
||||
# folder
|
||||
try:
|
||||
for f in os.listdir(superfolder + purename + "/"):
|
||||
if f.split(".")[-1] in ["png","jpg","jpeg","gif"]:
|
||||
images.append("/" + superfolder + purename + "/" + f)
|
||||
except:
|
||||
pass
|
||||
|
||||
return images
|
||||
|
||||
|
||||
|
||||
|
||||
def getTrackImage(artists,title,fast=False):
|
||||
@ -164,24 +248,11 @@ def getTrackImage(artists,title,fast=False):
|
||||
if filename == "": filename = str(hash(obj))
|
||||
filepath = "images/tracks/" + filename
|
||||
|
||||
images = []
|
||||
|
||||
# add all images named like the tracks
|
||||
for ext in ["png","jpg","jpeg","gif"]:
|
||||
for num in [""] + [str(n) for n in range(0,10)]:
|
||||
if os.path.exists(filepath + num + "." + ext):
|
||||
images.append("/" + filepath + num + "." + ext)
|
||||
|
||||
# add images in a folder for that track
|
||||
try:
|
||||
for f in os.listdir(filepath + "/"):
|
||||
if f.split(".")[-1] in ["png","jpg","jpeg","gif"]:
|
||||
images.append("/" + filepath + "/" + f)
|
||||
except:
|
||||
pass
|
||||
|
||||
images = local_files(artists=artists,title=title)
|
||||
if len(images) != 0:
|
||||
return random.choice(images)
|
||||
#return random.choice(images)
|
||||
return urllib.parse.quote(random.choice(images))
|
||||
|
||||
|
||||
# check if custom image exists
|
||||
# if os.path.exists(filepath + ".png"):
|
||||
@ -246,24 +317,10 @@ def getArtistImage(artist,fast=False):
|
||||
filepath = "images/artists/" + filename
|
||||
#filepath_cache = "info/artists_cache/" + filename
|
||||
|
||||
images = []
|
||||
|
||||
# add all images named like the artist
|
||||
for ext in ["png","jpg","jpeg","gif"]:
|
||||
for num in [""] + [str(n) for n in range(0,10)]:
|
||||
if os.path.exists(filepath + num + "." + ext):
|
||||
images.append("/" + filepath + num + "." + ext)
|
||||
|
||||
# add images in a folder for that artist
|
||||
try:
|
||||
for f in os.listdir(filepath + "/"):
|
||||
if f.split(".")[-1] in ["png","jpg","jpeg","gif"]:
|
||||
images.append("/" + filepath + "/" + f)
|
||||
except:
|
||||
pass
|
||||
|
||||
images = local_files(artist=artist)
|
||||
if len(images) != 0:
|
||||
return random.choice(images)
|
||||
#return random.choice(images)
|
||||
return urllib.parse.quote(random.choice(images))
|
||||
|
||||
# check if custom image exists
|
||||
# if os.path.exists(filepath + ".png"):
|
||||
|
Loading…
Reference in New Issue
Block a user