WIP. Restoring video playback
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
|
||||
// Db types
|
||||
#include "AudioTypes.hpp"
|
||||
#include "FileTypes.hpp"
|
||||
#include "VideoTypes.hpp"
|
||||
#include "MediaDirectory.hpp"
|
||||
#include "User.hpp"
|
||||
|
||||
@@ -67,7 +67,6 @@ _dbBackend( db.string() )
|
||||
_session.mapClass<Database::Artist>("artist");
|
||||
_session.mapClass<Database::Release>("release");
|
||||
_session.mapClass<Database::Release>("release");
|
||||
_session.mapClass<Database::Path>("path");
|
||||
_session.mapClass<Database::Video>("video");
|
||||
_session.mapClass<Database::MediaDirectory>("media_directory");
|
||||
_session.mapClass<Database::MediaDirectorySettings>("media_directory_settings");
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
#ifndef DATABASE_FILE_TYPES_HPP
|
||||
#define DATABASE_FILE_TYPES_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <Wt/Dbo/Dbo>
|
||||
#include <Wt/Dbo/WtSqlTraits>
|
||||
|
||||
#include <Wt/WDateTime>
|
||||
|
||||
#include "VideoTypes.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
class Path
|
||||
{
|
||||
public:
|
||||
|
||||
typedef Wt::Dbo::ptr<Path> pointer;
|
||||
|
||||
Path();
|
||||
Path(boost::filesystem::path p);
|
||||
|
||||
// utility
|
||||
static pointer create(Wt::Dbo::Session& session, boost::filesystem::path p);
|
||||
static pointer create(Wt::Dbo::Session& session, boost::filesystem::path p, Path::pointer parent);
|
||||
static pointer getByPath(Wt::Dbo::Session& session, boost::filesystem::path p);
|
||||
static std::vector< pointer > getRoots(Wt::Dbo::Session& session); // get root pathes (no parent!)
|
||||
|
||||
// Modifiers
|
||||
void addChild( pointer child );
|
||||
void setLastWriteTime(boost::posix_time::ptime time) { _fileLastWrite = time; }
|
||||
void setChecksum(const std::vector<unsigned char>& checksum) { _fileChecksum = checksum; }
|
||||
void setCreationTime(const boost::posix_time::ptime& time) { _creationTime = time; }
|
||||
|
||||
// Accessors
|
||||
std::string getFileName(void) const;
|
||||
boost::filesystem::path getPath(void) const {return boost::filesystem::path(_filePath);}
|
||||
bool isDirectory() const {return _isDirectory;}
|
||||
std::vector< pointer > getChilds() const;
|
||||
pointer getParent() const;
|
||||
boost::posix_time::ptime getLastWriteTime(void) const { return _fileLastWrite; }
|
||||
const std::vector<unsigned char>& getChecksum(void) const { return _fileChecksum; }
|
||||
Wt::Dbo::ptr<Video> getVideo();
|
||||
const Wt::Dbo::ptr<Video> getVideo() const;
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
Wt::Dbo::field(a, _filePath, "path");
|
||||
Wt::Dbo::field(a, _isDirectory, "directory");
|
||||
Wt::Dbo::field(a, _creationTime, "creation_time");
|
||||
Wt::Dbo::field(a, _fileLastWrite, "last_write");
|
||||
Wt::Dbo::field(a, _fileChecksum, "checksum");
|
||||
Wt::Dbo::hasMany(a, _childPathes, Wt::Dbo::ManyToMany, "path_path", "child_path_id");
|
||||
Wt::Dbo::hasMany(a, _parentPathes, Wt::Dbo::ManyToMany, "path_path", "parent_path_id");
|
||||
Wt::Dbo::hasMany(a, _video, Wt::Dbo::ManyToOne, "path");
|
||||
}
|
||||
private:
|
||||
|
||||
std::string _filePath;
|
||||
bool _isDirectory;
|
||||
boost::posix_time::ptime _creationTime;
|
||||
std::vector<unsigned char> _fileChecksum;
|
||||
boost::posix_time::ptime _fileLastWrite;
|
||||
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<Video> > _video;
|
||||
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<Path> > _childPathes; // Child pathes
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<Path> > _parentPathes; // Parent pathes
|
||||
|
||||
};
|
||||
|
||||
} // namespace Database
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
|
||||
#include "FileTypes.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
Path::Path()
|
||||
{}
|
||||
|
||||
Path::Path(boost::filesystem::path p)
|
||||
: _filePath (p.string()),
|
||||
_isDirectory( boost::filesystem::is_directory( _filePath ) )
|
||||
{}
|
||||
|
||||
Path::pointer
|
||||
Path::create(Wt::Dbo::Session& session, boost::filesystem::path p)
|
||||
{
|
||||
return session.add(new Path(p));
|
||||
}
|
||||
|
||||
Path::pointer
|
||||
Path::create(Wt::Dbo::Session& session, boost::filesystem::path p, Path::pointer parent)
|
||||
{
|
||||
Path::pointer res = session.add(new Path(p));
|
||||
if (parent)
|
||||
parent.modify()->addChild( res );
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
Path::addChild( pointer child)
|
||||
{
|
||||
_childPathes.insert(child);
|
||||
}
|
||||
|
||||
Path::pointer
|
||||
Path::getByPath(Wt::Dbo::Session& session, boost::filesystem::path p)
|
||||
{
|
||||
return session.find<Path>().where("path = ?").bind( p.string() );
|
||||
}
|
||||
|
||||
std::vector<Path::pointer>
|
||||
Path::getChilds(void) const
|
||||
{
|
||||
std::vector< pointer > childs;
|
||||
|
||||
// Get childs in another way: order by type then name
|
||||
Wt::Dbo::Query< Path::pointer> query = _childPathes.find().orderBy("path.directory DESC, path.path");
|
||||
Wt::Dbo::collection< Path::pointer > res = query.resultList();
|
||||
|
||||
std::copy( res.begin(), res.end(), std::back_inserter( childs ));
|
||||
return childs;
|
||||
}
|
||||
|
||||
Path::pointer
|
||||
Path::getParent(void) const
|
||||
{
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<Path> >::const_iterator it = _parentPathes.begin();
|
||||
return it != _parentPathes.end() ? *it : Path::pointer();
|
||||
}
|
||||
|
||||
std::vector<Path::pointer>
|
||||
Path::getRoots(Wt::Dbo::Session& session)
|
||||
{
|
||||
std::vector<pointer> roots;
|
||||
|
||||
typedef Wt::Dbo::collection< pointer > Pathes;
|
||||
|
||||
Pathes pathes = session.find<Path>();
|
||||
|
||||
for (Pathes::const_iterator it = pathes.begin(); it != pathes.end(); ++it)
|
||||
{
|
||||
if (!(*it)->getParent())
|
||||
{
|
||||
std::cout << "path '" << (*it)->getPath() << "' has no parent!" << std::endl;
|
||||
roots.push_back( *it );
|
||||
}
|
||||
}
|
||||
|
||||
return roots;
|
||||
}
|
||||
|
||||
Wt::Dbo::ptr<Video>
|
||||
Path::getVideo()
|
||||
{
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<Video> >::const_iterator it = _video.begin();
|
||||
return it != _video.end() ? *it : Wt::Dbo::ptr<Video>();
|
||||
}
|
||||
|
||||
const Wt::Dbo::ptr<Video>
|
||||
Path::getVideo() const
|
||||
{
|
||||
Wt::Dbo::collection< Wt::Dbo::ptr<Video> >::const_iterator it = _video.begin();
|
||||
return it != _video.end() ? *it : Wt::Dbo::ptr<Video>();
|
||||
}
|
||||
|
||||
std::string
|
||||
Path::getFileName(void) const
|
||||
{
|
||||
if (isDirectory())
|
||||
return boost::filesystem::path(_filePath).string();
|
||||
else
|
||||
return boost::filesystem::path(_filePath).filename().string();
|
||||
}
|
||||
|
||||
} // namespace Database
|
||||
+16
-6
@@ -1,22 +1,32 @@
|
||||
#include "VideoTypes.hpp"
|
||||
|
||||
#include "FileTypes.hpp"
|
||||
|
||||
namespace Database {
|
||||
|
||||
Video::Video()
|
||||
{
|
||||
}
|
||||
|
||||
Video::Video(Wt::Dbo::ptr<Path> path)
|
||||
: _path(path)
|
||||
Video::Video(const boost::filesystem::path& p)
|
||||
: _filePath(p.string())
|
||||
{
|
||||
}
|
||||
|
||||
Video::pointer
|
||||
Video::create(Wt::Dbo::Session& session, Wt::Dbo::ptr<Path> path)
|
||||
Video::create(Wt::Dbo::Session& session, const boost::filesystem::path& p)
|
||||
{
|
||||
return session.add(new Video(path));
|
||||
return session.add(new Video(p));
|
||||
}
|
||||
|
||||
Wt::Dbo::collection< Video::pointer >
|
||||
Video::getAll(Wt::Dbo::Session& session)
|
||||
{
|
||||
return session.find<Video>();
|
||||
}
|
||||
|
||||
Video::pointer
|
||||
Video::getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p)
|
||||
{
|
||||
return session.find<Video>().where("path = ?").bind(p.string());
|
||||
}
|
||||
|
||||
} // namespace Video
|
||||
|
||||
+12
-9
@@ -12,8 +12,6 @@
|
||||
|
||||
namespace Database {
|
||||
|
||||
class Path;
|
||||
|
||||
class Video
|
||||
{
|
||||
public:
|
||||
@@ -21,37 +19,42 @@ class Video
|
||||
typedef Wt::Dbo::ptr<Video> pointer;
|
||||
|
||||
Video();
|
||||
Video( Wt::Dbo::ptr<Path> path);
|
||||
Video( const boost::filesystem::path& p);
|
||||
|
||||
// Find utilities
|
||||
static pointer getByPath(Wt::Dbo::Session& session, Wt::Dbo::ptr<Path> path);
|
||||
static pointer getByPath(Wt::Dbo::Session& session, const boost::filesystem::path& p);
|
||||
static Wt::Dbo::collection< pointer > getAll(Wt::Dbo::Session& session);
|
||||
static Wt::Dbo::collection< pointer > getByParentPath(Wt::Dbo::Session& session, const boost::filesystem::path& p);
|
||||
|
||||
// Create utility
|
||||
static pointer create(Wt::Dbo::Session& session, Wt::Dbo::ptr<Path> path);
|
||||
static pointer create(Wt::Dbo::Session& session, const boost::filesystem::path& p);
|
||||
|
||||
// Modifiers
|
||||
void setName(const std::string& name) { _name = name; }
|
||||
void setDuration(boost::posix_time::time_duration duration) { _duration = duration; }
|
||||
void setLastWriteTime(boost::posix_time::ptime time) { _fileLastWrite = time; }
|
||||
|
||||
// Accessors
|
||||
std::string getName(void) const { return _name; }
|
||||
Wt::Dbo::ptr<Path> getPath(void) { return _path; }
|
||||
std::string getName(void) const { return _name; }
|
||||
boost::posix_time::time_duration getDuration(void) const { return _duration; }
|
||||
boost::filesystem::path getPath(void) const { return _filePath; }
|
||||
boost::posix_time::ptime getLastWriteTime(void) const { return _fileLastWrite; }
|
||||
|
||||
template<class Action>
|
||||
void persist(Action& a)
|
||||
{
|
||||
Wt::Dbo::field(a, _name, "name");
|
||||
Wt::Dbo::field(a, _duration, "duration");
|
||||
Wt::Dbo::belongsTo(a, _path, "path");
|
||||
Wt::Dbo::field(a, _fileLastWrite, "last_write");
|
||||
Wt::Dbo::field(a, _filePath, "path");
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Wt::Dbo::ptr<Path> _path;
|
||||
std::string _name;
|
||||
boost::posix_time::time_duration _duration;
|
||||
std::string _filePath;
|
||||
boost::posix_time::ptime _fileLastWrite;
|
||||
|
||||
}; // Video
|
||||
|
||||
|
||||
Reference in New Issue
Block a user