diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h index 054203ee3a..603e4eff9a 100644 --- a/include/vlc_media_library.h +++ b/include/vlc_media_library.h @@ -481,6 +481,8 @@ enum vlc_ml_list_queries VLC_ML_COUNT_MEDIA, /**< arg1 (out): size_t* */ VLC_ML_LIST_VIDEOS, /**< arg1 (out): vlc_ml_media_list_t** */ VLC_ML_COUNT_VIDEOS, /**< arg1 (out): size_t* */ + VLC_ML_LIST_MOVIES, /**< arg1 (out): vlc_ml_media_list_t** */ + VLC_ML_COUNT_MOVIES, /**< arg1 (out): size_t* */ VLC_ML_LIST_AUDIOS, /**< arg1 (out): vlc_ml_media_list_t** */ VLC_ML_COUNT_AUDIOS, /**< arg1 (out): size_t* */ VLC_ML_LIST_ALBUMS, /**< arg1 (out): vlc_ml_album_list_t** */ @@ -1661,6 +1663,24 @@ static inline vlc_ml_show_list_t* vlc_ml_list_shows( vlc_medialibrary_t* p_ml, c return res; } +static inline vlc_ml_media_list_t* vlc_ml_list_movies(vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params) +{ + vlc_assert(p_ml != NULL); + vlc_ml_media_list_t* res; + if (vlc_ml_list(p_ml, VLC_ML_LIST_MOVIES, params, &res) != VLC_SUCCESS) + return NULL; + return res; +} + +static inline size_t vlc_ml_count_movies(vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params) +{ + vlc_assert(p_ml != NULL); + size_t count; + if (vlc_ml_list(p_ml, VLC_ML_COUNT_MOVIES, params, &count) != VLC_SUCCESS) + return 0; + return count; +} + static inline size_t vlc_ml_count_shows( vlc_medialibrary_t* p_ml, const vlc_ml_query_params_t* params ) { vlc_assert( p_ml != NULL ); diff --git a/modules/misc/medialibrary/medialibrary.cpp b/modules/misc/medialibrary/medialibrary.cpp index c8e05a3b91..abea408f65 100644 --- a/modules/misc/medialibrary/medialibrary.cpp +++ b/modules/misc/medialibrary/medialibrary.cpp @@ -1019,6 +1019,49 @@ int MediaLibrary::List( int listQuery, const vlc_ml_query_params_t* params, va_l *va_arg( args, size_t* ) = query->count(); break; } + case VLC_ML_LIST_MOVIES: + { + medialibrary::Query query; + if ( psz_pattern != nullptr ) + query = m_ml->searchVideo( psz_pattern, paramsPtr ); + else + query = m_ml->videoFiles( paramsPtr ); + if ( query == nullptr ) + return VLC_EGENERIC; + // Filter for movies only + auto items = query->items(nbItems, offset); + items.erase( + std::remove_if( + items.begin(), + items.end(), + [](const auto& item) { + return item->subType() != medialibrary::IMedia::SubType::Movie; + }), + items.end()); + const auto res = ml_convert_list(items); + *va_arg( args, vlc_ml_media_list_t**) = res; + break; + } + case VLC_ML_COUNT_MOVIES: + { + medialibrary::Query query; + if ( psz_pattern != nullptr ) + query = m_ml->searchVideo( psz_pattern, paramsPtr ); + else + query = m_ml->videoFiles( paramsPtr ); + if ( query == nullptr ) + return VLC_EGENERIC; + // Filter for movies only + const auto items = query->items( 0, 0 ); + const size_t count = std::count_if( + items.cbegin(), + items.cend(), + [](const auto& item) { + return item->subType() == medialibrary::IMedia::SubType::Movie; + }); + *va_arg( args, size_t* ) = count; + break; + } case VLC_ML_LIST_AUDIOS: { medialibrary::Query query;