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