diff options
| author | ailurux <ailurux@noreply.codeberg.org> | 2024-12-17 05:45:59 +0000 |
|---|---|---|
| committer | ailurux <ailurux@noreply.codeberg.org> | 2024-12-17 05:45:59 +0000 |
| commit | b3e1e88ba25da15bfbfd948be788241adaef7e48 (patch) | |
| tree | 581223c19cfbea558b3fbc782058558c27a22820 | |
| parent | 287c4bfb26a3fc6a94d7fd10c8d2b1a90ebe8db5 (diff) | |
| parent | 96e2fdd4e2e502cb52fe89bf9fd26b61a07108d9 (diff) | |
| download | tangara-fw-b3e1e88ba25da15bfbfd948be788241adaef7e48.tar.gz | |
Merge pull request 'When no media-specific top level directories exist, assume everything is music' (#119) from jqln/no-media-types into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/119
| -rw-r--r-- | src/tangara/database/database.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/tangara/database/database.cpp b/src/tangara/database/database.cpp index f939725a..ce074ef9 100644 --- a/src/tangara/database/database.cpp +++ b/src/tangara/database/database.cpp @@ -292,9 +292,8 @@ auto Database::setTrackData(TrackId id, const TrackData& data) -> void { auto Database::getIndexes() -> std::vector<IndexInfo> { // TODO(jacqueline): This probably needs to be async? When we have runtime // configurable indexes, they will need to come from somewhere. - return { - kAllTracks, kAllAlbums, kAlbumsByArtist, kTracksByGenre, kPodcasts, kAudiobooks - }; + return {kAllTracks, kAllAlbums, kAlbumsByArtist, + kTracksByGenre, kPodcasts, kAudiobooks}; } Database::UpdateTracker::UpdateTracker() @@ -568,6 +567,23 @@ auto Database::calculateMediaType(TrackTags& tags, std::string_view path) return MediaType::kMusic; } + auto dir_exists = [&](auto path) { + FF_DIR dir; + bool res = f_opendir(&dir, path); + if (res == FR_OK) { + f_closedir(&dir); + } + return res == FR_OK; + }; + + // As a special case, if no media-specific paths exist at all, then assume + // the user doesn't really care about alternate media types and just wants to + // use the device for music. + if (!dir_exists(kMusicMediaPath) && !dir_exists(kPodcastMediaPath) && + !dir_exists(kAudiobookMediaPath)) { + return MediaType::kMusic; + } + return MediaType::kUnknown; } |
