Added a config parameter to set the read style used by the metadata parser. Default value switched from fast to accurate

This commit is contained in:
emeric
2022-08-21 14:17:20 +02:00
parent 1fb838c8d0
commit 5324d1fd15
12 changed files with 137 additions and 14 deletions
+3
View File
@@ -80,3 +80,6 @@ cover-preferred-file-names = ("cover", "front" );
# Set to true if you want to hide duplicate tracks
scanner-skip-duplicate-recording-mbid = false;
# Scanner read style for metadata, maybe be 'fast', 'average' or 'accurate'
scanner-parser-read-style = "accurate";
+1
View File
@@ -5,6 +5,7 @@ endif()
add_library(lmsmetadata SHARED
impl/AvFormatParser.cpp
impl/Factory.cpp
impl/TagLibParser.cpp
impl/Utils.cpp
)
+1 -1
View File
@@ -17,7 +17,7 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "metadata/AvFormatParser.hpp"
#include "AvFormatParser.hpp"
#include <algorithm>
#include <iostream>
+48
View File
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2022 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "metadata/IParser.hpp"
#include "utils/Exception.hpp"
#include "utils/Logger.hpp"
#include "AvFormatParser.hpp"
#include "TagLibParser.hpp"
#include "Utils.hpp"
namespace MetaData
{
std::unique_ptr<IParser>
createParser(ParserType parserType, ParserReadStyle parserReadStyle)
{
switch (parserType)
{
case ParserType::TagLib:
LMS_LOG(METADATA, INFO) << "Creating TagLib parser with read style = " << Utils::readStyleToString(parserReadStyle);
return std::make_unique<TagLibParser>(parserReadStyle);
case ParserType::AvFormat:
LMS_LOG(METADATA, INFO) << "Creating AvFormat parser";
return std::make_unique<AvFormatParser>();
}
throw LmsException {"Unhandled parser type"};
}
}
+25 -2
View File
@@ -17,7 +17,7 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include "metadata/TagLibParser.hpp"
#include "TagLibParser.hpp"
#include <taglib/apetag.h>
#include <taglib/asffile.h>
@@ -33,7 +33,10 @@
#include <taglib/vorbisfile.h>
#include <taglib/wavpackfile.h>
#include "utils/IConfig.hpp"
#include "utils/Exception.hpp"
#include "utils/Logger.hpp"
#include "utils/Service.hpp"
#include "utils/String.hpp"
#include "Utils.hpp"
@@ -145,6 +148,26 @@ getAlbum(const TagLib::PropertyMap& properties)
return Album {std::move(albumName.front()), albumMBID.front()};
}
static
TagLib::AudioProperties::ReadStyle
readStyleToTagLibReadStyle(ParserReadStyle readStyle)
{
switch (readStyle)
{
case ParserReadStyle::Fast: return TagLib::AudioProperties::ReadStyle::Fast;
case ParserReadStyle::Average: return TagLib::AudioProperties::ReadStyle::Average;
case ParserReadStyle::Accurate: return TagLib::AudioProperties::ReadStyle::Accurate;
}
throw LmsException {"Cannot convert read style"};
}
TagLibParser::TagLibParser(ParserReadStyle readStyle)
: _readStyle {readStyleToTagLibReadStyle(readStyle)}
{
}
void
TagLibParser::processTag(Track& track, const std::string& tag, const TagLib::StringList& values, bool debug)
{
@@ -267,7 +290,7 @@ TagLibParser::parse(const std::filesystem::path& p, bool debug)
{
TagLib::FileRef f {p.string().c_str(),
true, // read audio properties
TagLib::AudioProperties::Fast}; // TODO parametrize this
_readStyle};
if (f.isNull())
{
@@ -19,6 +19,7 @@
#pragma once
#include <taglib/audioproperties.h>
#include "metadata/IParser.hpp"
namespace TagLib
@@ -32,10 +33,14 @@ namespace MetaData
// Parse that makes use of AvFormat
class TagLibParser : public IParser
{
public:
TagLibParser(ParserReadStyle readStyle);
private:
std::optional<Track> parse(const std::filesystem::path& p, bool debug = false) override;
void processTag(Track& track, const std::string& tag, const TagLib::StringList& values, bool debug);
const TagLib::AudioProperties::ReadStyle _readStyle;
};
} // namespace MetaData
+15
View File
@@ -23,6 +23,8 @@
#include <iomanip>
#include <sstream>
#include "utils/Exception.hpp"
namespace MetaData::Utils
{
Wt::WDate
@@ -56,5 +58,18 @@ namespace MetaData::Utils
return {};
}
std::string_view
readStyleToString(ParserReadStyle readStyle)
{
switch (readStyle)
{
case ParserReadStyle::Fast: return "fast";
case ParserReadStyle::Average: return "average";
case ParserReadStyle::Accurate: return "accurate";
}
throw LmsException {"Unknown read style"};
}
}
+3
View File
@@ -20,8 +20,11 @@
#include <Wt/WDate.h>
#include "metadata/IParser.hpp"
namespace MetaData::Utils
{
Wt::WDate parseDate(const std::string& dateStr);
std::string_view readStyleToString(ParserReadStyle readStyle);
}
@@ -100,5 +100,18 @@ namespace MetaData
std::set<std::string> _clusterTypeNames;
};
enum class ParserType
{
TagLib,
AvFormat,
};
enum class ParserReadStyle
{
Fast,
Average,
Accurate,
};
std::unique_ptr<IParser> createParser(ParserType parserType, ParserReadStyle parserReadStyle);
} // namespace MetaData
@@ -31,7 +31,7 @@
#include "services/database/Track.hpp"
#include "services/database/TrackArtistLink.hpp"
#include "services/database/TrackFeatures.hpp"
#include "metadata/TagLibParser.hpp"
#include "metadata/IParser.hpp"
#include "services/recommendation/IRecommendationService.hpp"
#include "utils/Exception.hpp"
#include "utils/IConfig.hpp"
@@ -255,16 +255,29 @@ createScannerService(Db& db, Recommendation::IRecommendationService& recommendat
return std::make_unique<ScannerService>(db, recommendationService);
}
MetaData::ParserReadStyle
getParserReadStyle()
{
std::string_view readStyle {Service<IConfig>::get()->getString("scanner-parser-read-style", "accurate")};
if (readStyle == "fast")
return MetaData::ParserReadStyle::Fast;
else if (readStyle == "average")
return MetaData::ParserReadStyle::Average;
else if (readStyle == "accurate")
return MetaData::ParserReadStyle::Accurate;
throw LmsException {"Invalid value for 'scanner-parser-read-style'"};
}
ScannerService::ScannerService(Db& db, Recommendation::IRecommendationService& recommendationService)
: _recommendationService {recommendationService}
, _skipDuplicateRecordingMBID {Service<IConfig>::get()->getBool("scanner-skip-duplicate-recording-mbid", false)}
, _dbSession {db}
, _metadataParser {MetaData::createParser(MetaData::ParserType::TagLib, getParserReadStyle())} // For now, always use TagLib
{
LMS_LOG(DBUPDATER, INFO) << "skipDuplicateRecordingMBID = " << _skipDuplicateRecordingMBID;
// For now, always use TagLib
_metadataParser = std::make_unique<MetaData::TagLibParser>();
_ioService.setThreadCount(1);
refreshScanSettings();
+5 -6
View File
@@ -25,8 +25,7 @@
#include <Wt/WDate.h>
#include "metadata/AvFormatParser.hpp"
#include "metadata/TagLibParser.hpp"
#include "metadata/IParser.hpp"
#include "utils/StreamLogger.hpp"
std::ostream& operator<<(std::ostream& os, const MetaData::Artist& artist)
@@ -184,14 +183,14 @@ int main(int argc, char *argv[])
{
std::cout << "Using av:" << std::endl;
MetaData::AvFormatParser parser;
parse(parser, file);
auto parser {MetaData::createParser(MetaData::ParserType::AvFormat, MetaData::ParserReadStyle::Accurate)};
parse(*parser, file);
}
{
std::cout << "Using TagLib:" << std::endl;
MetaData::TagLibParser parser;
parse(parser, file);
auto parser {MetaData::createParser(MetaData::ParserType::TagLib, MetaData::ParserReadStyle::Accurate)};
parse(*parser, file);
}
}
}