Skip to content

Support for Artist Sort Tags #1779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

x9foo
Copy link

@x9foo x9foo commented Jul 8, 2025

Overview

This PR adds support for sorting a collection by sort names often included as special tags in song files. This allows, for example, to see "The Beatles" sorted as "Beatles, The".

Strawberry already has some support for filtering articles from names before sorting, but this has limitations like no support for languages other than English. A more reliable way is to use provided data since the rules for correct sort names can be quite complex. If you tag your files with MusicBrainz, for example, then sort information is stored in tags "artist sort" and "album artist sort".

Technically, the PR implements support for vorbis tags ARTISTSORT and ALBUMARTISTSORT, and id3v2 tags TSOP and TSO2 (see e.g. https://docs.mp3tag.de/mapping-table/ or https://picard-docs.musicbrainz.org/downloads/MusicBrainz_Picard_Tag_Map.html ).

While motivated mainly by my own needs, this PR also addresses requests in the following forum posts:

User Visible Changes

Collection

The Settings|Collection page now has a combo box for choosing the sort behavior. Previous versions of strawberry had a checkbox "Skip leading articles ("the", "a", "an") when sorting artist names". This has been removed, but the underlying behavior is still available as one of the combobox options.

collectionsettings

There are four settings available:

combobox

Option 1 (Sort and show artist name as is) uses the artist name as is. It is equivalent to the unchecked state of the "Skip leading articles..." checkbox in previous versions of strawberry. Here is an example of the result:

option-1

Option 2 (Skip articles "The, A, An" and show "The Beatles") is the default and the same as the checkbox "Skip leading articles..." in earlier versions. Note that this option does not correctly handle non-English names as can be seen by the entry for "Die Ärzte".

option-2

Options 1 and 2 provide full backwards compatibility. They can be used, for example, if your collection does not have sort tags, you do not want to use them, or you are just happy with the current behavior.

Option 3 and 4 provide the new functionality by using sort tags. Option 3 (Use sort tag "Beatles, The" and show "The Beatles") uses the sort tag for sorting internally, but shows the artist name.

option-3

Option 4 (Use sort tag "Beatles, The" and show "Beatles, The") uses the sort tag internally and also for display.

option-4

Playlists

Two new columns Artist Sort and Album Artist Sort can be enabled in the context menu of playlists:

playlistmenu

playlist

Smart Playlists

Smart playlists can use search terms with Artist Sort and Album Artist Sort fields.

smartplsearch

Both new fields can then be used for sorting the results as well.

smartplsort

Edit Track Information

The Edit Track Information dialog allows to edit the two new fields for supported file formats (e.g. flac and mp3). Changes are written back to the song files and the collection database is updated as well.

edittrack

Context View

The custom text settings for the context view can now make use of the new fields. The popup menu in the Settings|Context page has additional entries for that:

contextsettings

Here is an example setting using the artistsort field.

context1

context2

Migrating Existing Collections

When the new version of strawberry detects an older collection database on startup, it offers to rescan the collection.

rescan

This should be confirmed in order to read information for the new tags from song files.

Implementation Details

The steps necessary to implement this were:

  • Add new fields artistsort and albumartistsort to database schema
  • Increment database schema from 20 to 21
  • Add migration script for database upgrade
  • Add new fields artistsort and albumartistsort to Song class
  • Read/write vorbis and id3v2 tags in Tagreader and set/get corresponding Song fields
  • Implement new sort options in CollectionModel
  • Extend settings ui
  • Extend playlist view
  • Extend smart playlist ui
  • Extend edit track dialog
  • Trigger dialog offering collection rescan on startup
  • Add unit tests

Limitations

  • Tested only on Fedora 42
  • Tested only with flac and mp3 files
  • Unit tests are very limited in scope, most tests where done manually

Tests

I have run the following manual tests with a flac and mp3 collection of about 1,000 albums / 16,000 songs:

  • Verify schema migration is triggered on start up, and adds / reads new fields
  • Verify all four options for sorting the collection work
  • Verify empty sort fields do not crash strawberry
  • Verify playlist columns can be switched on, can be used to sort, and can be edited
  • Verify edit track information dialog allows to edit new fields
  • Verify smart playlist allows to use new fields for selection and sorting

Sorry, that this PR got a bit long. Initially, when I started to work on this, I thought it might be a rather small change. Then I learned how many places in strawberry actually are affected, although, I think most changes were rather straightforward. Let me know if there is anything else to do or if you find any issues with my changes. I will try to fix them.

@x9foo x9foo marked this pull request as ready for review July 8, 2025 09:13
Copy link
Member

@jonaski jonaski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks great.

Could you also add "TITLESORT" and "ALBUMSORT" at the same time?
And optionally "COMPOSERSORT" and "PERFORMERSORT".

And if you could do me the favor of adding "bpm" (REAL), "mood" (TEXT) and "initial_key" (TEXT) to the same schema update. I can do the work and add support for those tags. But that way we don't have to do multiple schema updates before the next version. Once this get's merged some users will already be using it.


DROP INDEX IF EXISTS idx_albumartistsort;

ALTER TABLE songs ADD COLUMN artistsort TEXT;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use %allsongstables to reduce the number of entries, and that will also update the device song tables.
See

if (command.contains(QLatin1String(kMagicAllSongsTables))) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to add the columns to device-schema.sql https://github.com/strawberrymusicplayer/strawberry/blob/master/data/schema/device-schema.sql identical to songs, otherwise devices will fail.

@@ -50,6 +50,13 @@ constexpr char kOverwriteRating[] = "overwrite_rating";
constexpr char kDeleteFiles[] = "delete_files";
constexpr char kLastPath[] = "last_path";

enum class SortShowArtists {
AsIs = 1,
SortSkipArticleShowArtist = 2,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SortSkipArticleShowArtist = 2,
SkipArticles = 2,

@@ -50,6 +50,13 @@ constexpr char kOverwriteRating[] = "overwrite_rating";
constexpr char kDeleteFiles[] = "delete_files";
constexpr char kLastPath[] = "last_path";

enum class SortShowArtists {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest different names so we can use the same enum for all sort tags:
SortBehaviour

enum class SortShowArtists {
AsIs = 1,
SortSkipArticleShowArtist = 2,
SortByTagShowArtist = 3,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This name was a bit confusing to me, also don't limit the enum to artist.

Suggested change
SortByTagShowArtist = 3,
UseSortTagForSort = 3,

AsIs = 1,
SortSkipArticleShowArtist = 2,
SortByTagShowArtist = 3,
SortByTagShowTag = 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SortByTagShowTag = 4
UseSortTagForDisplayAndSort = 4

@x9foo
Copy link
Author

x9foo commented Jul 10, 2025

Thanks for reviewing. I agree with all your comments. Handling the other sort tags as well certainly makes sense (I just hope that the ui doesn't get too messy).

What's the best way forward now? Since the scope changes quite a bit I propose the following:

  • I create a new PR "Database Schema Version 21" that only includes my sort tag additions as well as your proposed bpm, mood, initial_key additions. UPDATE: Change prepared
  • I create a new PR "Support for Sort Tags" where I basically replay and extend my changes from this PR and integrate your comments
  • We leave this PR as reference for now and close it when the other two are done

That way we could get the db changes early into master and you can work on bpm, mood, initial_key without depending on me (I won't be able to work on the sort tags next week). What do you think?

x9foo pushed a commit to x9foo/strawberry that referenced this pull request Jul 10, 2025
Upgrade from schema version 20 to 21. This includes:

- six fields for sort tags
- new fields bpm, mood, initial_key

See strawberrymusicplayer#1779 (review)
@jonaski
Copy link
Member

jonaski commented Jul 10, 2025

You don't need to create a new PR, but you can add the schema update first if you want.

x9foo pushed a commit to x9foo/strawberry that referenced this pull request Jul 12, 2025
Upgrade from schema version 20 to 21. This includes:

- six fields for sort tags
- new fields bpm, mood, initial_key

See strawberrymusicplayer#1779 (review)
jonaski pushed a commit that referenced this pull request Jul 12, 2025
Upgrade from schema version 20 to 21. This includes:

- six fields for sort tags
- new fields bpm, mood, initial_key

See #1779 (review)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants