<commit_before>#include <glib.h>
#include <string.h>

#include <media-store.h>

#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "test-main"

static void
print_supported_ops (MsMetadataSource *source)
{
  g_debug ("  Operations available in '%s'",
	   ms_metadata_source_get_name (source));

  MsSupportedOps caps = ms_metadata_source_supported_operations (source);

  if (caps & MS_OP_METADATA) {
    g_debug ("    + Metadata");
  }
  if (caps & MS_OP_RESOLVE) {
    g_debug ("    + Resolution");
  }
  if (caps & MS_OP_BROWSE) {
    g_debug ("    + Browse");
  }
  if (caps & MS_OP_SEARCH) {
    g_debug ("    + Search");
  }
}

static void
print_metadata (MsContent *content, MsKeyID key_id)
{
  if (key_id == MS_METADATA_KEY_DESCRIPTION) {
    return;
  }

  MsPluginRegistry *registry = ms_plugin_registry_get_instance ();
  const MsMetadataKey *key = 
    ms_plugin_registry_lookup_metadata_key (registry,
					    GPOINTER_TO_UINT (key_id));

  const GValue *value = ms_content_get (MS_CONTENT(content), key_id);
  if (value && G_VALUE_HOLDS_STRING (value)) {
    g_debug ("\t%s: %s", MS_METADATA_KEY_GET_NAME (key),
	     g_value_get_string (value));
  } else if (value && G_VALUE_HOLDS_INT (value)) {
    g_debug ("\t%s: %d",  MS_METADATA_KEY_GET_NAME (key),
	     g_value_get_int (value));
  }
}

static MsContentMedia *
media_from_id (const gchar *id)
{
  MsContentMedia *media;
  media = ms_content_media_new ();
  ms_content_media_set_id (media, id);
  return media;
}

static void 
browse_cb (MsMediaSource *source,
	   guint browse_id,
           MsContentMedia *media,
	   guint remaining,
	   gpointer user_data,
	   const GError *error)
{
  MsKeyID *keys;
  gint size;
  gint i;
  static guint index = 0;

  g_debug ("  browse result (%d - %d|%d)",
	   browse_id, index++, remaining);

  if (error) {
    g_error ("Got error from browse: %s", error->message);
  }

  if (!media && remaining == 0) {
    g_debug ("  No results");
    return;
  }

  g_debug ("\tContainer: %s",
	   IS_MS_CONTENT_BOX(media) ? "yes" : "no");

  keys = ms_content_get_keys (MS_CONTENT (media), &size);
  for (i = 0; i < size; i++) {
    print_metadata (MS_CONTENT (media), keys[i]);
  }
  g_free (keys);
  g_object_unref (media);

  if (remaining == 0) {
    g_debug ("  Browse operation finished");
  }
}

static void 
metadata_cb (MsMediaSource *source,
	     MsContentMedia *media,
	     gpointer user_data,
	     const GError *error)
{
  MsKeyID *keys;
  gint size;
  gint i;

  g_debug ("  metadata_cb");

  if (error) {
    g_debug ("Error: %s", error->message);
    return;
  }
  
  g_debug ("    Got metadata for object '%s'",
	   ms_content_media_get_id (MS_CONTENT_MEDIA (media)));

  g_debug ("\tContainer: %s",
	   IS_MS_CONTENT_BOX(media) ? "yes" : "no");

  keys = ms_content_get_keys (MS_CONTENT (media), &size);
  for (i = 0; i < size; i++) {
    print_metadata (MS_CONTENT (media), keys[i]);
  }
  g_free (keys);
  g_object_unref (media);

  g_debug ("  Metadata operation finished");
}

gint
main (void)
{
  GList *keys;

  g_type_init ();

  ms_log_init ("*:warning,test-main:*,ms-youtube:*,ms-filesystem:*,ms-jamendo:*");

  keys = ms_metadata_key_list_new (MS_METADATA_KEY_ID,
				   MS_METADATA_KEY_TITLE,
				   MS_METADATA_KEY_URL,
                                   MS_METADATA_KEY_ALBUM,
                                   MS_METADATA_KEY_ARTIST,
                                   MS_METADATA_KEY_GENRE,
                                   MS_METADATA_KEY_THUMBNAIL,
				   MS_METADATA_KEY_DESCRIPTION,
				   MS_METADATA_KEY_AUTHOR,
                                   MS_METADATA_KEY_LYRICS,
				   MS_METADATA_KEY_DURATION,
				   MS_METADATA_KEY_CHILDCOUNT,
				   MS_METADATA_KEY_MIME,<commit_msg>Refactor ms_content_get_keys so it returns a GList instead of an array.<commit_after>#include <glib.h>
#include <string.h>

#include <media-store.h>

#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "test-main"

static void
print_supported_ops (MsMetadataSource *source)
{
  g_debug ("  Operations available in '%s'",
	   ms_metadata_source_get_name (source));

  MsSupportedOps caps = ms_metadata_source_supported_operations (source);

  if (caps & MS_OP_METADATA) {
    g_debug ("    + Metadata");
  }
  if (caps & MS_OP_RESOLVE) {
    g_debug ("    + Resolution");
  }
  if (caps & MS_OP_BROWSE) {
    g_debug ("    + Browse");
  }
  if (caps & MS_OP_SEARCH) {
    g_debug ("    + Search");
  }
}

static void
print_metadata (gpointer key, MsContent *content)
{
  MsKeyID key_id = POINTER_TO_MSKEYID(key);

  if (key_id == MS_METADATA_KEY_DESCRIPTION) {
    return;
  }

  MsPluginRegistry *registry = ms_plugin_registry_get_instance ();
  const MsMetadataKey *mkey =
    ms_plugin_registry_lookup_metadata_key (registry, key_id);

  const GValue *value = ms_content_get (content, key_id);
  if (value && G_VALUE_HOLDS_STRING (value)) {
    g_debug ("\t%s: %s", MS_METADATA_KEY_GET_NAME (mkey),
	     g_value_get_string (value));
  } else if (value && G_VALUE_HOLDS_INT (value)) {
    g_debug ("\t%s: %d",  MS_METADATA_KEY_GET_NAME (mkey),
	     g_value_get_int (value));
  }
}

static MsContentMedia *
media_from_id (const gchar *id)
{
  MsContentMedia *media;
  media = ms_content_media_new ();
  ms_content_media_set_id (media, id);
  return media;
}

static void
browse_cb (MsMediaSource *source,
	   guint browse_id,
           MsContentMedia *media,
	   guint remaining,
	   gpointer user_data,
	   const GError *error)
{
  GList *keys;
  static guint index = 0;

  g_debug ("  browse result (%d - %d|%d)",
	   browse_id, index++, remaining);

  if (error) {
    g_error ("Got error from browse: %s", error->message);
  }

  if (!media && remaining == 0) {
    g_debug ("  No results");
    return;
  }

  g_debug ("\tContainer: %s",
	   IS_MS_CONTENT_BOX(media) ? "yes" : "no");

  keys = ms_content_get_keys (MS_CONTENT (media));
  g_list_foreach (keys, (GFunc) print_metadata, MS_CONTENT (media));
  g_list_free (keys);
  g_object_unref (media);

  if (remaining == 0) {
    g_debug ("  Browse operation finished");
  }
}

static void
metadata_cb (MsMediaSource *source,
	     MsContentMedia *media,
	     gpointer user_data,
	     const GError *error)
{
  GList *keys;

  g_debug ("  metadata_cb");

  if (error) {
    g_debug ("Error: %s", error->message);
    return;
  }

  g_debug ("    Got metadata for object '%s'",
	   ms_content_media_get_id (MS_CONTENT_MEDIA (media)));

  g_debug ("\tContainer: %s",
	   IS_MS_CONTENT_BOX(media) ? "yes" : "no");

  keys = ms_content_get_keys (MS_CONTENT (media));
  g_list_foreach (keys, (GFunc) print_metadata, MS_CONTENT (media));
  g_list_free (keys);
  g_object_unref (media);

  g_debug ("  Metadata operation finished");
}

gint
main (void)
{
  GList *keys;

  g_type_init ();

  ms_log_init ("*:warning,test-main:*,ms-youtube:*,ms-filesystem:*,ms-jamendo:*");

  keys = ms_metadata_key_list_new (MS_METADATA_KEY_ID,
				   MS_METADATA_KEY_TITLE,
				   MS_METADATA_KEY_URL,
                                   MS_METADATA_KEY_ALBUM,
                                   MS_METADATA_KEY_ARTIST,
                                   MS_METADATA_KEY_GENRE,
                                   MS_METADATA_KEY_THUMBNAIL,
				   MS_METADATA_KEY_DESCRIPTION,
				   MS_METADATA_KEY_AUTHOR,
                                   MS_METADATA_KEY_LYRICS,
				   MS_METADATA_KEY_DURATION,
				   MS_METADATA_KEY_CHILDCOUNT,
				   MS_METADATA_KEY_MIME,
{'fraction_non_alphanumeric': 0.11897366644159352, 'fraction_numerical': 0.0010803511141120863, 'mean_word_length': 3.10077519379845, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5577548', 'n_tokens_mistral': 2940, 'n_tokens_neox': 2749, 'n_words': 559}