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

IMediaLibrary: Don't expose an unknownArtist getter

parent 0e70d943
......@@ -114,10 +114,6 @@ class IMediaLibrary
virtual ShowPtr show( const std::string& name ) = 0;
virtual MoviePtr movie( const std::string& title ) = 0;
virtual ArtistPtr artist( const std::string& name ) = 0;
/**
* @brief unknownArtist returns a representation of a virtual "unknown" artist.
*/
virtual ArtistPtr unknownArtist() = 0;
virtual std::vector<ArtistPtr> artists() const = 0;
/**
......
......@@ -323,13 +323,6 @@ ArtistPtr MediaLibrary::artist(const std::string &name)
return Artist::fetchOne( m_dbConnection.get(), req, name );
}
ArtistPtr MediaLibrary::unknownArtist()
{
if ( m_unknownArtist == nullptr )
m_unknownArtist = std::make_shared<Artist>( m_dbConnection.get() );
return m_unknownArtist;
}
std::shared_ptr<Artist> MediaLibrary::createArtist( const std::string& name )
{
return Artist::create( m_dbConnection.get(), name );
......@@ -355,9 +348,6 @@ void MediaLibrary::addMetadataService(std::unique_ptr<IMetadataService> service)
void MediaLibrary::reload()
{
// For the sake of simplicity, just flush the unknownArtist cache, regardless of any change
// FIXME: Replicate this for "live" change handling, once we have it.
m_unknownArtist = nullptr;
m_discoverer->reload();
}
......
......@@ -73,7 +73,6 @@ class MediaLibrary : public IMediaLibrary
std::shared_ptr<Movie> createMovie( const std::string& title );
virtual ArtistPtr artist( const std::string& name ) override;
virtual ArtistPtr unknownArtist() override;
std::shared_ptr<Artist> createArtist( const std::string& name );
virtual std::vector<ArtistPtr> artists() const override;
......@@ -99,9 +98,6 @@ class MediaLibrary : public IMediaLibrary
std::shared_ptr<factory::IFileSystem> m_fsFactory;
std::string m_snapshotPath;
IMediaLibraryCb* m_callback;
// Unknown artist "cache". If a track has been parsed with an unknown artist, this
// won't change (until we reload or detect a change)
ArtistPtr m_unknownArtist;
// This probably qualifies as a work around, but we need to keep the VLC::Instance
// alive to be able to use the logging wrapper lambda
......
......@@ -386,7 +386,8 @@ bool VLCMetadataService::link( std::shared_ptr<Media> media, std::shared_ptr<Alb
if ( albumArtist == nullptr && artist == nullptr )
{
// We don't know anything about the artist, simply mark it as a track from unknown artist.
std::static_pointer_cast<Artist>( m_ml->unknownArtist() )->addMedia( media.get() );
auto unknownArtist = Artist::fetch( m_dbConn, medialibrary::UnknownArtistID );
unknownArtist->addMedia( media.get() );
return true;
}
......
......@@ -135,13 +135,17 @@ TEST_F( Artists, AllSongs )
TEST_F( Artists, GetAll )
{
auto artists = ml->artists();
// Ensure we don't include Unknown Artist // Various Artists
ASSERT_EQ( artists.size(), 0u );
for ( int i = 0; i < 5; i++ )
{
auto a = ml->createArtist( std::to_string( i ) );
a->markAsAlbumArtist();
ASSERT_NE( a, nullptr );
}
auto artists = ml->artists();
artists = ml->artists();
ASSERT_EQ( artists.size(), 5u );
Reload();
......
......@@ -152,29 +152,3 @@ TEST_F( Medias, Snapshot )
auto f2 = ml->file( "media.avi" );
ASSERT_EQ( f2->snapshot(), newSnapshot );
}
TEST_F( Medias, UnknownArtist )
{
auto a = std::static_pointer_cast<Artist>( ml->unknownArtist() );
ASSERT_NE( a, nullptr );
auto tracks = a->media();
ASSERT_EQ( tracks.size(), 0u );
auto f = ml->addFile( "file.mp3", nullptr );
// explicitely set the artist to nullptr (aka "unknown artist")
auto res = a->addMedia( f.get() );
ASSERT_EQ( res, true );
// Now, querying unknownArtist should give out some results.
tracks = a->media();
ASSERT_EQ( tracks.size(), 1u );
Reload();
// Check that unknown artist tracks listing persists in DB
auto a2 = ml->unknownArtist();
ASSERT_NE( a2, nullptr );
auto tracks2 = a2->media();
ASSERT_EQ( tracks2.size(), 1u );
}
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