diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-12-23 16:21:22 +1100 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-12-23 16:21:22 +1100 |
| commit | 35520ef17720778f7140c085c6c2bd005ed802f8 (patch) | |
| tree | 21fb46f70afb0b4f54809c8be588aebc1108ea95 /src | |
| parent | 5cdc1141ee5f5c7b19809940457b4c4c21db9ae6 (diff) | |
| download | tangara-fw-35520ef17720778f7140c085c6c2bd005ed802f8.tar.gz | |
Make media directories case insensitive
Diffstat (limited to 'src')
| -rw-r--r-- | src/tangara/database/database.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/tangara/database/database.cpp b/src/tangara/database/database.cpp index ce074ef9..9851b041 100644 --- a/src/tangara/database/database.cpp +++ b/src/tangara/database/database.cpp @@ -532,28 +532,34 @@ static constexpr char kAudiobookMediaPath[] = "/Audiobooks/"; auto Database::calculateMediaType(TrackTags& tags, std::string_view path) -> MediaType { + + auto equalsIgnoreCase = [&](char lhs, char rhs) { + return std::tolower(lhs) == std::tolower(rhs); + }; + // Use the filepath first, since it's the most explicit way for the user to // tell us what this track is. - if (path.starts_with(kMusicMediaPath)) { + auto checkPathPrefix = [&](std::string_view path, std::string prefix) { + auto res = std::mismatch(prefix.begin(), prefix.end(), path.begin(), path.end(), equalsIgnoreCase); + return res.first == prefix.end(); + }; + + if (checkPathPrefix(path, kMusicMediaPath)) { return MediaType::kMusic; } - if (path.starts_with(kPodcastMediaPath)) { + if (checkPathPrefix(path, kPodcastMediaPath)) { return MediaType::kPodcast; } - if (path.starts_with(kAudiobookMediaPath)) { + if (checkPathPrefix(path, kAudiobookMediaPath)) { return MediaType::kAudiobook; } // Podcasts may (rarely!) have a genre tag that tells us what they are. Look // for it. - auto equalsIgnoreCase = [&](char lhs, char rhs) { - // NB: not really safe across languages, but genre tags tend to be in - // English anyway. - return std::tolower(lhs) == std::tolower(rhs); - }; - auto genres = tags.genres(); for (const auto& genre : genres) { + // NB: not really safe across languages, but genre tags tend to be in + // English anyway. if (std::ranges::equal(genre, "podcast", equalsIgnoreCase)) { return MediaType::kPodcast; } |
