Commit 1a2afad6 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

IMediaLibrary: Remove show & movie getters by name

parent a21552ae
......@@ -264,9 +264,7 @@ class IMediaLibrary
virtual AlbumPtr album( int64_t id ) const = 0;
virtual Query<IAlbum> albums( const QueryParameters* params = nullptr ) const = 0;
virtual ShowPtr show( int64_t id ) const = 0;
virtual ShowPtr show( const std::string& name ) const = 0;
virtual MoviePtr movie( int64_t id ) const = 0;
virtual MoviePtr movie( const std::string& title ) const = 0;
virtual ArtistPtr artist( int64_t id ) const = 0;
/**
* @brief artists List all artists that have at least an album.
......
......@@ -564,13 +564,6 @@ ShowPtr MediaLibrary::show( int64_t id ) const
return Show::fetch( this, id );
}
ShowPtr MediaLibrary::show( const std::string& name ) const
{
static const std::string req = "SELECT * FROM " + policy::ShowTable::Name
+ " WHERE name = ?";
return Show::fetch( this, req, name );
}
std::shared_ptr<Show> MediaLibrary::createShow( const std::string& name )
{
return Show::create( this, name );
......@@ -581,16 +574,6 @@ MoviePtr MediaLibrary::movie( int64_t id ) const
return Movie::fetch( this, id );
}
MoviePtr MediaLibrary::movie( const std::string& title ) const
{
static const std::string req = "SELECT * FROM " + policy::MediaTable::Name
+ " WHERE title = ?";
auto media = Media::fetch( this, req, title );
if ( media == nullptr || media->subType() != IMedia::SubType::Movie )
return nullptr;
return media->movie();
}
std::shared_ptr<Movie> MediaLibrary::createMovie( Media& media )
{
auto movie = Movie::create( this, media.id() );
......
......@@ -71,7 +71,7 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual void setVerbosity( LogLevel v ) override;
virtual MediaPtr media( int64_t mediaId ) const override;
virtual MediaPtr media( const std::string& path ) const override;
virtual MediaPtr media( const std::string& mrl ) const override;
virtual MediaPtr addMedia( const std::string& mrl ) override;
virtual Query<IMedia> audioFiles( const QueryParameters* params ) const override;
virtual Query<IMedia> videoFiles( const QueryParameters* params ) const override;
......@@ -94,11 +94,9 @@ class MediaLibrary : public IMediaLibrary, public IDeviceListerCb
virtual GenrePtr genre( int64_t id ) const override;
virtual ShowPtr show( int64_t id ) const override;
virtual ShowPtr show( const std::string& name ) const override;
std::shared_ptr<Show> createShow( const std::string& name );
virtual MoviePtr movie( int64_t id ) const override;
virtual MoviePtr movie( const std::string& title ) const override;
std::shared_ptr<Movie> createMovie( Media& media );
virtual ArtistPtr artist( int64_t id ) const override;
......
......@@ -390,13 +390,23 @@ bool MetadataAnalyzer::parseVideoFile( IItem& item ) const
if ( showName.length() != 0 )
{
auto show = m_ml->show( showName );
if ( show == nullptr )
const std::string req = "SELECT * FROM " + policy::ShowTable::Name +
" WHERE name = ?";
auto shows = Show::fetchAll<Show>( m_ml, req, showName );
std::shared_ptr<Show> show;
if ( shows.empty() == true )
{
show = m_ml->createShow( showName );
if ( show == nullptr )
return false;
}
else
{
//FIXME: Discriminate amongst shows
LOG_WARN( "Defaulting to first matching show" );
show = shows[0];
}
auto episode = toInt( item, IItem::Metadata::Episode );
if ( episode != 0 )
{
......
......@@ -47,13 +47,13 @@ TEST_F( Movies, Fetch )
media->setTitle( "movie" );
// Setting the movie during ml::createMovie will save the media, thus saving the title.
auto m = ml->createMovie( *media );
auto m2 = ml->movie( "movie" );
auto m2 = ml->movie( m->id() );
ASSERT_EQ( m, m2 );
Reload();
m2 = ml->movie( "movie" );
m2 = ml->movie( m->id() );
ASSERT_NE( m2, nullptr );
}
......@@ -69,7 +69,7 @@ TEST_F( Movies, SetShortSummary )
Reload();
auto m2 = ml->movie( "movie" );
auto m2 = ml->movie( m->id() );
ASSERT_EQ( m2->shortSummary(), "great movie" );
}
......@@ -85,7 +85,7 @@ TEST_F( Movies, SetImdbId )
Reload();
auto m2 = ml->movie( "movie" );
auto m2 = ml->movie( m->id() );
ASSERT_EQ( m2->imdbId(), "id" );
}
......
......@@ -40,7 +40,7 @@ TEST_F( Shows, Create )
auto s = ml->createShow( "show" );
ASSERT_NE( s, nullptr );
auto s2 = ml->show( "show" );
auto s2 = ml->show( s->id() );
ASSERT_EQ( s, s2 );
}
......@@ -51,7 +51,7 @@ TEST_F( Shows, Fetch )
// Clear the cache
Reload();
auto s2 = ml->show( "show" );
auto s2 = ml->show( s->id() );
// The shared pointers are expected to point to different instances
ASSERT_NE( s, s2 );
......@@ -67,7 +67,7 @@ TEST_F( Shows, SetReleaseDate )
Reload();
auto s2 = ml->show( "show" );
auto s2 = ml->show( s->id() );
ASSERT_EQ( s->releaseDate(), s2->releaseDate() );
}
......@@ -81,7 +81,7 @@ TEST_F( Shows, SetShortSummary )
Reload();
auto s2 = ml->show( "show" );
auto s2 = ml->show( s->id() );
ASSERT_EQ( s->shortSummary(), s2->shortSummary() );
}
......@@ -94,7 +94,7 @@ TEST_F( Shows, SetArtworkMrl )
Reload();
auto s2 = ml->show( "show" );
auto s2 = ml->show( s->id() );
ASSERT_EQ( s->artworkMrl(), s2->artworkMrl() );
}
......@@ -107,7 +107,7 @@ TEST_F( Shows, SetTvdbId )
Reload();
auto s2 = ml->show( "show" );
auto s2 = ml->show( s->id() );
ASSERT_EQ( s->tvdbId(), s2->tvdbId() );
}
......@@ -162,7 +162,7 @@ TEST_F( Shows, SetEpisodeSeasonNumber )
Reload();
show = std::static_pointer_cast<Show>( ml->show( "show" ) );
show = std::static_pointer_cast<Show>( ml->show( show->id() ) );
auto episodes = show->episodes()->all();
ASSERT_EQ( episodes[0]->seasonNumber(), e->seasonNumber() );
}
......@@ -178,7 +178,7 @@ TEST_F( Shows, SetEpisodeSummary )
Reload();
show = std::static_pointer_cast<Show>( ml->show( "show" ) );
show = std::static_pointer_cast<Show>( ml->show( show->id() ) );
auto episodes = show->episodes()->all();
ASSERT_EQ( episodes[0]->shortSummary(), e->shortSummary() );
}
......@@ -194,7 +194,7 @@ TEST_F( Shows, SetEpisodeTvdbId )
Reload();
show = std::static_pointer_cast<Show>( ml->show( "show" ) );
show = std::static_pointer_cast<Show>( ml->show( show->id() ) );
auto episodes = show->episodes()->all();
ASSERT_EQ( episodes[0]->tvdbId(), e->tvdbId() );
}
......
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