mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-12 21:22:17 +00:00
Factor in index construction
This commit is contained in:
parent
65a7131c05
commit
bc373e595f
@ -49,6 +49,27 @@ def ignored_articles_str():
|
|||||||
return " ".join(articles.split())
|
return " ".join(articles.split())
|
||||||
|
|
||||||
|
|
||||||
|
def build_indexes(source):
|
||||||
|
indexes = {}
|
||||||
|
pattern = build_ignored_articles_pattern()
|
||||||
|
for item in source:
|
||||||
|
name = item.name
|
||||||
|
if pattern:
|
||||||
|
name = re.sub(pattern, "", name, flags=re.I)
|
||||||
|
index = name[0].upper()
|
||||||
|
if index in string.digits:
|
||||||
|
index = "#"
|
||||||
|
elif index not in string.ascii_letters:
|
||||||
|
index = "?"
|
||||||
|
|
||||||
|
if index not in indexes:
|
||||||
|
indexes[index] = []
|
||||||
|
|
||||||
|
indexes[index].append((item, name))
|
||||||
|
|
||||||
|
return indexes
|
||||||
|
|
||||||
|
|
||||||
@api_routing("/getIndexes")
|
@api_routing("/getIndexes")
|
||||||
def list_indexes():
|
def list_indexes():
|
||||||
musicFolderId = request.values.get("musicFolderId")
|
musicFolderId = request.values.get("musicFolderId")
|
||||||
@ -83,23 +104,7 @@ def list_indexes():
|
|||||||
artists += f.children.select()[:]
|
artists += f.children.select()[:]
|
||||||
children += f.tracks.select()[:]
|
children += f.tracks.select()[:]
|
||||||
|
|
||||||
indexes = {}
|
indexes = build_indexes(artists)
|
||||||
pattern = build_ignored_articles_pattern()
|
|
||||||
for artist in artists:
|
|
||||||
name = artist.name
|
|
||||||
if pattern:
|
|
||||||
name = re.sub(pattern, "", name, flags=re.I)
|
|
||||||
index = name[0].upper()
|
|
||||||
if index in string.digits:
|
|
||||||
index = "#"
|
|
||||||
elif index not in string.ascii_letters:
|
|
||||||
index = "?"
|
|
||||||
|
|
||||||
if index not in indexes:
|
|
||||||
indexes[index] = []
|
|
||||||
|
|
||||||
indexes[index].append((artist, name))
|
|
||||||
|
|
||||||
return request.formatter(
|
return request.formatter(
|
||||||
"indexes",
|
"indexes",
|
||||||
{
|
{
|
||||||
@ -149,23 +154,7 @@ def list_genres():
|
|||||||
@api_routing("/getArtists")
|
@api_routing("/getArtists")
|
||||||
def list_artists():
|
def list_artists():
|
||||||
# According to the API page, there are no parameters?
|
# According to the API page, there are no parameters?
|
||||||
indexes = {}
|
indexes = build_indexes(Artist.select())
|
||||||
pattern = build_ignored_articles_pattern()
|
|
||||||
for artist in Artist.select():
|
|
||||||
name = artist.name or "?"
|
|
||||||
if pattern:
|
|
||||||
name = re.sub(pattern, "", name, flags=re.I)
|
|
||||||
index = name[0].upper()
|
|
||||||
if index in string.digits:
|
|
||||||
index = "#"
|
|
||||||
elif index not in string.ascii_letters:
|
|
||||||
index = "?"
|
|
||||||
|
|
||||||
if index not in indexes:
|
|
||||||
indexes[index] = []
|
|
||||||
|
|
||||||
indexes[index].append((artist, name))
|
|
||||||
|
|
||||||
return request.formatter(
|
return request.formatter(
|
||||||
"artists",
|
"artists",
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user