Simplifiying the cluster types handling
This commit is contained in:
@@ -16,6 +16,7 @@ lms_SOURCES = \
|
||||
$(srcdir)/database/User.cpp \
|
||||
$(srcdir)/image/Image.cpp \
|
||||
$(srcdir)/metadata/AvFormat.cpp \
|
||||
$(srcdir)/metadata/MetaData.cpp \
|
||||
$(srcdir)/metadata/TagLibParser.cpp \
|
||||
$(srcdir)/scanner/MediaScanner.cpp \
|
||||
$(srcdir)/ui/Auth.cpp \
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
namespace MetaData
|
||||
{
|
||||
|
||||
AvFormat::AvFormat(const std::map<std::string, std::string>& clusterMap)
|
||||
: _clusterMap(clusterMap)
|
||||
AvFormat::AvFormat(const ClusterTypes& clusterTypes)
|
||||
: Parser(clusterTypes)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -155,13 +155,13 @@ AvFormat::parse(const boost::filesystem::path& p)
|
||||
{
|
||||
items.insert( std::make_pair(MetaData::Type::AcoustID, stringTrim(value)) );
|
||||
}
|
||||
else if (_clusterMap.find(tag) != _clusterMap.end())
|
||||
else if (_clusterTypes.find(tag) != _clusterTypes.end())
|
||||
{
|
||||
std::vector<std::string> clusterNames = splitString(value, ";,\\");
|
||||
|
||||
if (!clusterNames.empty())
|
||||
{
|
||||
clusters[_clusterMap[tag]] = std::set<std::string>(clusterNames.begin(), clusterNames.end());
|
||||
clusters[tag] = std::set<std::string>(clusterNames.begin(), clusterNames.end());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,18 +32,9 @@ class AvFormat : public Parser
|
||||
{
|
||||
public:
|
||||
|
||||
AvFormat(const std::map<std::string, std::string>& clusterMap
|
||||
= {
|
||||
{"GENRE", "Genre" },
|
||||
{"ALBUMGROUPING", "Group" }
|
||||
});
|
||||
|
||||
AvFormat(const ClusterTypes& clusterTypes = defaultClusterTypes);
|
||||
|
||||
boost::optional<Items> parse(const boost::filesystem::path& p);
|
||||
|
||||
private:
|
||||
|
||||
std::map<std::string,std::string> _clusterMap;
|
||||
};
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Emeric Poupon
|
||||
* Copyright (C) 2018 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
@@ -17,8 +17,7 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef METADATA_HPP
|
||||
#define METADATA_HPP
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
@@ -63,17 +62,26 @@ namespace MetaData
|
||||
// Type and associated data
|
||||
// See enum Type's comments
|
||||
using Items = std::map<Type, boost::any>;
|
||||
using Clusters = std::map<std::string, std::set<std::string>>;
|
||||
using Clusters = std::map<std::string /* type */, std::set<std::string> /* names */>;
|
||||
using ClusterTypes = std::set<std::string>;
|
||||
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
static const ClusterTypes defaultClusterTypes;
|
||||
|
||||
// Provide a map for tag name -> Cluster name
|
||||
Parser(const ClusterTypes& clusterTypes) : _clusterTypes(clusterTypes) {}
|
||||
|
||||
virtual boost::optional<Items> parse(const boost::filesystem::path& p) = 0;
|
||||
|
||||
void updateClusterTypes(const ClusterTypes& clusterTypes) { _clusterTypes = clusterTypes; }
|
||||
const ClusterTypes& getClusterTypes() const { return _clusterTypes; }
|
||||
bool isClusterTypeSupported(const std::string& clusterType) const { return _clusterTypes.find(clusterType) != _clusterTypes.end(); }
|
||||
|
||||
protected:
|
||||
ClusterTypes _clusterTypes;
|
||||
};
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
namespace MetaData
|
||||
{
|
||||
|
||||
TagLibParser::TagLibParser(const std::map<std::string, std::string>& clusterMap)
|
||||
: _clusterMap(clusterMap)
|
||||
TagLibParser::TagLibParser(const ClusterTypes& clusterTypes)
|
||||
: Parser(clusterTypes)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -188,14 +188,14 @@ TagLibParser::parse(const boost::filesystem::path& p)
|
||||
items.insert( std::make_pair(MetaData::Type::HasCover, true));
|
||||
}
|
||||
// Check if a hit a cluster tag
|
||||
else if (_clusterMap.find(tag) != _clusterMap.end())
|
||||
else if (_clusterTypes.find(tag) != _clusterTypes.end())
|
||||
{
|
||||
std::set<std::string> clusterNames;
|
||||
for (const auto& value : values)
|
||||
clusterNames.insert(value.to8Bit(true));
|
||||
|
||||
if (!clusterNames.empty())
|
||||
clusters[_clusterMap[tag]] = clusterNames;
|
||||
clusters[tag] = clusterNames;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,18 +32,9 @@ class TagLibParser : public Parser
|
||||
{
|
||||
public:
|
||||
|
||||
// Provide a map for TagLib name -> Cluster name
|
||||
TagLibParser(const std::map<std::string, std::string>& clusterMap
|
||||
= {
|
||||
{"GENRE", "Genre" },
|
||||
{"ALBUMGROUPING", "Group" }
|
||||
});
|
||||
TagLibParser(const ClusterTypes& clusterTypes = defaultClusterTypes);
|
||||
|
||||
boost::optional<Items> parse(const boost::filesystem::path& p);
|
||||
|
||||
private:
|
||||
|
||||
std::map<std::string,std::string> _clusterMap;
|
||||
};
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
@@ -59,13 +59,6 @@ const std::vector<std::string> defaultFileExtensions =
|
||||
".shn",
|
||||
};
|
||||
|
||||
// Caution current implementation prevents spaces with the names
|
||||
const std::vector<std::string> defaultClusters =
|
||||
{
|
||||
"Genre",
|
||||
"Group",
|
||||
};
|
||||
|
||||
Wt::WDate
|
||||
getNextMonday(Wt::WDate current)
|
||||
{
|
||||
@@ -160,7 +153,12 @@ _db(connectionPool)
|
||||
Setting::setString(_db.getSession(), fileExtensionsSetting, joinStrings(defaultFileExtensions, " "));
|
||||
|
||||
if (!Setting::exists(_db.getSession(), clustersSetting))
|
||||
Setting::setString(_db.getSession(), clustersSetting, joinStrings(defaultClusters, " "));
|
||||
{
|
||||
std::vector<std::string> defaultClusterTypes(MetaData::Parser::defaultClusterTypes.begin(), MetaData::Parser::defaultClusterTypes.end());
|
||||
Setting::setString(_db.getSession(), clustersSetting, joinStrings(defaultClusterTypes, " "));
|
||||
}
|
||||
|
||||
refreshScanSettings();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -325,9 +323,11 @@ MediaScanner::refreshScanSettings()
|
||||
for (auto rootDir : Database::MediaDirectory::getAll(_db.getSession()))
|
||||
_rootDirectories.push_back(rootDir->getPath());
|
||||
|
||||
_clusterTypes.clear();
|
||||
MetaData::ClusterTypes clusterTypes;
|
||||
for (auto cluster : splitString(Setting::getString(_db.getSession(), clustersSetting), " "))
|
||||
_clusterTypes.push_back(cluster);
|
||||
clusterTypes.insert(cluster);
|
||||
|
||||
_metadataParser.updateClusterTypes(clusterTypes);
|
||||
}
|
||||
|
||||
Artist::pointer
|
||||
@@ -800,8 +800,7 @@ MediaScanner::checkClusters()
|
||||
// Remove no longer desired clusters
|
||||
for (auto clusterType : clusterTypes)
|
||||
{
|
||||
if (std::none_of(_clusterTypes.begin(), _clusterTypes.end(),
|
||||
[&clusterType](std::string clusterTypeName) { return clusterTypeName == clusterType->getName(); }))
|
||||
if (!_metadataParser.isClusterTypeSupported(clusterType->getName()))
|
||||
{
|
||||
LMS_LOG(DBUPDATER, INFO) << "Removing cluster type " << clusterType->getName();
|
||||
clusterType.remove();
|
||||
@@ -810,7 +809,7 @@ MediaScanner::checkClusters()
|
||||
}
|
||||
|
||||
// Add any missing clusters
|
||||
for (auto clusterTypeName : _clusterTypes)
|
||||
for (auto clusterTypeName : _metadataParser.getClusterTypes())
|
||||
{
|
||||
if (std::none_of(clusterTypes.begin(), clusterTypes.end(),
|
||||
[&clusterTypeName](ClusterType::pointer clusterType) { return (clusterType->getName() == clusterTypeName); }))
|
||||
|
||||
@@ -126,7 +126,6 @@ class MediaScanner
|
||||
Database::Handler _db;
|
||||
|
||||
// Scan settings
|
||||
std::vector<std::string> _clusterTypes;
|
||||
std::vector<boost::filesystem::path> _fileExtensions;
|
||||
std::vector<boost::filesystem::path> _rootDirectories;
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ test_avmetadata_SOURCES = TestAvMetadata.cpp \
|
||||
$(top_srcdir)/src/utils/Utils.cpp \
|
||||
$(top_srcdir)/src/metadata/AvFormat.cpp \
|
||||
$(top_srcdir)/src/metadata/TagLibParser.cpp \
|
||||
$(top_srcdir)/src/metadata/MetaData.cpp \
|
||||
$(top_srcdir)/src/av/AvInfo.cpp
|
||||
|
||||
test_avmetadata_CXXFLAGS=-std=c++11 -Wall -Wextra -I$(top_srcdir)/src
|
||||
|
||||
Reference in New Issue
Block a user