[vlc-commits] [Git][videolan/vlc][master] 7 commits: cli: factor out item printing

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Thu May 19 18:48:16 UTC 2022



Jean-Baptiste Kempf pushed to branch master at VideoLAN / VLC


Commits:
82e0b970 by Rémi Denis-Courmont at 2022-05-19T18:33:26+00:00
cli: factor out item printing

- - - - -
fd0cc5d3 by Rémi Denis-Courmont at 2022-05-19T18:33:26+00:00
cli: make info a playlist command

- - - - -
85772a0e by Rémi Denis-Courmont at 2022-05-19T18:33:26+00:00
cli: print infos of playlist items (refs #24986)

This matches the Lua RC info semantics. If there is an argument print
the infos of the item with that index, rather than the playing item.

- - - - -
f67038f2 by Rémi Denis-Courmont at 2022-05-19T18:33:26+00:00
meta: add vlc_meta_TypeToString()

Same as vlc_meta_TypeToLocalizedString() without localisation.

- - - - -
0b74dc4f by Rémi Denis-Courmont at 2022-05-19T18:33:26+00:00
cli: factor strings

- - - - -
f2b463f9 by Rémi Denis-Courmont at 2022-05-19T18:33:26+00:00
cli: print item meta data (refs #24986)

Note that item->p_meta cannot be NULL.

- - - - -
2390f360 by Rémi Denis-Courmont at 2022-05-19T18:33:26+00:00
cli: print item extra meta data (fixes #24986)

- - - - -


5 changed files:

- include/vlc_meta.h
- modules/control/cli/player.c
- modules/control/cli/playlist.c
- src/input/meta.c
- src/libvlccore.sym


Changes:

=====================================
include/vlc_meta.h
=====================================
@@ -91,6 +91,8 @@ VLC_API void vlc_meta_Merge( vlc_meta_t *dst, const vlc_meta_t *src );
 VLC_API int vlc_meta_GetStatus( vlc_meta_t *m );
 VLC_API void vlc_meta_SetStatus( vlc_meta_t *m, int status );
 
+VLC_API const char *vlc_meta_TypeToString(vlc_meta_type_t meta_type);
+
 /**
  * Returns a localizes string describing the meta
  */


=====================================
modules/control/cli/player.c
=====================================
@@ -503,43 +503,6 @@ static int PlayerRecord(struct cli_client *cl, const char *const *args,
     return 0;
 }
 
-static int PlayerItemInfo(struct cli_client *cl, const char *const *args,
-                          size_t count, void *data)
-{
-    vlc_player_t *player = data;
-    input_item_t *item;
-
-    vlc_player_Lock(player);
-    item = vlc_player_GetCurrentMedia(player);
-
-    if (item != NULL)
-    {
-        vlc_mutex_lock(&item->lock);
-        info_category_t *category;
-        vlc_list_foreach(category, &item->categories, node)
-        {
-            info_t *info;
-
-            if (info_category_IsHidden(category))
-                continue;
-
-            cli_printf(cl, "+----[ %s ]", category->psz_name);
-            cli_printf(cl, "| ");
-            info_foreach(info, &category->infos)
-                cli_printf(cl, "| %s: %s", info->psz_name,
-                           info->psz_value);
-            cli_printf(cl, "| ");
-        }
-        cli_printf(cl, "+----[ end of stream info ]");
-        vlc_mutex_unlock(&item->lock);
-    }
-    else
-        cli_printf(cl, "no input");
-    vlc_player_Unlock(player);
-    (void) args; (void) count;
-    return (item != NULL) ? 0 : VLC_ENOENT;
-}
-
 static int PlayerGetTime(struct cli_client *cl, const char *const *args,
                          size_t count, void *data)
 {
@@ -1029,7 +992,6 @@ static const struct cli_handler cmds[] =
     { "normal", PlayerNormal },
     { "rate", PlayerRate },
     { "frame", PlayerFrame },
-    { "info", PlayerItemInfo },
     { "get_time", PlayerGetTime },
     { "get_length", PlayerGetLength },
     { "get_title", PlayerGetTitle },


=====================================
modules/control/cli/playlist.c
=====================================
@@ -489,6 +489,79 @@ static int PlaylistMove(struct cli_client *cl, const char *const *args,
     return ret;
 }
 
+static void ItemPrint(struct cli_client *cl, input_item_t *item)
+{
+    vlc_meta_t *meta;
+    info_category_t *category;
+    char **extras;
+
+    vlc_mutex_lock(&item->lock);
+    meta = item->p_meta;
+    cli_printf(cl, "+----[ %s ]", "Meta data");
+    cli_printf(cl, "| ");
+
+    for (int i = 0; i < VLC_META_TYPE_COUNT; i++) {
+        const char *s = vlc_meta_Get(meta, i);
+
+        if (s != NULL)
+            cli_printf(cl, "| %s: %s", vlc_meta_TypeToString(i), s);
+    }
+
+    extras = vlc_meta_CopyExtraNames(meta);
+    if (extras != NULL) {
+        for (size_t i = 0; extras[i] != NULL; i++) {
+             cli_printf(cl, "| %s: %s", extras[i],
+                        vlc_meta_GetExtra(meta, extras[i]));
+             free(extras[i]);
+        }
+        free(extras);
+    }
+
+    cli_printf(cl, "| ");
+
+    vlc_list_foreach(category, &item->categories, node) {
+        info_t *info;
+
+        if (info_category_IsHidden(category))
+            continue;
+
+        cli_printf(cl, "+----[ %s ]", category->psz_name);
+        cli_printf(cl, "| ");
+        info_foreach(info, &category->infos)
+            cli_printf(cl, "| %s: %s", info->psz_name, info->psz_value);
+        cli_printf(cl, "| ");
+    }
+    cli_printf(cl, "+----[ %s ]", "end of stream info");
+    vlc_mutex_unlock(&item->lock);
+}
+
+static int PlaylistItemInfo(struct cli_client *cl, const char *const *args,
+                            size_t count, void *data)
+{
+    vlc_playlist_t *playlist = data;
+    ssize_t idx;
+    input_item_t *item;
+
+    vlc_playlist_Lock(playlist);
+    if (count >= 2)
+        idx = atoi(args[1]);
+    else
+        idx = vlc_playlist_GetCurrentIndex(playlist);
+
+    if ((size_t)idx < vlc_playlist_Count(playlist))
+        item = vlc_playlist_item_GetMedia(vlc_playlist_Get(playlist, idx));
+    else
+        item = NULL;
+
+    if (item != NULL)
+        ItemPrint(cl, item);
+    else
+        cli_printf(cl, "no input");
+    vlc_playlist_Unlock(playlist);
+    (void) args; (void) count;
+    return (item != NULL) ? 0 : VLC_ENOENT;
+}
+
 static const struct cli_handler cmds[] =
 {
     { "playlist", PlaylistList },
@@ -505,6 +578,7 @@ static const struct cli_handler cmds[] =
     { "enqueue", PlaylistEnqueue },
     { "goto", PlaylistGoto },
     { "move", PlaylistMove },
+    { "info", PlaylistItemInfo },
 };
 
 void RegisterPlaylist(intf_thread_t *intf)


=====================================
src/input/meta.c
=====================================
@@ -45,10 +45,9 @@ struct vlc_meta_t
     int i_status;
 };
 
-/* FIXME bad name convention */
-const char * vlc_meta_TypeToLocalizedString( vlc_meta_type_t meta_type )
+const char *vlc_meta_TypeToString(vlc_meta_type_t meta_type)
 {
-    static const char posix_names[][18] =
+    static const char posix_names[VLC_META_TYPE_COUNT][18] =
     {
         [vlc_meta_Title]       = N_("Title"),
         [vlc_meta_Artist]      = N_("Artist"),
@@ -79,9 +78,15 @@ const char * vlc_meta_TypeToLocalizedString( vlc_meta_type_t meta_type )
         [vlc_meta_DiscTotal]   = N_("Total disc number")
     };
 
-    assert (meta_type < ARRAY_SIZE(posix_names));
-    assert (strlen(posix_names[meta_type]));
-    return vlc_gettext (posix_names[meta_type]);
+    assert(meta_type < ARRAY_SIZE(posix_names));
+    assert(posix_names[meta_type][0] != '\0');
+    return posix_names[meta_type];
+}
+
+/* FIXME bad name convention */
+const char * vlc_meta_TypeToLocalizedString( vlc_meta_type_t meta_type )
+{
+    return vlc_gettext(vlc_meta_TypeToString(meta_type));
 }
 
 


=====================================
src/libvlccore.sym
=====================================
@@ -651,6 +651,7 @@ vlc_meta_New
 vlc_meta_Set
 vlc_meta_SetStatus
 vlc_meta_TypeToLocalizedString
+vlc_meta_TypeToString
 vlc_mime_Ext2Mime
 vlc_mutex_init
 vlc_mutex_init_recursive



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f7848ef09990972db8013e45e3dc342ae1c58930...2390f360d663c44a97821444765520b2acf0a91a

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/f7848ef09990972db8013e45e3dc342ae1c58930...2390f360d663c44a97821444765520b2acf0a91a
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list