From 614cffc5c13f72002db64140583d5c47f4984266 Mon Sep 17 00:00:00 2001 From: emeric Date: Tue, 9 Sep 2014 14:06:44 +0200 Subject: [PATCH] WIP. Restoring video playback --- Makefile.am | 1 - TODO | 2 +- config/ConfigReader.cpp | 2 +- database-updater/DatabaseUpdater.cpp | 168 ++++++++++----------------- database-updater/DatabaseUpdater.hpp | 8 +- database/DatabaseHandler.cpp | 3 +- database/FileTypes.hpp | 79 ------------- database/Path.cpp | 105 ----------------- database/Video.cpp | 22 +++- database/VideoTypes.hpp | 21 ++-- ui/video/VideoDatabaseWidget.cpp | 117 ++++++++----------- ui/video/VideoDatabaseWidget.hpp | 10 +- 12 files changed, 152 insertions(+), 386 deletions(-) delete mode 100644 database/FileTypes.hpp delete mode 100644 database/Path.cpp diff --git a/Makefile.am b/Makefile.am index 5834e424..731ca6d9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,6 @@ lms_SOURCES = \ $(top_srcdir)/database/Track.cpp \ $(top_srcdir)/database/DatabaseHandler.cpp \ $(top_srcdir)/database/SqlQuery.cpp \ - $(top_srcdir)/database/Path.cpp \ $(top_srcdir)/database/Video.cpp \ $(top_srcdir)/database/User.cpp \ $(top_srcdir)/database-updater/DatabaseUpdater.cpp \ diff --git a/TODO b/TODO index 25ee53c1..6a42e481 100644 --- a/TODO +++ b/TODO @@ -19,8 +19,8 @@ - Implement a video database cleanup - Group videos in "video groups". Each video may has sub groups (current "Path" class) -> Simplify the database and remove the Path class -- Process only files whose extensions are well known in audio/video world (avoid useless parsing/errors)? - make a default admin/admin account of the very first connection? +- count scan import errors [Metadata] diff --git a/config/ConfigReader.cpp b/config/ConfigReader.cpp index b8310b5d..a3875cf6 100644 --- a/config/ConfigReader.cpp +++ b/config/ConfigReader.cpp @@ -71,7 +71,7 @@ ConfigReader::getDatabaseUpdateConfig(Service::DatabaseUpdateService::Config& co config.dbPath = _config.lookup("main.database.path"); std::string audioExtensions = _config.lookup("main.database.audio_extensions"); - std::string videoExtensions = _config.lookup("main.database.audio_extensions"); + std::string videoExtensions = _config.lookup("main.database.video_extensions"); splitStrings(audioExtensions, config.audioExtensions); splitStrings(videoExtensions, config.videoExtensions); diff --git a/database-updater/DatabaseUpdater.cpp b/database-updater/DatabaseUpdater.cpp index b32f118a..49f48a93 100644 --- a/database-updater/DatabaseUpdater.cpp +++ b/database-updater/DatabaseUpdater.cpp @@ -8,6 +8,7 @@ #include "database/MediaDirectory.hpp" #include "database/AudioTypes.hpp" +#include "database/VideoTypes.hpp" #include "Checksum.hpp" #include "DatabaseUpdater.hpp" @@ -200,8 +201,7 @@ Updater::process(boost::system::error_code err) Stats stats; checkAudioFiles(stats); - // TODO video files - + checkVideoFiles(stats); typedef std::pair RootDirectory; std::vector rootDirectories; @@ -289,6 +289,7 @@ Updater::processAudioFile( const boost::filesystem::path& file, Stats& stats) return; } + // ***** Title std::string title; if (items.find(MetaData::Title) != items.end()) { title = boost::any_cast(items[MetaData::Title]); @@ -436,7 +437,8 @@ Updater::processDirectory(const boost::filesystem::path& rootDirectory, break; case Database::MediaDirectory::Video: -// processVideoFile( rootDirectory, *itPath, stats); + if (isFileSupported(*itPath, _videoExtensions)) + processVideoFile( *itPath, stats); break; } } @@ -549,70 +551,33 @@ Updater::checkAudioFiles( Stats& stats ) LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Check audio files done!"; } -Path::pointer -Updater::getAddPath(const boost::filesystem::path& path) -{ - Path::pointer res; - Path::pointer parentDirectory; - - if (path.has_parent_path()) - parentDirectory = Path::getByPath(_db.getSession(), path.parent_path()); - - res = Path::getByPath(_db.getSession(), path); - if (!res) - res = Path::create(_db.getSession(), path, parentDirectory); - else - { - // Make sure the parent directory owns the child - if (parentDirectory && !res->getParent()) - parentDirectory.modify()->addChild( res ); - } - - return res; -} - - -/*void -Updater::refreshVideoDirectory( const boost::filesystem::path& path) -{ - LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Refreshing video directory " << path; - if (boost::filesystem::exists(path) && boost::filesystem::is_directory(path)) - { - - // Add this directory in the database - { - Wt::Dbo::Transaction transaction(_db.getSession()); - - Path::pointer pathDirectory = getAddPath(path); - assert( pathDirectory->isDirectory() ); - - transaction.commit(); - } - - // Now process all files/dirs in directory - typedef std::vector Paths; // store paths, - - Paths pathChildren; - std::copy(boost::filesystem::directory_iterator(path), boost::filesystem::directory_iterator(), std::back_inserter(pathChildren)); - - BOOST_FOREACH(const boost::filesystem::path& pathChild, pathChildren) { - - if (boost::filesystem::is_directory(pathChild)) { - refreshVideoDirectory( pathChild ); - } - else if (boost::filesystem::is_regular(pathChild)) { - processVideoFile( pathChild ); - } - else { - LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Skipped '" << pathChild << "' (not regular)"; - } - } - } - LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Refreshing video directory " << path << ": DONE"; -}*/ -/* void -Updater::processVideoFile( const boost::filesystem::path& file) +Updater::checkVideoFiles( Stats& stats ) +{ + LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking video files..."; + Wt::Dbo::Transaction transaction(_db.getSession()); + + std::vector rootDirs = getRootDirectoriesByType(_db.getSession(), Database::MediaDirectory::Video); + + LMS_LOG(MOD_DBUPDATER, SEV_DEBUG) << "Checking videos..."; + typedef Wt::Dbo::collection< Wt::Dbo::ptr