Commit 4f019264 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

MediaLibrary: Allow an external media to be deleted

Fix #45
parent 8eef7fe4
Pipeline #1361 passed with stages
in 11 minutes and 35 seconds
......@@ -273,6 +273,13 @@ class IMediaLibrary
* new media's type
*/
virtual MediaPtr addStream( const std::string& mrl ) = 0;
/**
* @brief removeExternalMedia Remove an external media or a stream
* @return false if the media was not external/stream, or in case of DB failure
*/
virtual bool removeExternalMedia( MediaPtr media ) = 0;
virtual Query<IMedia> audioFiles( const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> videoFiles( const QueryParameters* params = nullptr ) const = 0;
virtual AlbumPtr album( int64_t id ) const = 0;
......
......@@ -431,6 +431,17 @@ MediaPtr MediaLibrary::addStream( const std::string& mrl )
return addExternalMedia( mrl, IMedia::Type::Stream );
}
bool MediaLibrary::removeExternalMedia(MediaPtr media)
{
if ( media->type() != Media::Type::External &&
media->type() != Media::Type::Stream )
{
assert( !"Invalid media provided" );
return false;
}
return Media::destroy( this, media->id() );
}
Query<IMedia> MediaLibrary::audioFiles( const QueryParameters* params ) const
{
return Media::listAll( this, IMedia::Type::Audio, params );
......
......@@ -78,6 +78,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual MediaPtr media( const std::string& mrl ) const override;
virtual MediaPtr addExternalMedia( const std::string& mrl ) override;
virtual MediaPtr addStream( const std::string& mrl ) override;
virtual bool removeExternalMedia( MediaPtr media ) override;
virtual Query<IMedia> audioFiles( const QueryParameters* params ) const override;
virtual Query<IMedia> videoFiles( const QueryParameters* params ) const override;
......
......@@ -767,6 +767,20 @@ TEST_F( Medias, VacuumNeverPlayedMedia )
ASSERT_NE( nullptr, s1 );
}
TEST_F( Medias, RemoveExternal )
{
auto m = ml->addExternalMedia( "http://extern.al/media.mkv" );
ASSERT_NE( nullptr, m );
auto res = ml->removeExternalMedia( m );
ASSERT_TRUE( res );
m = ml->media( m->id() );
ASSERT_EQ( nullptr, m );
m = ml->media( "http://extern.al/media.mkv" );
ASSERT_EQ( nullptr, m );
}
TEST_F( Medias, NbPlaylists )
{
auto m = std::static_pointer_cast<Media>( ml->addExternalMedia( "media.mkv" ) );
......
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