Split Cluster and Track in order to reduce compile dependencies
This commit is contained in:
@@ -5,6 +5,7 @@ lms_SOURCES = \
|
|||||||
$(srcdir)/av/AvInfo.cpp \
|
$(srcdir)/av/AvInfo.cpp \
|
||||||
$(srcdir)/av/AvTranscoder.cpp \
|
$(srcdir)/av/AvTranscoder.cpp \
|
||||||
$(srcdir)/cover/CoverArtGrabber.cpp \
|
$(srcdir)/cover/CoverArtGrabber.cpp \
|
||||||
|
$(srcdir)/database/Cluster.cpp \
|
||||||
$(srcdir)/database/DbArtist.cpp \
|
$(srcdir)/database/DbArtist.cpp \
|
||||||
$(srcdir)/database/DatabaseHandler.cpp \
|
$(srcdir)/database/DatabaseHandler.cpp \
|
||||||
$(srcdir)/database/MediaDirectory.cpp \
|
$(srcdir)/database/MediaDirectory.cpp \
|
||||||
|
|||||||
@@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2013-2016 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 "Cluster.hpp"
|
||||||
|
|
||||||
|
#include "DbArtist.hpp"
|
||||||
|
#include "Release.hpp"
|
||||||
|
#include "SqlQuery.hpp"
|
||||||
|
#include "Track.hpp"
|
||||||
|
|
||||||
|
namespace Database {
|
||||||
|
|
||||||
|
Cluster::Cluster()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Cluster::Cluster(Wt::Dbo::ptr<ClusterType> type, std::string name)
|
||||||
|
: _name(std::string(name, 0, _maxNameLength)),
|
||||||
|
_clusterType(type)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Cluster::pointer
|
||||||
|
Cluster::create(Wt::Dbo::Session& session, Wt::Dbo::ptr<ClusterType> type, std::string name)
|
||||||
|
{
|
||||||
|
return session.add(std::make_unique<Cluster>(type, name));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Cluster::pointer>
|
||||||
|
Cluster::getAll(Wt::Dbo::Session& session)
|
||||||
|
{
|
||||||
|
Wt::Dbo::collection<Cluster::pointer> res = session.find<Cluster>();
|
||||||
|
|
||||||
|
return std::vector<Cluster::pointer>(res.begin(), res.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
Cluster::pointer
|
||||||
|
Cluster::getById(Wt::Dbo::Session& session, IdType id)
|
||||||
|
{
|
||||||
|
return session.find<Cluster>().where("id = ?").bind(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClusterType::ClusterType(std::string name)
|
||||||
|
: _name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ClusterType::pointer>
|
||||||
|
ClusterType::getAllOrphans(Wt::Dbo::Session& session)
|
||||||
|
{
|
||||||
|
Wt::Dbo::collection<pointer> res = session.query<Wt::Dbo::ptr<ClusterType>>("select c_t from cluster_type c_t LEFT OUTER JOIN cluster c ON c_t.id = c.cluster_type_id WHERE c.id IS NULL");
|
||||||
|
|
||||||
|
return std::vector<pointer>(res.begin(), res.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ClusterType::pointer
|
||||||
|
ClusterType::getByName(Wt::Dbo::Session& session, std::string name)
|
||||||
|
{
|
||||||
|
return session.find<ClusterType>().where("name = ?").bind(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<ClusterType::pointer>
|
||||||
|
ClusterType::getAll(Wt::Dbo::Session& session)
|
||||||
|
{
|
||||||
|
Wt::Dbo::collection<pointer> res = session.find<ClusterType>();
|
||||||
|
|
||||||
|
return std::vector<pointer>(res.begin(), res.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
ClusterType::pointer
|
||||||
|
ClusterType::create(Wt::Dbo::Session& session, std::string name)
|
||||||
|
{
|
||||||
|
return session.add(std::make_unique<ClusterType>(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
Cluster::pointer
|
||||||
|
ClusterType::getCluster(std::string name) const
|
||||||
|
{
|
||||||
|
assert(self());
|
||||||
|
assert(IdIsValid(self()->id()));
|
||||||
|
assert(session());
|
||||||
|
|
||||||
|
return session()->find<Cluster>()
|
||||||
|
.where("name = ?").bind(name)
|
||||||
|
.where("cluster_type_id = ?").bind(self()->id());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Cluster::pointer>
|
||||||
|
ClusterType::getClusters() const
|
||||||
|
{
|
||||||
|
assert(self());
|
||||||
|
assert(IdIsValid(self()->id()));
|
||||||
|
assert(session());
|
||||||
|
|
||||||
|
Wt::Dbo::collection<Cluster::pointer> res = session()->find<Cluster>()
|
||||||
|
.where("cluster_type_id = ?").bind(self()->id())
|
||||||
|
.orderBy("name");
|
||||||
|
|
||||||
|
return std::vector<Cluster::pointer>(res.begin(), res.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
Cluster::addTrack(Wt::Dbo::ptr<Track> track)
|
||||||
|
{
|
||||||
|
_tracks.insert(track);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Database
|
||||||
|
|
||||||
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* 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 <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <Wt/Dbo/Dbo.h>
|
||||||
|
|
||||||
|
#include <Wt/WDateTime.h>
|
||||||
|
|
||||||
|
#include "Types.hpp"
|
||||||
|
|
||||||
|
namespace Database {
|
||||||
|
|
||||||
|
class Track;
|
||||||
|
class ClusterType;
|
||||||
|
|
||||||
|
class Cluster : public Wt::Dbo::Dbo<Cluster>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef Wt::Dbo::ptr<Cluster> pointer;
|
||||||
|
|
||||||
|
Cluster();
|
||||||
|
Cluster(Wt::Dbo::ptr<ClusterType> type, std::string name);
|
||||||
|
|
||||||
|
// Find utility
|
||||||
|
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
|
||||||
|
static pointer getById(Wt::Dbo::Session& session, IdType id);
|
||||||
|
|
||||||
|
// Create utility
|
||||||
|
static pointer create(Wt::Dbo::Session& session, Wt::Dbo::ptr<ClusterType> type, std::string name);
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
const std::string& getName(void) const { return _name; }
|
||||||
|
Wt::Dbo::ptr<ClusterType> getType() const { return _clusterType; }
|
||||||
|
const Wt::Dbo::collection<Wt::Dbo::ptr<Track>>& getTracks() const { return _tracks; }
|
||||||
|
|
||||||
|
void addTrack(Wt::Dbo::ptr<Track> track);
|
||||||
|
|
||||||
|
template<class Action>
|
||||||
|
void persist(Action& a)
|
||||||
|
{
|
||||||
|
Wt::Dbo::field(a, _name, "name");
|
||||||
|
|
||||||
|
Wt::Dbo::belongsTo(a, _clusterType, "cluster_type", Wt::Dbo::OnDeleteCascade);
|
||||||
|
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToMany, "track_cluster", "", Wt::Dbo::OnDeleteCascade);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static const std::size_t _maxNameLength = 128;
|
||||||
|
|
||||||
|
std::string _name;
|
||||||
|
|
||||||
|
Wt::Dbo::ptr<ClusterType> _clusterType;
|
||||||
|
Wt::Dbo::collection< Wt::Dbo::ptr<Track> > _tracks;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class ClusterType : public Wt::Dbo::Dbo<ClusterType>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using pointer = Wt::Dbo::ptr<ClusterType>;
|
||||||
|
|
||||||
|
ClusterType() {}
|
||||||
|
ClusterType(std::string name);
|
||||||
|
|
||||||
|
static std::vector<pointer> getAllOrphans(Wt::Dbo::Session& session);
|
||||||
|
static pointer getByName(Wt::Dbo::Session& session, std::string name);
|
||||||
|
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
|
||||||
|
|
||||||
|
static pointer create(Wt::Dbo::Session& session, std::string name);
|
||||||
|
static void remove(Wt::Dbo::Session& session, std::string name);
|
||||||
|
|
||||||
|
// Accessors
|
||||||
|
const std::string& getName(void) const { return _name; }
|
||||||
|
std::vector<Cluster::pointer> getClusters() const;
|
||||||
|
Cluster::pointer getCluster(std::string name) const;
|
||||||
|
|
||||||
|
template<class Action>
|
||||||
|
void persist(Action& a)
|
||||||
|
{
|
||||||
|
Wt::Dbo::field(a, _name, "name");
|
||||||
|
Wt::Dbo::hasMany(a, _clusters, Wt::Dbo::ManyToOne, "cluster_type");
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
static const std::size_t _maxNameLength = 128;
|
||||||
|
|
||||||
|
std::string _name;
|
||||||
|
Wt::Dbo::collection< Wt::Dbo::ptr<Cluster> > _clusters;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Database
|
||||||
|
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
|
|
||||||
#include "DbArtist.hpp"
|
#include "DbArtist.hpp"
|
||||||
|
#include "Cluster.hpp"
|
||||||
#include "MediaDirectory.hpp"
|
#include "MediaDirectory.hpp"
|
||||||
#include "Playlist.hpp"
|
#include "Playlist.hpp"
|
||||||
#include "Release.hpp"
|
#include "Release.hpp"
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
|
|
||||||
|
#include "Cluster.hpp"
|
||||||
#include "Release.hpp"
|
#include "Release.hpp"
|
||||||
#include "SqlQuery.hpp"
|
#include "SqlQuery.hpp"
|
||||||
#include "Track.hpp"
|
#include "Track.hpp"
|
||||||
|
|||||||
@@ -23,7 +23,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <Wt/Dbo/Dbo.h>
|
#include <Wt/Dbo/Dbo.h>
|
||||||
#include <Wt/Dbo/QueryModel.h>
|
|
||||||
|
|
||||||
#include "Types.hpp"
|
#include "Types.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@
|
|||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
#include <Wt/Dbo/Dbo.h>
|
#include <Wt/Dbo/Dbo.h>
|
||||||
#include <Wt/Dbo/WtSqlTraits.h>
|
|
||||||
|
|
||||||
namespace Database {
|
namespace Database {
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
#include "Release.hpp"
|
#include "Release.hpp"
|
||||||
|
|
||||||
|
#include "Cluster.hpp"
|
||||||
#include "DbArtist.hpp"
|
#include "DbArtist.hpp"
|
||||||
#include "SqlQuery.hpp"
|
#include "SqlQuery.hpp"
|
||||||
#include "Track.hpp"
|
#include "Track.hpp"
|
||||||
|
|||||||
+3
-96
@@ -19,8 +19,11 @@
|
|||||||
|
|
||||||
#include "Track.hpp"
|
#include "Track.hpp"
|
||||||
|
|
||||||
|
#include <Wt/Dbo/WtSqlTraits.h>
|
||||||
|
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
|
|
||||||
|
#include "Cluster.hpp"
|
||||||
#include "DbArtist.hpp"
|
#include "DbArtist.hpp"
|
||||||
#include "Release.hpp"
|
#include "Release.hpp"
|
||||||
#include "SqlQuery.hpp"
|
#include "SqlQuery.hpp"
|
||||||
@@ -254,101 +257,5 @@ Track::getClusterGroups(std::vector<ClusterType::pointer> clusterTypes, std::siz
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cluster::Cluster()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Cluster::Cluster(Wt::Dbo::ptr<ClusterType> type, std::string name)
|
|
||||||
: _name(std::string(name, 0, _maxNameLength)),
|
|
||||||
_clusterType(type)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Cluster::pointer
|
|
||||||
Cluster::create(Wt::Dbo::Session& session, Wt::Dbo::ptr<ClusterType> type, std::string name)
|
|
||||||
{
|
|
||||||
return session.add(std::make_unique<Cluster>(type, name));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Cluster::pointer>
|
|
||||||
Cluster::getAll(Wt::Dbo::Session& session)
|
|
||||||
{
|
|
||||||
Wt::Dbo::collection<Cluster::pointer> res = session.find<Cluster>();
|
|
||||||
|
|
||||||
return std::vector<Cluster::pointer>(res.begin(), res.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
Cluster::pointer
|
|
||||||
Cluster::getById(Wt::Dbo::Session& session, IdType id)
|
|
||||||
{
|
|
||||||
return session.find<Cluster>().where("id = ?").bind(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
ClusterType::ClusterType(std::string name)
|
|
||||||
: _name(name)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ClusterType::pointer>
|
|
||||||
ClusterType::getAllOrphans(Wt::Dbo::Session& session)
|
|
||||||
{
|
|
||||||
Wt::Dbo::collection<pointer> res = session.query<Wt::Dbo::ptr<ClusterType>>("select c_t from cluster_type c_t LEFT OUTER JOIN cluster c ON c_t.id = c.cluster_type_id WHERE c.id IS NULL");
|
|
||||||
|
|
||||||
return std::vector<pointer>(res.begin(), res.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ClusterType::pointer
|
|
||||||
ClusterType::getByName(Wt::Dbo::Session& session, std::string name)
|
|
||||||
{
|
|
||||||
return session.find<ClusterType>().where("name = ?").bind(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<ClusterType::pointer>
|
|
||||||
ClusterType::getAll(Wt::Dbo::Session& session)
|
|
||||||
{
|
|
||||||
Wt::Dbo::collection<pointer> res = session.find<ClusterType>();
|
|
||||||
|
|
||||||
return std::vector<pointer>(res.begin(), res.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
ClusterType::pointer
|
|
||||||
ClusterType::create(Wt::Dbo::Session& session, std::string name)
|
|
||||||
{
|
|
||||||
return session.add(std::make_unique<ClusterType>(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
Cluster::pointer
|
|
||||||
ClusterType::getCluster(std::string name) const
|
|
||||||
{
|
|
||||||
assert(self());
|
|
||||||
assert(IdIsValid(self()->id()));
|
|
||||||
assert(session());
|
|
||||||
|
|
||||||
return session()->find<Cluster>()
|
|
||||||
.where("name = ?").bind(name)
|
|
||||||
.where("cluster_type_id = ?").bind(self()->id());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Cluster::pointer>
|
|
||||||
ClusterType::getClusters() const
|
|
||||||
{
|
|
||||||
assert(self());
|
|
||||||
assert(IdIsValid(self()->id()));
|
|
||||||
assert(session());
|
|
||||||
|
|
||||||
Wt::Dbo::collection<Cluster::pointer> res = session()->find<Cluster>()
|
|
||||||
.where("cluster_type_id = ?").bind(self()->id())
|
|
||||||
.orderBy("name");
|
|
||||||
|
|
||||||
return std::vector<Cluster::pointer>(res.begin(), res.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
Cluster::addTrack(Wt::Dbo::ptr<Track> track)
|
|
||||||
{
|
|
||||||
_tracks.insert(track);
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Database
|
} // namespace Database
|
||||||
|
|
||||||
|
|||||||
+2
-82
@@ -27,7 +27,6 @@
|
|||||||
#include <boost/optional.hpp>
|
#include <boost/optional.hpp>
|
||||||
|
|
||||||
#include <Wt/Dbo/Dbo.h>
|
#include <Wt/Dbo/Dbo.h>
|
||||||
#include <Wt/Dbo/WtSqlTraits.h>
|
|
||||||
|
|
||||||
#include <Wt/WDateTime.h>
|
#include <Wt/WDateTime.h>
|
||||||
|
|
||||||
@@ -35,91 +34,12 @@
|
|||||||
|
|
||||||
namespace Database {
|
namespace Database {
|
||||||
|
|
||||||
|
|
||||||
class Artist;
|
class Artist;
|
||||||
class Release;
|
class Release;
|
||||||
class Track;
|
|
||||||
class PlaylistEntry;
|
class PlaylistEntry;
|
||||||
|
class Cluster;
|
||||||
class ClusterType;
|
class ClusterType;
|
||||||
|
|
||||||
class Cluster : public Wt::Dbo::Dbo<Cluster>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
typedef Wt::Dbo::ptr<Cluster> pointer;
|
|
||||||
|
|
||||||
Cluster();
|
|
||||||
Cluster(Wt::Dbo::ptr<ClusterType> type, std::string name);
|
|
||||||
|
|
||||||
// Find utility
|
|
||||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
|
|
||||||
static pointer getById(Wt::Dbo::Session& session, IdType id);
|
|
||||||
|
|
||||||
// Create utility
|
|
||||||
static pointer create(Wt::Dbo::Session& session, Wt::Dbo::ptr<ClusterType> type, std::string name);
|
|
||||||
|
|
||||||
// Accessors
|
|
||||||
const std::string& getName(void) const { return _name; }
|
|
||||||
Wt::Dbo::ptr<ClusterType> getType() const { return _clusterType; }
|
|
||||||
const Wt::Dbo::collection<Wt::Dbo::ptr<Track>>& getTracks() const { return _tracks; }
|
|
||||||
|
|
||||||
void addTrack(Wt::Dbo::ptr<Track> track);
|
|
||||||
|
|
||||||
template<class Action>
|
|
||||||
void persist(Action& a)
|
|
||||||
{
|
|
||||||
Wt::Dbo::field(a, _name, "name");
|
|
||||||
|
|
||||||
Wt::Dbo::belongsTo(a, _clusterType, "cluster_type", Wt::Dbo::OnDeleteCascade);
|
|
||||||
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToMany, "track_cluster", "", Wt::Dbo::OnDeleteCascade);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static const std::size_t _maxNameLength = 128;
|
|
||||||
|
|
||||||
std::string _name;
|
|
||||||
|
|
||||||
Wt::Dbo::ptr<ClusterType> _clusterType;
|
|
||||||
Wt::Dbo::collection< Wt::Dbo::ptr<Track> > _tracks;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
class ClusterType : public Wt::Dbo::Dbo<ClusterType>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
using pointer = Wt::Dbo::ptr<ClusterType>;
|
|
||||||
|
|
||||||
ClusterType() {}
|
|
||||||
ClusterType(std::string name);
|
|
||||||
|
|
||||||
static std::vector<pointer> getAllOrphans(Wt::Dbo::Session& session);
|
|
||||||
static pointer getByName(Wt::Dbo::Session& session, std::string name);
|
|
||||||
static std::vector<pointer> getAll(Wt::Dbo::Session& session);
|
|
||||||
|
|
||||||
static pointer create(Wt::Dbo::Session& session, std::string name);
|
|
||||||
static void remove(Wt::Dbo::Session& session, std::string name);
|
|
||||||
|
|
||||||
// Accessors
|
|
||||||
const std::string& getName(void) const { return _name; }
|
|
||||||
std::vector<Cluster::pointer> getClusters() const;
|
|
||||||
Cluster::pointer getCluster(std::string name) const;
|
|
||||||
|
|
||||||
template<class Action>
|
|
||||||
void persist(Action& a)
|
|
||||||
{
|
|
||||||
Wt::Dbo::field(a, _name, "name");
|
|
||||||
Wt::Dbo::hasMany(a, _clusters, Wt::Dbo::ManyToOne, "cluster_type");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
static const std::size_t _maxNameLength = 128;
|
|
||||||
|
|
||||||
std::string _name;
|
|
||||||
Wt::Dbo::collection< Wt::Dbo::ptr<Cluster> > _clusters;
|
|
||||||
};
|
|
||||||
|
|
||||||
class Track : public Wt::Dbo::Dbo<Track>
|
class Track : public Wt::Dbo::Dbo<Track>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -194,7 +114,7 @@ class Track : public Wt::Dbo::Dbo<Track>
|
|||||||
const std::string& getMBID(void) const { return _MBID; }
|
const std::string& getMBID(void) const { return _MBID; }
|
||||||
Wt::Dbo::ptr<Artist> getArtist(void) const { return _artist; }
|
Wt::Dbo::ptr<Artist> getArtist(void) const { return _artist; }
|
||||||
Wt::Dbo::ptr<Release> getRelease(void) const { return _release; }
|
Wt::Dbo::ptr<Release> getRelease(void) const { return _release; }
|
||||||
std::vector< Cluster::pointer > getClusters(void) const;
|
std::vector<Wt::Dbo::ptr<Cluster>> getClusters(void) const;
|
||||||
|
|
||||||
std::vector<std::vector<Wt::Dbo::ptr<Cluster>>> getClusterGroups(std::vector<Wt::Dbo::ptr<ClusterType>> clusterTypes, std::size_t size) const;
|
std::vector<std::vector<Wt::Dbo::ptr<Cluster>>> getClusterGroups(std::vector<Wt::Dbo::ptr<ClusterType>> clusterTypes, std::size_t size) const;
|
||||||
|
|
||||||
|
|||||||
+104
-108
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "cover/CoverArtGrabber.hpp"
|
#include "cover/CoverArtGrabber.hpp"
|
||||||
|
|
||||||
|
#include "database/Cluster.hpp"
|
||||||
#include "database/DbArtist.hpp"
|
#include "database/DbArtist.hpp"
|
||||||
#include "database/Release.hpp"
|
#include "database/Release.hpp"
|
||||||
#include "database/MediaDirectory.hpp"
|
#include "database/MediaDirectory.hpp"
|
||||||
@@ -38,6 +39,8 @@
|
|||||||
#include "utils/Path.hpp"
|
#include "utils/Path.hpp"
|
||||||
#include "utils/Utils.hpp"
|
#include "utils/Utils.hpp"
|
||||||
|
|
||||||
|
using namespace Database;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
const std::string updatePeriodSetting = "update_period";
|
const std::string updatePeriodSetting = "update_period";
|
||||||
@@ -114,13 +117,108 @@ isPathInParentPath(const boost::filesystem::path& path, const boost::filesystem:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Artist::pointer
|
||||||
|
getArtist(Wt::Dbo::Session& session, const std::string& name, const std::string& mbid)
|
||||||
|
{
|
||||||
|
Artist::pointer artist;
|
||||||
|
|
||||||
|
// First try to get by MBID
|
||||||
|
if (!mbid.empty())
|
||||||
|
{
|
||||||
|
artist = Artist::getByMBID(session, mbid);
|
||||||
|
if (!artist)
|
||||||
|
artist = Artist::create(session, name, mbid);
|
||||||
|
|
||||||
|
return artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back on artist name (collisions may occur)
|
||||||
|
if (!name.empty())
|
||||||
|
{
|
||||||
|
for (Artist::pointer sameNamedArtist : Artist::getByName(session, name))
|
||||||
|
{
|
||||||
|
if (sameNamedArtist->getMBID().empty())
|
||||||
|
{
|
||||||
|
artist = sameNamedArtist;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No Artist found with the same name and without MBID -> creating
|
||||||
|
if (!artist)
|
||||||
|
artist = Artist::create(session, name);
|
||||||
|
|
||||||
|
return artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Artist::pointer();
|
||||||
|
}
|
||||||
|
|
||||||
|
Release::pointer
|
||||||
|
getRelease(Wt::Dbo::Session& session, const std::string& name, const std::string& mbid)
|
||||||
|
{
|
||||||
|
Release::pointer release;
|
||||||
|
|
||||||
|
// First try to get by MBID
|
||||||
|
if (!mbid.empty())
|
||||||
|
{
|
||||||
|
release = Release::getByMBID(session, mbid );
|
||||||
|
if (!release)
|
||||||
|
release = Release::create(session, name, mbid);
|
||||||
|
|
||||||
|
return release;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back on release name (collisions may occur)
|
||||||
|
if (!name.empty())
|
||||||
|
{
|
||||||
|
for (Release::pointer sameNamedRelease : Release::getByName(session, name))
|
||||||
|
{
|
||||||
|
if (sameNamedRelease->getMBID().empty())
|
||||||
|
{
|
||||||
|
release = sameNamedRelease;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// No release found with the same name and without MBID -> creating
|
||||||
|
if (!release)
|
||||||
|
release = Release::create(session, name);
|
||||||
|
|
||||||
|
return release;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Release::pointer();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Cluster::pointer>
|
||||||
|
getClusters(Wt::Dbo::Session& session, const MetaData::Clusters& clustersNames)
|
||||||
|
{
|
||||||
|
std::vector< Cluster::pointer > clusters;
|
||||||
|
|
||||||
|
for (auto clusterNames : clustersNames)
|
||||||
|
{
|
||||||
|
auto clusterType = ClusterType::getByName(session, clusterNames.first);
|
||||||
|
if (!clusterType)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (auto clusterName : clusterNames.second)
|
||||||
|
{
|
||||||
|
auto cluster = clusterType->getCluster(clusterName);
|
||||||
|
if (!cluster)
|
||||||
|
cluster = Cluster::create(session, clusterType, clusterName);
|
||||||
|
|
||||||
|
clusters.push_back(cluster);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return clusters;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
||||||
namespace Scanner {
|
namespace Scanner {
|
||||||
|
|
||||||
using namespace Database;
|
|
||||||
|
|
||||||
UpdatePeriod
|
UpdatePeriod
|
||||||
getUpdatePeriod(Wt::Dbo::Session& session)
|
getUpdatePeriod(Wt::Dbo::Session& session)
|
||||||
{
|
{
|
||||||
@@ -345,104 +443,6 @@ MediaScanner::refreshScanSettings()
|
|||||||
_metadataParser.updateClusterTypes(getClusterTypes(_db.getSession()));
|
_metadataParser.updateClusterTypes(getClusterTypes(_db.getSession()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Artist::pointer
|
|
||||||
MediaScanner::getArtist( const boost::filesystem::path& file, const std::string& name, const std::string& mbid)
|
|
||||||
{
|
|
||||||
Artist::pointer artist;
|
|
||||||
|
|
||||||
// First try to get by MBID
|
|
||||||
if (!mbid.empty())
|
|
||||||
{
|
|
||||||
artist = Artist::getByMBID( _db.getSession(), mbid );
|
|
||||||
if (!artist)
|
|
||||||
artist = Artist::create( _db.getSession(), name, mbid);
|
|
||||||
|
|
||||||
return artist;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back on artist name (collisions may occur)
|
|
||||||
if (!name.empty())
|
|
||||||
{
|
|
||||||
for (Artist::pointer sameNamedArtist : Artist::getByName( _db.getSession(), name ))
|
|
||||||
{
|
|
||||||
if (sameNamedArtist->getMBID().empty())
|
|
||||||
{
|
|
||||||
artist = sameNamedArtist;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// No Artist found with the same name and without MBID -> creating
|
|
||||||
if (!artist)
|
|
||||||
artist = Artist::create( _db.getSession(), name);
|
|
||||||
|
|
||||||
return artist;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Artist::pointer();
|
|
||||||
}
|
|
||||||
|
|
||||||
Release::pointer
|
|
||||||
MediaScanner::getRelease( const boost::filesystem::path& file, const std::string& name, const std::string& mbid)
|
|
||||||
{
|
|
||||||
Release::pointer release;
|
|
||||||
|
|
||||||
// First try to get by MBID
|
|
||||||
if (!mbid.empty())
|
|
||||||
{
|
|
||||||
release = Release::getByMBID( _db.getSession(), mbid );
|
|
||||||
if (!release)
|
|
||||||
release = Release::create( _db.getSession(), name, mbid);
|
|
||||||
|
|
||||||
return release;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back on release name (collisions may occur)
|
|
||||||
if (!name.empty())
|
|
||||||
{
|
|
||||||
for (Release::pointer sameNamedRelease : Release::getByName( _db.getSession(), name ))
|
|
||||||
{
|
|
||||||
if (sameNamedRelease->getMBID().empty())
|
|
||||||
{
|
|
||||||
release = sameNamedRelease;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// No release found with the same name and without MBID -> creating
|
|
||||||
if (!release)
|
|
||||||
release = Release::create( _db.getSession(), name);
|
|
||||||
|
|
||||||
return release;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Release::pointer();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Cluster::pointer>
|
|
||||||
MediaScanner::getClusters( const MetaData::Clusters& clustersNames)
|
|
||||||
{
|
|
||||||
std::vector< Cluster::pointer > clusters;
|
|
||||||
|
|
||||||
for (auto clusterNames : clustersNames)
|
|
||||||
{
|
|
||||||
auto clusterType = ClusterType::getByName(_db.getSession(), clusterNames.first);
|
|
||||||
if (!clusterType)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
for (auto clusterName : clusterNames.second)
|
|
||||||
{
|
|
||||||
auto cluster = clusterType->getCluster(clusterName);
|
|
||||||
if (!cluster)
|
|
||||||
cluster = Cluster::create(_db.getSession(), clusterType, clusterName);
|
|
||||||
|
|
||||||
clusters.push_back(cluster);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return clusters;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan, Stats& stats)
|
MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan, Stats& stats)
|
||||||
{
|
{
|
||||||
@@ -535,8 +535,7 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
|
|||||||
clusterNames = boost::any_cast<MetaData::Clusters> ((*items)[MetaData::Type::Clusters]);
|
clusterNames = boost::any_cast<MetaData::Clusters> ((*items)[MetaData::Type::Clusters]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO rename
|
genres = getClusters(_db.getSession(), clusterNames);
|
||||||
genres = getClusters( clusterNames );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***** Artist
|
// ***** Artist
|
||||||
@@ -551,7 +550,7 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
|
|||||||
if ((*items).find(MetaData::Type::Artist) != (*items).end())
|
if ((*items).find(MetaData::Type::Artist) != (*items).end())
|
||||||
artistName = boost::any_cast<std::string>((*items)[MetaData::Type::Artist]);
|
artistName = boost::any_cast<std::string>((*items)[MetaData::Type::Artist]);
|
||||||
|
|
||||||
artist = getArtist(file, artistName, artistMusicBrainzID);
|
artist = getArtist(_db.getSession(), artistName, artistMusicBrainzID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ***** Release
|
// ***** Release
|
||||||
@@ -566,7 +565,7 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
|
|||||||
if ((*items).find(MetaData::Type::Album) != (*items).end())
|
if ((*items).find(MetaData::Type::Album) != (*items).end())
|
||||||
releaseName = boost::any_cast<std::string>((*items)[MetaData::Type::Album]);
|
releaseName = boost::any_cast<std::string>((*items)[MetaData::Type::Album]);
|
||||||
|
|
||||||
release = getRelease(file, releaseName, releaseMusicBrainzID);
|
release = getRelease(_db.getSession(), releaseName, releaseMusicBrainzID);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If file already exist, update data
|
// If file already exist, update data
|
||||||
@@ -650,9 +649,6 @@ MediaScanner::scanAudioFile(const boost::filesystem::path& file, bool forceScan,
|
|||||||
track.modify()->setCoverType( hasCover ? Track::CoverType::Embedded : Track::CoverType::None );
|
track.modify()->setCoverType( hasCover ? Track::CoverType::Embedded : Track::CoverType::None );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO check added/modified
|
|
||||||
_sigAddedTrack.emit(track);
|
|
||||||
|
|
||||||
transaction.commit();
|
transaction.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,6 @@
|
|||||||
#include "metadata/TagLibParser.hpp"
|
#include "metadata/TagLibParser.hpp"
|
||||||
|
|
||||||
#include "database/DatabaseHandler.hpp"
|
#include "database/DatabaseHandler.hpp"
|
||||||
#include "database/Track.hpp"
|
|
||||||
#include "database/DbArtist.hpp"
|
|
||||||
#include "database/Release.hpp"
|
|
||||||
|
|
||||||
namespace Scanner {
|
namespace Scanner {
|
||||||
|
|
||||||
@@ -83,16 +80,6 @@ class MediaScanner
|
|||||||
std::size_t nbDuplicates() const { return duplicateHashes + duplicateMBID; }
|
std::size_t nbDuplicates() const { return duplicateHashes + duplicateMBID; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Called just after track addition
|
|
||||||
Wt::Signal<Database::Track::pointer>& addedTrack() { return _sigAddedTrack; }
|
|
||||||
|
|
||||||
// Called just before track removal
|
|
||||||
Wt::Signal<Database::Track::pointer>& removedTrack() { return _sigRemovedTrack; }
|
|
||||||
|
|
||||||
// Called just after track modification
|
|
||||||
Wt::Signal<Database::Track::pointer>& modifiedTrack() { return _sigModifiedTrack; }
|
|
||||||
|
|
||||||
// Called just after scan complete
|
// Called just after scan complete
|
||||||
Wt::Signal<Stats>& scanComplete() { return _sigScanComplete; }
|
Wt::Signal<Stats>& scanComplete() { return _sigScanComplete; }
|
||||||
|
|
||||||
@@ -109,9 +96,6 @@ class MediaScanner
|
|||||||
void scanRootDirectory( boost::filesystem::path rootDirectory, bool forceScan, Stats& stats);
|
void scanRootDirectory( boost::filesystem::path rootDirectory, bool forceScan, Stats& stats);
|
||||||
|
|
||||||
// Helpers
|
// Helpers
|
||||||
Database::Artist::pointer getArtist( const boost::filesystem::path& file, const std::string& name, const std::string& MBID);
|
|
||||||
Database::Release::pointer getRelease( const boost::filesystem::path& file, const std::string& name, const std::string& MBID);
|
|
||||||
std::vector<Database::Cluster::pointer> getClusters( const MetaData::Clusters& names);
|
|
||||||
void refreshScanSettings();
|
void refreshScanSettings();
|
||||||
|
|
||||||
void checkAudioFiles( Stats& stats );
|
void checkAudioFiles( Stats& stats );
|
||||||
@@ -123,9 +107,6 @@ class MediaScanner
|
|||||||
Wt::WIOService _ioService;
|
Wt::WIOService _ioService;
|
||||||
|
|
||||||
Wt::Signal<Stats> _sigScanComplete;
|
Wt::Signal<Stats> _sigScanComplete;
|
||||||
Wt::Signal<Database::Track::pointer> _sigModifiedTrack;
|
|
||||||
Wt::Signal<Database::Track::pointer> _sigAddedTrack;
|
|
||||||
Wt::Signal<Database::Track::pointer> _sigRemovedTrack;
|
|
||||||
|
|
||||||
boost::asio::system_timer _scheduleTimer;
|
boost::asio::system_timer _scheduleTimer;
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,10 @@
|
|||||||
#include "database/DatabaseHandler.hpp"
|
#include "database/DatabaseHandler.hpp"
|
||||||
#include "scanner/MediaScanner.hpp"
|
#include "scanner/MediaScanner.hpp"
|
||||||
|
|
||||||
|
#include "database/Cluster.hpp"
|
||||||
|
#include "database/DbArtist.hpp"
|
||||||
|
#include "database/Release.hpp"
|
||||||
|
|
||||||
#include "Auth.hpp"
|
#include "Auth.hpp"
|
||||||
|
|
||||||
namespace UserInterface {
|
namespace UserInterface {
|
||||||
|
|||||||
@@ -24,6 +24,9 @@
|
|||||||
#include "av/AvInfo.hpp"
|
#include "av/AvInfo.hpp"
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
|
|
||||||
|
#include "database/Track.hpp"
|
||||||
|
|
||||||
|
|
||||||
#include "resource/ImageResource.hpp"
|
#include "resource/ImageResource.hpp"
|
||||||
#include "resource/TranscodeResource.hpp"
|
#include "resource/TranscodeResource.hpp"
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "database/Track.hpp"
|
#include "database/Cluster.hpp"
|
||||||
|
|
||||||
namespace UserInterface {
|
namespace UserInterface {
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "database/Release.hpp"
|
#include "database/Release.hpp"
|
||||||
#include "database/Setting.hpp"
|
#include "database/Setting.hpp"
|
||||||
|
#include "database/Track.hpp"
|
||||||
|
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
#include "utils/Utils.hpp"
|
#include "utils/Utils.hpp"
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
#include "utils/Utils.hpp"
|
#include "utils/Utils.hpp"
|
||||||
|
|
||||||
|
#include "database/Track.hpp"
|
||||||
|
|
||||||
#include "LmsApplication.hpp"
|
#include "LmsApplication.hpp"
|
||||||
|
|
||||||
#include "cover/CoverArtGrabber.hpp"
|
#include "cover/CoverArtGrabber.hpp"
|
||||||
|
|||||||
@@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
#include "utils/Logger.hpp"
|
#include "utils/Logger.hpp"
|
||||||
|
|
||||||
|
#include "database/Track.hpp"
|
||||||
|
|
||||||
#include "LmsApplication.hpp"
|
#include "LmsApplication.hpp"
|
||||||
|
|
||||||
namespace UserInterface {
|
namespace UserInterface {
|
||||||
|
|||||||
Reference in New Issue
Block a user