Commit a5cf0649 authored by Aymeric Guillien's avatar Aymeric Guillien
Browse files

Medialibrary: Add movie list getter

parent 42d1fba4
Pipeline #182145 failed with stages
in 8 minutes and 58 seconds
......@@ -480,6 +480,15 @@ public:
*/
virtual Query<IMedia> videoFiles( const QueryParameters* params = nullptr ) const = 0;
/**
* @brief movies Returns the media classified as Movie
* @param params Some query parameters.
* @return A query representing the results set
*
* \see{IMediaLibrary::videoFiles} for the supported sorting criteria
*/
virtual Query<IMedia> movies( const QueryParameters* params = nullptr ) const = 0;
/**
* @brief inProgressMedia Returns media for which playback wasn't completed
* @param type The type of media to fetch, or 'Unknown' for all
......
......@@ -1235,7 +1235,8 @@ std::string Media::sortRequest( const QueryParameters* params )
}
Query<IMedia> Media::listAll( MediaLibraryPtr ml, IMedia::Type type,
const QueryParameters* params )
const QueryParameters* params,
IMedia::SubType subType )
{
assert( type == IMedia::Type::Audio || type == IMedia::Type::Video );
std::string req = "FROM " + Media::Table::Name + " m ";
......@@ -1253,6 +1254,14 @@ Query<IMedia> Media::listAll( MediaLibraryPtr ml, IMedia::Type type,
if ( params == nullptr || params->includeMissing == false )
req += " AND m.is_present != 0";
if ( subType != IMedia::SubType::Unknown )
{
req += " AND m.subtype = ?";
return make_query<Media, IMedia>( ml, "m.*", std::move( req ),
sortRequest( params ), IMedia::Type::Audio,
IFile::Type::Main, IFile::Type::Disc, subType );
}
return make_query<Media, IMedia>( ml, "m.*", std::move( req ),
sortRequest( params ), IMedia::Type::Audio,
IFile::Type::Main, IFile::Type::Disc );
......
......@@ -296,7 +296,9 @@ class Media : public IMedia,
virtual const std::string& lyrics() const override;
bool setLyrics( std::string lyrics );
static Query<IMedia> listAll(MediaLibraryPtr ml, Type type, const QueryParameters* params );
static Query<IMedia> listAll( MediaLibraryPtr ml, Type type,
const QueryParameters* params,
Media::SubType subType );
static Query<IMedia> listInProgress( MediaLibraryPtr ml, Type type,
const QueryParameters* params );
......
......@@ -712,12 +712,17 @@ bool MediaLibrary::removeExternalMedia(MediaPtr media)
Query<IMedia> MediaLibrary::audioFiles( const QueryParameters* params ) const
{
return Media::listAll( this, IMedia::Type::Audio, params );
return Media::listAll( this, IMedia::Type::Audio, params, IMedia::SubType::Unknown );
}
Query<IMedia> MediaLibrary::videoFiles( const QueryParameters* params ) const
{
return Media::listAll( this, IMedia::Type::Video, params );
return Media::listAll( this, IMedia::Type::Video, params, IMedia::SubType::Unknown );
}
Query<IMedia> MediaLibrary::movies( const QueryParameters* params ) const
{
return Media::listAll( this, IMedia::Type::Video, params, IMedia::SubType::Movie );
}
Query<IMedia> MediaLibrary::inProgressMedia( IMedia::Type type, const QueryParameters *params ) const
......
......@@ -102,6 +102,7 @@ public:
virtual bool removeExternalMedia( MediaPtr media ) override;
virtual Query<IMedia> audioFiles( const QueryParameters* params ) const override;
virtual Query<IMedia> videoFiles( const QueryParameters* params ) const override;
virtual Query<IMedia> movies( const QueryParameters* params ) const override;
virtual Query<IMedia> inProgressMedia( IMedia::Type type,
const QueryParameters* params ) const override;
......
......@@ -52,6 +52,80 @@ static void Fetch( Tests* T )
ASSERT_NE( m2, nullptr );
}
static void FetchAll( Tests* T )
{
auto media = std::static_pointer_cast<Media>( T->ml->addMedia( "movie.mkv", IMedia::Type::Video ) );
auto m = T->ml->createMovie( *media );
auto media2 = std::static_pointer_cast<Media>( T->ml->addMedia( "movie2.mkv", IMedia::Type::Video ) );
auto m2 = T->ml->createMovie( *media2 );
auto movies = T->ml->movies( nullptr )->all();
ASSERT_EQ( 2u, movies.size() );
ASSERT_EQ( m->id(), movies[0]->id() );
ASSERT_EQ( m2->id(), movies[1]->id() );
}
static void SortByAlpha( Tests* T )
{
auto media = std::static_pointer_cast<Media>( T->ml->addMedia( "movie.mkv", Media::Type::Video ) );
media->setTitle( "Abcd", true );
auto m = T->ml->createMovie( *media );
auto media2 = std::static_pointer_cast<Media>( T->ml->addMedia( "movie2.mkv", Media::Type::Video ) );
media2->setTitle( "Zyxw", true );
auto m2 = T->ml->createMovie( *media2 );
auto media3 = std::static_pointer_cast<Media>( T->ml->addMedia( "movie3.mkv", Media::Type::Video ) );
media3->setTitle( "afterA-beforeZ", true );
auto m3 = T->ml->createMovie( *media3 );
QueryParameters params { SortingCriteria::Alpha, false };
auto medias = T->ml->movies( &params )->all();
ASSERT_EQ( 3u, medias.size() );
ASSERT_EQ( m->id(), medias[0]->id() );
ASSERT_EQ( m3->id(), medias[1]->id() );
ASSERT_EQ( m2->id(), medias[2]->id() );
params.desc = true;
medias = T->ml->movies( &params )->all();
ASSERT_EQ( 3u, medias.size() );
ASSERT_EQ( m2->id(), medias[0]->id() );
ASSERT_EQ( m3->id(), medias[1]->id() );
ASSERT_EQ( m->id(), medias[2]->id() );
}
static void SortByLastPlayedDate( Tests* T )
{
auto media = std::static_pointer_cast<Media>( T->ml->addMedia( "movie.mkv", Media::Type::Video ) );
auto m = T->ml->createMovie( *media );
T->ml->setMediaLastPlayedDate( media->id(), 100 );
auto media2 = std::static_pointer_cast<Media>( T->ml->addMedia( "movie2.mkv", Media::Type::Video ) );
auto m2 = T->ml->createMovie( *media2 );
T->ml->setMediaLastPlayedDate( media2->id(), 10 );
auto media3 = std::static_pointer_cast<Media>( T->ml->addMedia( "movie3.mkv", Media::Type::Video ) );
auto m3 = T->ml->createMovie( *media3 );
T->ml->setMediaLastPlayedDate( media3->id(), 0 );
QueryParameters params { SortingCriteria::LastPlaybackDate, false };
auto medias = T->ml->movies( &params )->all();
ASSERT_EQ( 3u, medias.size() );
ASSERT_EQ( m3->id(), medias[0]->id() );
ASSERT_EQ( m2->id(), medias[1]->id() );
ASSERT_EQ( m->id(), medias[2]->id() );
params.desc = true;
medias = T->ml->movies( &params )->all();
ASSERT_EQ( 3u, medias.size() );
ASSERT_EQ( m->id(), medias[0]->id() );
ASSERT_EQ( m2->id(), medias[1]->id() );
ASSERT_EQ( m3->id(), medias[2]->id() );
}
static void SetShortSummary( Tests* T )
{
auto media = std::static_pointer_cast<Media>( T->ml->addMedia( "movie.mkv", IMedia::Type::Video ) );
......@@ -122,6 +196,9 @@ int main( int ac, char** av )
ADD_TEST( Create );
ADD_TEST( Fetch );
ADD_TEST( FetchAll );
ADD_TEST( SortByLastPlayedDate );
ADD_TEST( SortByAlpha );
ADD_TEST( SetShortSummary );
ADD_TEST( SetImdbId );
ADD_TEST( AssignToFile );
......
......@@ -652,6 +652,9 @@ movie_test_exe = executable('movie_tests', 'MovieTests.cpp',
movie_tests = [
'Create',
'Fetch',
'FetchAll',
'SortByAlpha',
'SortByLastPlayedDate',
'SetShortSummary',
'SetImdbId',
'AssignToFile',
......
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