Handle sort tags in fixup_tags()

Ensure the sort tags are filled and normalized.
This commit is contained in:
Kai Elwert 2010-09-21 18:42:37 +02:00 committed by Julien BLACHE
parent 373c5584af
commit 3162028c41

View File

@ -37,6 +37,8 @@
#include <dirent.h>
#include <pthread.h>
#include <uninorm.h>
#if defined(__linux__)
# include <sys/inotify.h>
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
@ -132,6 +134,24 @@ pop_dir(struct stacked_dir **s)
}
static void
normalize_fixup_tag(char **tag, char *src_tag)
{
char *norm;
size_t len;
/* Note: include terminating NUL in string length for u8_normalize */
if (!*tag)
*tag = (char *)u8_normalize(UNINORM_NFD, (uint8_t *)src_tag, strlen(src_tag) + 1, NULL, &len);
else
{
norm = (char *)u8_normalize(UNINORM_NFD, (uint8_t *)*tag, strlen(*tag) + 1, NULL, &len);
free(*tag);
*tag = norm;
}
}
static void
fixup_tags(struct media_file_info *mfi)
{
@ -247,6 +267,16 @@ fixup_tags(struct media_file_info *mfi)
else
mfi->album_artist = strdup(mfi->artist);
}
/* Ensure sort tags are filled and normalized */
normalize_fixup_tag(&mfi->artist_sort, mfi->artist);
normalize_fixup_tag(&mfi->album_sort, mfi->album);
normalize_fixup_tag(&mfi->title_sort, mfi->title);
normalize_fixup_tag(&mfi->album_artist_sort, mfi->album_artist);
/* Composer is not one of our mandatory tags, so take extra care */
if (mfi->composer_sort || mfi->composer)
normalize_fixup_tag(&mfi->composer_sort, mfi->composer);
}