From 6bef411318a255f0f90bf438f068a845f8777c84 Mon Sep 17 00:00:00 2001
From: Aymeric Guillien <aymericguillien.pro@gmail.com>
Date: Thu, 13 Jan 2022 18:04:42 +0100
Subject: [PATCH] medialib: Add movie getter

---
 include/vlc_media_library.h                | 13 +++++++++++
 modules/misc/medialibrary/medialibrary.cpp | 26 ++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/include/vlc_media_library.h b/include/vlc_media_library.h
index 97765a9e5dd7..8d93b40a0169 100644
--- a/include/vlc_media_library.h
+++ b/include/vlc_media_library.h
@@ -528,6 +528,10 @@ enum vlc_ml_list_queries
     VLC_ML_COUNT_ARTISTS_OF,      /**< arg1: parent entity type; arg2: parent entity id; arg3(out): size_t*             */
     VLC_ML_LIST_ALBUMS_OF,        /**< arg1: parent entity type; arg2: parent entity id; arg3(out): ml_album_list_t**   */
     VLC_ML_COUNT_ALBUMS_OF,       /**< arg1: parent entity type; arg2: parent entity id; arg3(out): size_t*             */
+
+    /* Movies specific listings */
+    VLC_ML_LIST_MOVIES,           /**< arg1 (out): vlc_ml_media_list_t**                                                */
+    VLC_ML_COUNT_MOVIES,          /**< arg1 (out): size_t*                                                              */
 };
 
 enum vlc_ml_parent_type
@@ -1437,6 +1441,15 @@ static inline vlc_ml_media_list_t* vlc_ml_list_video_media( vlc_medialibrary_t*
     return res;
 }
 
+static inline vlc_ml_media_list_t* vlc_ml_list_movie_media( 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_video_media( 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 8144637c37b4..281d6494e801 100644
--- a/modules/misc/medialibrary/medialibrary.cpp
+++ b/modules/misc/medialibrary/medialibrary.cpp
@@ -825,6 +825,32 @@ 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<medialibrary::IMedia> query;
+            if ( psz_pattern != nullptr )
+                query = m_ml->searchMovie( psz_pattern, paramsPtr );
+            else
+                query = m_ml->movies( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
+            auto res = ml_convert_list<vlc_ml_media_list_t, vlc_ml_media_t>(
+                        query->items( nbItems, offset ) );
+            *va_arg( args, vlc_ml_media_list_t**) = res;
+            break;
+        }
+        case VLC_ML_COUNT_MOVIES:
+        {
+            medialibrary::Query<medialibrary::IMedia> query;
+            if ( psz_pattern != nullptr )
+                query = m_ml->searchMovie( psz_pattern, paramsPtr );
+            else
+                query = m_ml->movies( paramsPtr );
+            if ( query == nullptr )
+                return VLC_EGENERIC;
+            *va_arg( args, size_t* ) = query->count();
+            break;
+        }
         case VLC_ML_LIST_AUDIOS:
         {
             medialibrary::Query<medialibrary::IMedia> query;
-- 
GitLab