Attempt to parse tags only from supported audio files

Trying and failing to parse tags from unsupported files is probably
costly (requires reading from SD card), and it probably slows down
indexing large collections that include a lot of non-audio files (like
cover art, etc).

This limits tag parsing to only files that have extensions for
supported audio formats. It assumes that folks don't have audio files
in supported formats with crazy extensions (e.g. an mp3-formatted file
with the extension .lol). Since this hardcodes a list of supported file
extensions for tag parsing, it'll need to be maintained later if more
formats are supported. The file ext matching is case-insensitive.

Fixes #149
custom
Clayton Craft 4 months ago committed by cooljqln
parent 46f55e3a1f
commit 92908533c4
  1. 17
      src/tangara/database/tag_parser.cpp
  2. 13
      src/tangara/database/tag_parser.hpp

@ -312,6 +312,23 @@ auto GenericTagParser::ReadAndParseTags(std::string_view p)
-> std::shared_ptr<TrackTags> {
std::string path{p};
libtags::Aux aux;
// Fail fast if trying to parse a file that doesn't appear to be a supported audio format
// For context, see: https://codeberg.org/cool-tech-zone/tangara-fw/issues/149
bool found = false;
for (const auto& ext : supported_exts) {
// Case-insensitive file extension check
if (std::equal(ext.rbegin(), ext.rend(), path.rbegin(),
[](char a, char b) { return std::tolower(a) == std::tolower(b); })) {
found=true;
break;
}
}
if (!found) {
ESP_LOGD(kTag, "skipping unsupported file: %s", path.c_str());
return {};
}
auto out = TrackTags::create();
aux.tags = out.get();

@ -55,6 +55,19 @@ class GenericTagParser : public ITagParser {
public:
auto ReadAndParseTags(std::string_view path)
-> std::shared_ptr<TrackTags> override;
private:
// Supported file extensions for parsing tags, derived from the list of
// supported audio formats here:
// https://cooltech.zone/tangara/docs/music-library/
static constexpr std::string supported_exts[] = {
"flac",
"mp3",
"ogg",
"ogx",
"opus",
"wav"
};
};
} // namespace database

Loading…
Cancel
Save