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:
@@ -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>
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "metadata/IParser.hpp"
|
||||
|
||||
namespace MetaData
|
||||
{
|
||||
|
||||
// Parse that makes use of AvFormat
|
||||
class AvFormatParser : public IParser
|
||||
{
|
||||
public:
|
||||
std::optional<Track> parse(const std::filesystem::path& p, bool debug = false) override;
|
||||
};
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
@@ -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/>.
|
||||
*/
|
||||
|
||||
#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())
|
||||
{
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <taglib/audioproperties.h>
|
||||
#include "metadata/IParser.hpp"
|
||||
|
||||
namespace TagLib
|
||||
{
|
||||
class StringList;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -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"};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user