Commit 68abcae2 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Reintroduce onFileAdded & ensure the file has a type when its added to the ML

The file is initially determined as a best guess
This also remove images from supported extensions
parent a955a5dc
......@@ -13,8 +13,16 @@ class IMediaLibraryCb
public:
virtual ~IMediaLibraryCb() = default;
/**
* @brief onMetadataUpdated Will be called when a file gets added, or if its metadata
* got updated.
* @brief onFileAdded Will be called when a file gets added.
* Depending if the file is being restored or was just discovered,
* the file type might be a best effort guess. If the file was freshly
* discovered, it is extremely likely that no metadata will be
* available yet.
* @param file
*/
virtual void onFileAdded( FilePtr file ) = 0;
/**
* @brief onFileUpdated Will be called when a file metadata gets updated.
* @param file The updated file.
*/
virtual void onFileUpdated( FilePtr file ) = 0;
......
......@@ -28,15 +28,16 @@
#include "filesystem/IFile.h"
#include "factory/FileSystem.h"
const std::vector<std::string> MediaLibrary::supportedExtensions {
const std::vector<std::string> MediaLibrary::supportedVideoExtensions {
// Videos
"avi", "3gp", "amv", "asf", "divx", "dv", "flv", "gxf",
"iso", "m1v", "m2v", "m2t", "m2ts", "m4v", "mkv", "mov",
"mp2", "mp4", "mpeg", "mpeg1", "mpeg2", "mpeg4", "mpg",
"mts", "mxf", "nsv", "nuv", "ogg", "ogm", "ogv", "ogx", "ps",
"rec", "rm", "rmvb", "tod", "ts", "vob", "vro", "webm", "wmv",
// Images
"png", "jpg", "jpeg",
"rec", "rm", "rmvb", "tod", "ts", "vob", "vro", "webm", "wmv"
};
const std::vector<std::string> MediaLibrary::supportedAudioExtensions {
// Audio
"a52", "aac", "ac3", "aiff", "amr", "aob", "ape",
"dts", "flac", "it", "m4a", "m4p", "mid", "mka", "mlp",
......@@ -381,18 +382,29 @@ void MediaLibrary::checkFiles( fs::IDirectory* folder, unsigned int parentId )
FilePtr MediaLibrary::addFile( const fs::IFile* file, unsigned int folderId )
{
if ( std::find( begin( supportedExtensions ), end( supportedExtensions ),
file->extension() ) == end( supportedExtensions ) )
auto type = IFile::Type::UnknownType;
if ( std::find( begin( supportedVideoExtensions ), end( supportedVideoExtensions ),
file->extension() ) != end( supportedVideoExtensions ) )
{
return false;
type = IFile::Type::VideoType;
}
else if ( std::find( begin( supportedAudioExtensions ), end( supportedAudioExtensions ),
file->extension() ) != end( supportedAudioExtensions ) )
{
type = IFile::Type::AudioType;
}
if ( type == IFile::Type::UnknownType )
return false;
auto fptr = File::create( m_dbConnection, file, folderId );
if ( fptr == nullptr )
{
LOG_ERROR( "Failed to add file ", file->fullPath(), " to the media library" );
return nullptr;
}
fptr->setType( type );
LOG_INFO( "Adding ", file->name() );
m_callback->onFileAdded( fptr );
m_parser->parse( fptr, m_callback );
return fptr;
}
......
......@@ -50,7 +50,8 @@ class MediaLibrary : public IMediaLibrary, public IDiscovererCb
virtual void setLogger( ILogger* logger ) override;
private:
static const std::vector<std::string> supportedExtensions;
static const std::vector<std::string> supportedVideoExtensions;
static const std::vector<std::string> supportedAudioExtensions;
private:
bool loadFolders();
......
......@@ -86,11 +86,15 @@ void Parser::done( FilePtr file, ServiceStatus status, void* data )
delete t;
return ;
}
else if ( status == StatusSuccess )
{
t->cb->onFileUpdated( file );
}
++t->it;
if (t->it == t->end)
{
file->setReady();
t->cb->onFileUpdated( file );
delete t;
return;
}
......
......@@ -16,6 +16,10 @@ class ServiceCb : public IMediaLibraryCb
std::condition_variable waitCond;
std::mutex mutex;
virtual void onFileAdded( FilePtr ) override
{
}
virtual void onFileUpdated( FilePtr ) override
{
waitCond.notify_all();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment