mirror of
https://github.com/beetbox/beets.git
synced 2025-12-29 20:12:33 +01:00
sort by sort names
This commit is contained in:
parent
12998de8ee
commit
3c4d8500e5
2 changed files with 15 additions and 3 deletions
|
|
@ -118,6 +118,15 @@ log = logging.getLogger('beets')
|
|||
if not log.handlers:
|
||||
log.addHandler(logging.StreamHandler())
|
||||
|
||||
# A little SQL utility.
|
||||
def _orelse(exp1, exp2):
|
||||
"""Generates an SQLite expression that evaluates to exp1 if exp1 is
|
||||
non-null and non-empty or exp2 otherwise.
|
||||
"""
|
||||
return ('(CASE {0} WHEN NULL THEN {1} '
|
||||
'WHEN "" THEN {1} '
|
||||
'ELSE {0} END)').format(exp1, exp2)
|
||||
|
||||
|
||||
# Exceptions.
|
||||
|
||||
|
|
@ -1042,7 +1051,8 @@ class Library(BaseLibrary):
|
|||
where, subvals = query.clause()
|
||||
sql = "SELECT * FROM albums " + \
|
||||
"WHERE " + where + \
|
||||
" ORDER BY albumartist, album"
|
||||
" ORDER BY %s, album" % \
|
||||
_orelse("albumartist_sort", "albumartist")
|
||||
c = self.conn.execute(sql, subvals)
|
||||
return [Album(self, dict(res)) for res in c.fetchall()]
|
||||
|
||||
|
|
@ -1059,7 +1069,8 @@ class Library(BaseLibrary):
|
|||
|
||||
sql = "SELECT * FROM items " + \
|
||||
"WHERE " + where + \
|
||||
" ORDER BY artist, album, disc, track"
|
||||
" ORDER BY %s, album, disc, track" % \
|
||||
_orelse("artist_sort", "artist")
|
||||
log.debug('Getting items with SQL: %s' % sql)
|
||||
c = self.conn.execute(sql, subvals)
|
||||
return ResultIterator(c)
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ Changelog
|
|||
for details.
|
||||
* Artist **sort names** are now fetched from MusicBrainz. There are two new data
|
||||
fields, ``artist_sort`` and ``albumartist_sort``, that contain sortable artist
|
||||
names like "Beatles, The". Thanks to Paul Provost.
|
||||
names like "Beatles, The". These fields are also used to sort albums and items
|
||||
when using the ``list`` command. Thanks to Paul Provost.
|
||||
* New :doc:`/plugins/rdm`: Randomly select albums and tracks from your library.
|
||||
Thanks to Philippe Mongeau.
|
||||
* The :doc:`/plugins/mbcollection` by Jeffrey Aylesworth was added to the core
|
||||
|
|
|
|||
Loading…
Reference in a new issue