Commit 20b12b14 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen
Browse files

Media: Provide an unsetMetadata method

parent 82c8fb24
...@@ -156,6 +156,7 @@ class IMedia ...@@ -156,6 +156,7 @@ class IMedia
/// ///
virtual bool setMetadata( MetadataType type, const std::string& value ) = 0; virtual bool setMetadata( MetadataType type, const std::string& value ) = 0;
virtual bool setMetadata( MetadataType type, int64_t value ) = 0; virtual bool setMetadata( MetadataType type, int64_t value ) = 0;
virtual bool unsetMetadata( MetadataType type ) = 0;
}; };
} }
...@@ -322,6 +322,14 @@ bool Media::setMetadata( IMedia::MetadataType type, int64_t value ) ...@@ -322,6 +322,14 @@ bool Media::setMetadata( IMedia::MetadataType type, int64_t value )
return m_metadata.set( static_cast<MDType>( type ), value ); return m_metadata.set( static_cast<MDType>( type ), value );
} }
bool Media::unsetMetadata(IMedia::MetadataType type)
{
using MDType = typename std::underlying_type<IMedia::MetadataType>::type;
if ( m_metadata.isReady() == false )
m_metadata.init( m_id, IMedia::NbMeta );
return m_metadata.unset( static_cast<MDType>( type ) );
}
void Media::setReleaseDate( unsigned int date ) void Media::setReleaseDate( unsigned int date )
{ {
if ( m_releaseDate == date ) if ( m_releaseDate == date )
......
...@@ -113,6 +113,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable> ...@@ -113,6 +113,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual const IMetadata& metadata( MetadataType type ) const override; virtual const IMetadata& metadata( MetadataType type ) const override;
virtual bool setMetadata( MetadataType type, const std::string& value ) override; virtual bool setMetadata( MetadataType type, const std::string& value ) override;
virtual bool setMetadata( MetadataType type, int64_t value ) override; virtual bool setMetadata( MetadataType type, int64_t value ) override;
virtual bool unsetMetadata( MetadataType type ) override;
void setReleaseDate( unsigned int date ); void setReleaseDate( unsigned int date );
bool save(); bool save();
......
...@@ -542,6 +542,31 @@ TEST_F( Medias, MetadataOverride ) ...@@ -542,6 +542,31 @@ TEST_F( Medias, MetadataOverride )
ASSERT_EQ( "otter", md.str() ); ASSERT_EQ( "otter", md.str() );
} }
TEST_F( Medias, MetadataUnset )
{
auto m = ml->addMedia( "media.mp3" );
auto res = m->unsetMetadata( Media::MetadataType::ApplicationSpecific );
ASSERT_TRUE( res );
res = m->setMetadata( Media::MetadataType::ApplicationSpecific, "otters" );
ASSERT_TRUE( res );
auto& md = m->metadata( Media::MetadataType::ApplicationSpecific );
ASSERT_TRUE( md.isSet() );
ASSERT_EQ( "otters", md.str() );
res = m->unsetMetadata( Media::MetadataType::ApplicationSpecific );
ASSERT_TRUE( res );
ASSERT_FALSE( md.isSet() );
Reload();
m = ml->media( m->id() );
auto& md2 = m->metadata( Media::MetadataType::ApplicationSpecific );
ASSERT_FALSE( md2.isSet() );
}
TEST_F( Medias, ExternalMrl ) TEST_F( Medias, ExternalMrl )
{ {
auto m = ml->addMedia( "https://foo.bar/sea-otters.mkv" ); auto m = ml->addMedia( "https://foo.bar/sea-otters.mkv" );
......
Supports Markdown
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