Commit 906fee01 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

MediaLibrary: Move test only member function to MediaLibraryTester class

parent b994ab64
......@@ -418,31 +418,6 @@ bool MediaLibrary::isExtensionSupported( const char* ext )
});
}
std::shared_ptr<Media> MediaLibrary::addFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs )
{
LOG_INFO( "Adding ", fileFs->mrl() );
auto mptr = Media::create( this, IMedia::Type::Unknown,
utils::file::stripExtension( fileFs->name() ) );
if ( mptr == nullptr )
{
LOG_ERROR( "Failed to add media ", fileFs->mrl(), " to the media library" );
return nullptr;
}
// For now, assume all media are made of a single file
auto file = mptr->addFile( *fileFs, parentFolder->id(), parentFolderFs->device()->isRemovable(), File::Type::Main );
if ( file == nullptr )
{
LOG_ERROR( "Failed to add file ", fileFs->mrl(), " to media #", mptr->id() );
Media::destroy( this, mptr->id() );
return nullptr;
}
if ( m_parser != nullptr )
m_parser->parse( file, mptr, fileFs->mrl() );
return mptr;
}
void MediaLibrary::addDiscoveredFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs,
......
......@@ -74,10 +74,6 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual std::vector<MediaPtr> audioFiles( SortingCriteria sort, bool desc) const override;
virtual std::vector<MediaPtr> videoFiles( SortingCriteria sort, bool desc) const override;
std::shared_ptr<Media> addFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs );
virtual void addDiscoveredFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs,
......
......@@ -63,13 +63,38 @@ std::shared_ptr<Folder> MediaLibraryTester::folder( const std::string& mrl )
std::shared_ptr<Media> MediaLibraryTester::addFile( const std::string& path )
{
auto file = std::make_shared<mock::NoopFile>( path );
return MediaLibrary::addFile( file, dummyFolder, dummyDirectory );
return addFile( std::make_shared<mock::NoopFile>( path ),
dummyFolder, dummyDirectory );
}
std::shared_ptr<Media> MediaLibraryTester::addFile( std::shared_ptr<fs::IFile> file )
{
return MediaLibrary::addFile( std::move( file ), dummyFolder, dummyDirectory );
return addFile( std::move( file ), dummyFolder, dummyDirectory );
}
std::shared_ptr<Media> MediaLibraryTester::addFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs )
{
LOG_INFO( "Adding ", fileFs->mrl() );
auto mptr = Media::create( this, IMedia::Type::Unknown,
utils::file::stripExtension( fileFs->name() ) );
if ( mptr == nullptr )
{
LOG_ERROR( "Failed to add media ", fileFs->mrl(), " to the media library" );
return nullptr;
}
// For now, assume all media are made of a single file
auto file = mptr->addFile( *fileFs, parentFolder->id(), parentFolderFs->device()->isRemovable(), File::Type::Main );
if ( file == nullptr )
{
LOG_ERROR( "Failed to add file ", fileFs->mrl(), " to media #", mptr->id() );
Media::destroy( this, mptr->id() );
return nullptr;
}
if ( m_parser != nullptr )
m_parser->parse( file, mptr, fileFs->mrl() );
return mptr;
}
void MediaLibraryTester::addLocalFsFactory()
......@@ -160,5 +185,5 @@ void MediaLibraryTester::addDiscoveredFile(std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<fs::IDirectory> parentFolderFs,
std::pair<std::shared_ptr<Playlist>, unsigned int>)
{
MediaLibrary::addFile( fileFs, parentFolder, parentFolderFs );
addFile( fileFs, parentFolder, parentFolderFs );
}
......@@ -58,6 +58,9 @@ public:
std::shared_ptr<Media> addFile( std::shared_ptr<fs::IFile> file);
// Used when we need an actual file instead of an external media
std::shared_ptr<Media> addFile( const std::string& path );
std::shared_ptr<Media> addFile( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> parentFolder,
std::shared_ptr<fs::IDirectory> parentFolderFs );
virtual void addLocalFsFactory() override;
std::shared_ptr<Device> device( const std::string& uuid );
std::vector<const char*> getSupportedExtensions() const;
......
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