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:
@@ -80,3 +80,6 @@ cover-preferred-file-names = ("cover", "front" );
|
|||||||
|
|
||||||
# Set to true if you want to hide duplicate tracks
|
# Set to true if you want to hide duplicate tracks
|
||||||
scanner-skip-duplicate-recording-mbid = false;
|
scanner-skip-duplicate-recording-mbid = false;
|
||||||
|
|
||||||
|
# Scanner read style for metadata, maybe be 'fast', 'average' or 'accurate'
|
||||||
|
scanner-parser-read-style = "accurate";
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ endif()
|
|||||||
|
|
||||||
add_library(lmsmetadata SHARED
|
add_library(lmsmetadata SHARED
|
||||||
impl/AvFormatParser.cpp
|
impl/AvFormatParser.cpp
|
||||||
|
impl/Factory.cpp
|
||||||
impl/TagLibParser.cpp
|
impl/TagLibParser.cpp
|
||||||
impl/Utils.cpp
|
impl/Utils.cpp
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "metadata/AvFormatParser.hpp"
|
#include "AvFormatParser.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|||||||
@@ -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"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "metadata/TagLibParser.hpp"
|
#include "TagLibParser.hpp"
|
||||||
|
|
||||||
#include <taglib/apetag.h>
|
#include <taglib/apetag.h>
|
||||||
#include <taglib/asffile.h>
|
#include <taglib/asffile.h>
|
||||||
@@ -33,7 +33,10 @@
|
|||||||
#include <taglib/vorbisfile.h>
|
#include <taglib/vorbisfile.h>
|
||||||
#include <taglib/wavpackfile.h>
|
#include <taglib/wavpackfile.h>
|
||||||
|
|
||||||
|
#include "utils/IConfig.hpp"
|
||||||
|
#include "utils/Exception.hpp"
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
|
#include "utils/Service.hpp"
|
||||||
#include "utils/String.hpp"
|
#include "utils/String.hpp"
|
||||||
#include "Utils.hpp"
|
#include "Utils.hpp"
|
||||||
|
|
||||||
@@ -145,6 +148,26 @@ getAlbum(const TagLib::PropertyMap& properties)
|
|||||||
return Album {std::move(albumName.front()), albumMBID.front()};
|
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
|
void
|
||||||
TagLibParser::processTag(Track& track, const std::string& tag, const TagLib::StringList& values, bool debug)
|
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(),
|
TagLib::FileRef f {p.string().c_str(),
|
||||||
true, // read audio properties
|
true, // read audio properties
|
||||||
TagLib::AudioProperties::Fast}; // TODO parametrize this
|
_readStyle};
|
||||||
|
|
||||||
if (f.isNull())
|
if (f.isNull())
|
||||||
{
|
{
|
||||||
|
|||||||
+6
-1
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <taglib/audioproperties.h>
|
||||||
#include "metadata/IParser.hpp"
|
#include "metadata/IParser.hpp"
|
||||||
|
|
||||||
namespace TagLib
|
namespace TagLib
|
||||||
@@ -32,10 +33,14 @@ namespace MetaData
|
|||||||
// Parse that makes use of AvFormat
|
// Parse that makes use of AvFormat
|
||||||
class TagLibParser : public IParser
|
class TagLibParser : public IParser
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
TagLibParser(ParserReadStyle readStyle);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::optional<Track> parse(const std::filesystem::path& p, bool debug = false) override;
|
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);
|
void processTag(Track& track, const std::string& tag, const TagLib::StringList& values, bool debug);
|
||||||
|
|
||||||
|
const TagLib::AudioProperties::ReadStyle _readStyle;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace MetaData
|
} // namespace MetaData
|
||||||
@@ -23,6 +23,8 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
#include "utils/Exception.hpp"
|
||||||
|
|
||||||
namespace MetaData::Utils
|
namespace MetaData::Utils
|
||||||
{
|
{
|
||||||
Wt::WDate
|
Wt::WDate
|
||||||
@@ -56,5 +58,18 @@ namespace MetaData::Utils
|
|||||||
|
|
||||||
return {};
|
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"};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,8 +20,11 @@
|
|||||||
|
|
||||||
#include <Wt/WDate.h>
|
#include <Wt/WDate.h>
|
||||||
|
|
||||||
|
#include "metadata/IParser.hpp"
|
||||||
|
|
||||||
namespace MetaData::Utils
|
namespace MetaData::Utils
|
||||||
{
|
{
|
||||||
Wt::WDate parseDate(const std::string& dateStr);
|
Wt::WDate parseDate(const std::string& dateStr);
|
||||||
|
std::string_view readStyleToString(ParserReadStyle readStyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,5 +100,18 @@ namespace MetaData
|
|||||||
std::set<std::string> _clusterTypeNames;
|
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
|
} // namespace MetaData
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
#include "services/database/Track.hpp"
|
#include "services/database/Track.hpp"
|
||||||
#include "services/database/TrackArtistLink.hpp"
|
#include "services/database/TrackArtistLink.hpp"
|
||||||
#include "services/database/TrackFeatures.hpp"
|
#include "services/database/TrackFeatures.hpp"
|
||||||
#include "metadata/TagLibParser.hpp"
|
#include "metadata/IParser.hpp"
|
||||||
#include "services/recommendation/IRecommendationService.hpp"
|
#include "services/recommendation/IRecommendationService.hpp"
|
||||||
#include "utils/Exception.hpp"
|
#include "utils/Exception.hpp"
|
||||||
#include "utils/IConfig.hpp"
|
#include "utils/IConfig.hpp"
|
||||||
@@ -255,16 +255,29 @@ createScannerService(Db& db, Recommendation::IRecommendationService& recommendat
|
|||||||
return std::make_unique<ScannerService>(db, recommendationService);
|
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)
|
ScannerService::ScannerService(Db& db, Recommendation::IRecommendationService& recommendationService)
|
||||||
: _recommendationService {recommendationService}
|
: _recommendationService {recommendationService}
|
||||||
, _skipDuplicateRecordingMBID {Service<IConfig>::get()->getBool("scanner-skip-duplicate-recording-mbid", false)}
|
, _skipDuplicateRecordingMBID {Service<IConfig>::get()->getBool("scanner-skip-duplicate-recording-mbid", false)}
|
||||||
, _dbSession {db}
|
, _dbSession {db}
|
||||||
|
, _metadataParser {MetaData::createParser(MetaData::ParserType::TagLib, getParserReadStyle())} // For now, always use TagLib
|
||||||
{
|
{
|
||||||
LMS_LOG(DBUPDATER, INFO) << "skipDuplicateRecordingMBID = " << _skipDuplicateRecordingMBID;
|
LMS_LOG(DBUPDATER, INFO) << "skipDuplicateRecordingMBID = " << _skipDuplicateRecordingMBID;
|
||||||
|
|
||||||
// For now, always use TagLib
|
|
||||||
_metadataParser = std::make_unique<MetaData::TagLibParser>();
|
|
||||||
|
|
||||||
_ioService.setThreadCount(1);
|
_ioService.setThreadCount(1);
|
||||||
|
|
||||||
refreshScanSettings();
|
refreshScanSettings();
|
||||||
|
|||||||
@@ -25,8 +25,7 @@
|
|||||||
|
|
||||||
#include <Wt/WDate.h>
|
#include <Wt/WDate.h>
|
||||||
|
|
||||||
#include "metadata/AvFormatParser.hpp"
|
#include "metadata/IParser.hpp"
|
||||||
#include "metadata/TagLibParser.hpp"
|
|
||||||
#include "utils/StreamLogger.hpp"
|
#include "utils/StreamLogger.hpp"
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const MetaData::Artist& artist)
|
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;
|
std::cout << "Using av:" << std::endl;
|
||||||
MetaData::AvFormatParser parser;
|
auto parser {MetaData::createParser(MetaData::ParserType::AvFormat, MetaData::ParserReadStyle::Accurate)};
|
||||||
parse(parser, file);
|
parse(*parser, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::cout << "Using TagLib:" << std::endl;
|
std::cout << "Using TagLib:" << std::endl;
|
||||||
MetaData::TagLibParser parser;
|
auto parser {MetaData::createParser(MetaData::ParserType::TagLib, MetaData::ParserReadStyle::Accurate)};
|
||||||
parse(parser, file);
|
parse(*parser, file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user