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

Show: Allow episodes to be searched

parent 231c688b
......@@ -39,6 +39,8 @@ class IShow
virtual const std::string& artworkMrl() const = 0;
virtual const std::string& tvdbId() const = 0;
virtual Query<IMedia> episodes( const QueryParameters* params = nullptr ) const = 0;
virtual Query<IMedia> searchEpisodes( const std::string& pattern,
const QueryParameters* params = nullptr ) const = 0;
virtual uint32_t nbSeasons() const = 0;
virtual uint32_t nbEpisodes() const = 0;
};
......
......@@ -758,6 +758,24 @@ Query<IMedia> Media::searchGenreTracks(MediaLibraryPtr ml, const std::string& pa
File::Type::Main, Media::SubType::AlbumTrack );
}
Query<IMedia> Media::searchShowEpisodes(MediaLibraryPtr ml, const std::string& pattern,
int64_t showId, const QueryParameters* params)
{
std::string req = "FROM " + policy::MediaTable::Name + " m "
" INNER JOIN " + policy::FileTable::Name + " f ON m.id_media = f.media_id"
" INNER JOIN " + policy::ShowEpisodeTable::Name + " ep ON ep.media_id = m.id_media "
" WHERE"
" m.id_media IN (SELECT rowid FROM " + policy::MediaTable::Name + "Fts"
" WHERE " + policy::MediaTable::Name + "Fts MATCH '*' || ? || '*')"
" AND ep.show_id = ?"
" AND f.is_present = 1"
" AND f.type = ?"
" AND m.subtype = ?";
req += sortRequest( params );
return make_query<Media, IMedia>( ml, "m.*", req, pattern, showId,
File::Type::Main, Media::SubType::ShowEpisode );
}
Query<IMedia> Media::fetchHistory( MediaLibraryPtr ml )
{
static const std::string req = "FROM " + policy::MediaTable::Name + " WHERE last_played_date IS NOT NULL"
......
......@@ -135,6 +135,8 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
int64_t artistId, const QueryParameters* params );
static Query<IMedia> searchGenreTracks( MediaLibraryPtr ml, const std::string& pattern,
int64_t genreId, const QueryParameters* params );
static Query<IMedia> searchShowEpisodes( MediaLibraryPtr ml, const std::string& pattern,
int64_t showId, const QueryParameters* params );
static Query<IMedia> fetchHistory( MediaLibraryPtr ml );
static void clearHistory( MediaLibraryPtr ml );
......
......@@ -162,6 +162,12 @@ Query<IMedia> Show::episodes( const QueryParameters* params ) const
return make_query<Media, IMedia>( m_ml, "*", req, m_id );
}
Query<IMedia> Show::searchEpisodes( const std::string& pattern,
const QueryParameters* params ) const
{
return Media::searchShowEpisodes( m_ml, pattern, m_id, params );
}
uint32_t Show::nbSeasons() const
{
return 0;
......
......@@ -64,6 +64,8 @@ class Show : public IShow, public DatabaseHelpers<Show, policy::ShowTable>
bool setTvdbId( const std::string& summary );
std::shared_ptr<ShowEpisode> addEpisode( Media& media, unsigned int episodeNumber );
virtual Query<IMedia> episodes( const QueryParameters* params ) const override;
virtual Query<IMedia> searchEpisodes( const std::string& pattern,
const QueryParameters* params = nullptr ) const override;
virtual uint32_t nbSeasons() const override;
virtual uint32_t nbEpisodes() const override;
......
......@@ -269,3 +269,25 @@ TEST_F( Shows, FileSetShowEpisode )
ASSERT_NE( e2, nullptr );
}
TEST_F( Shows, SearchEpisodes )
{
auto show1 = ml->createShow( "Show1" );
auto show2 = ml->createShow( "show2" );
auto m1 = std::static_pointer_cast<Media>( ml->addMedia( "episode.mkv" ) );
m1->setTitleBuffered( "cute otters" );
m1->setType( IMedia::Type::Video );
auto ep1 = show1->addEpisode( *m1, 1 );
auto m2 = std::static_pointer_cast<Media>( ml->addMedia( "other episode.mkv" ) );
m2->setTitleBuffered( "fluffy otters" );
m2->setType( IMedia::Type::Video );
auto ep2 = show2->addEpisode( *m2, 1 );
auto episodes = ml->searchVideo( "otters", nullptr )->all();
ASSERT_EQ( 2u, episodes.size() );
episodes = show1->searchEpisodes( "otters", nullptr )->all();
ASSERT_EQ( 1u, episodes.size() );
ASSERT_EQ( m1->id(), episodes[0]->id() );
}
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