Browse Source

Simplifying normalization of strings used to sort songs

pull/47/head
Louis 11 years ago
parent
commit
e87c6d4d3f
  1. 18
      songbook_core/content/sorted.py
  2. 2
      songbook_core/index.py
  3. 18
      songbook_core/songs.py

18
songbook_core/content/sorted.py

@ -7,18 +7,28 @@ from songbook_core.content.song import OnlySongsError, process_songs
DEFAULT_SORT = ['by', 'album', '@title']
def normalize_string(string):
return locale.strxfrm(string.lower().strip())
def normalize_field(field):
if isinstance(field, basestring):
return normalize_string(field)
elif isinstance(field, list):
return [normalize_string(string) for string in field]
def key_generator(sort):
def ordered_song_keys(song):
songkey = []
for key in sort:
if key == "@title":
songkey.append(song.normalized_titles)
field = song.unprefixed_titles
elif key == "@path":
songkey.append(locale.strxfrm(song.path))
field = song.path
elif key == "by":
songkey.append(song.normalized_authors)
field = song.authors
else:
songkey.append(locale.strxfrm(song.args.get(key, "")))
field = song.args.get(key, "")
songkey.append(normalize_field(field))
return songkey
return ordered_song_keys

2
songbook_core/index.py

@ -30,7 +30,7 @@ def sortkey(value):
don't forget to call locale.setlocale(locale.LC_ALL, '')). It also handles
the sort with latex escape sequences.
"""
return locale.strxfrm(unidecode(simpleparse(value).replace(' ', 'A')))
return locale.strxfrm(unidecode(simpleparse(value).replace(' ', 'A')).lower())
def process_sxd(filename):

18
songbook_core/songs.py

@ -18,12 +18,10 @@ class Song(object):
# Data extraction from the song with plastex
data = parsetex(filename)
self.titles = data['titles']
self.normalized_titles = [
locale.strxfrm(
unprefixed_title(
unidecode(unicode(title, "utf-8")),
config['titleprefixwords']
)
self.unprefixed_titles = [
unprefixed_title(
unidecode(unicode(title, "utf-8")),
config['titleprefixwords']
)
for title
in self.titles
@ -32,13 +30,9 @@ class Song(object):
self.path = filename
self.languages = data['languages']
if "by" in self.args.keys():
self.normalized_authors = [
locale.strxfrm(author)
for author
in processauthors(self.args["by"], **config["authwords"])
]
self.authors = processauthors(self.args["by"], **config["authwords"])
else:
self.normalized_authors = []
self.authors = []
def __repr__(self):
return repr((self.titles, self.args, self.path))

Loading…
Cancel
Save