diff --git a/lib/libtags/opus.c b/lib/libtags/opus.c index fa2c7d40..fcea57d8 100644 --- a/lib/libtags/opus.c +++ b/lib/libtags/opus.c @@ -63,7 +63,7 @@ tagopus(Tagctx *ctx) ctx->buf[sz] = 0; if((v = strchr(ctx->buf, '=')) == nil) - return -1; + continue; *v++ = 0; cbvorbiscomment(ctx, ctx->buf, v); } diff --git a/src/database/include/tag_parser.hpp b/src/database/include/tag_parser.hpp index fe7a95f3..f196c479 100644 --- a/src/database/include/tag_parser.hpp +++ b/src/database/include/tag_parser.hpp @@ -20,12 +20,6 @@ class ITagParser { -> std::shared_ptr = 0; }; -class GenericTagParser : public ITagParser { - public: - auto ReadAndParseTags(const std::string& path) - -> std::shared_ptr override; -}; - class TagParserImpl : public ITagParser { public: TagParserImpl(); @@ -33,8 +27,7 @@ class TagParserImpl : public ITagParser { -> std::shared_ptr override; private: - std::map> extension_to_parser_; - GenericTagParser generic_parser_; + auto parseNew(const std::string& path) -> std::shared_ptr; /* * Cache of tags that have already been extracted from files. Ideally this @@ -48,10 +41,4 @@ class TagParserImpl : public ITagParser { // any of our UI. }; -class OpusTagParser : public ITagParser { - public: - auto ReadAndParseTags(const std::string& path) - -> std::shared_ptr override; -}; - } // namespace database diff --git a/src/database/tag_parser.cpp b/src/database/tag_parser.cpp index 293793f3..c247bb7d 100644 --- a/src/database/tag_parser.cpp +++ b/src/database/tag_parser.cpp @@ -6,14 +6,13 @@ #include "tag_parser.hpp" -#include +#include #include #include #include #include "esp_log.h" #include "ff.h" -#include "opusfile.h" #include "spi.hpp" #include "tags.h" @@ -21,16 +20,6 @@ namespace database { -const static std::array, 7> kVorbisIdToTag = {{ - {"TITLE", Tag::kTitle}, - {"ARTIST", Tag::kArtist}, - {"ALBUM", Tag::kAlbum}, - {"ALBUMARTIST", Tag::kAlbumArtist}, - {"DISCNUMBER", Tag::kDisc}, - {"TRACKNUMBER", Tag::kTrack}, - {"GENRE", Tag::kGenres}, -}}; - static auto convert_tag(int tag) -> std::optional { switch (tag) { case Ttitle: @@ -117,9 +106,7 @@ static void toc(Tagctx* ctx, int ms, int offset) {} static const std::size_t kBufSize = 1024; [[maybe_unused]] static const char* kTag = "TAGS"; -TagParserImpl::TagParserImpl() { - extension_to_parser_["opus"] = std::make_unique(); -} +TagParserImpl::TagParserImpl() {} auto TagParserImpl::ReadAndParseTags(const std::string& path) -> std::shared_ptr { @@ -132,18 +119,7 @@ auto TagParserImpl::ReadAndParseTags(const std::string& path) } } - ITagParser* parser = &generic_parser_; - auto dot_pos = path.find_last_of("."); - if (dot_pos != std::string::npos && path.size() - dot_pos > 1) { - std::string extension = path.substr(dot_pos + 1); - std::transform(extension.begin(), extension.end(), extension.begin(), - [](unsigned char c) { return std::tolower(c); }); - if (extension_to_parser_.contains(extension)) { - parser = extension_to_parser_[extension].get(); - } - } - - std::shared_ptr tags = parser->ReadAndParseTags(path); + std::shared_ptr tags = parseNew(path); if (!tags) { return {}; } @@ -167,7 +143,7 @@ auto TagParserImpl::ReadAndParseTags(const std::string& path) return tags; } -auto GenericTagParser::ReadAndParseTags(const std::string& path) +auto TagParserImpl::parseNew(const std::string& path) -> std::shared_ptr { libtags::Aux aux; auto out = TrackTags::create(); @@ -229,34 +205,4 @@ auto GenericTagParser::ReadAndParseTags(const std::string& path) return out; } -auto OpusTagParser::ReadAndParseTags(const std::string& path) - -> std::shared_ptr { - auto lock = drivers::acquire_spi(); - std::string vfs_path = "/sdcard" + path; - int err; - OggOpusFile* f = op_test_file(vfs_path.c_str(), &err); - if (f == NULL) { - ESP_LOGE(kTag, "opusfile tag parsing failed: %d", err); - return {}; - } - const OpusTags* tags = op_tags(f, -1); - if (tags == NULL) { - ESP_LOGE(kTag, "no tags in opusfile"); - op_free(f); - return {}; - } - - auto out = TrackTags::create(); - out->encoding(Container::kOpus); - for (const auto& pair : kVorbisIdToTag) { - const char* tag = opus_tags_query(tags, pair.first, 0); - if (tag != NULL) { - out->set(pair.second, tag); - } - } - - op_free(f); - return out; -} - } // namespace database