1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2006 Jonathan Matthew <jonathan@kaolin.hn.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The Rhythmbox authors hereby grant permission for non-GPL compatible
* GStreamer plugins to be used and distributed together with GStreamer
* and Rhythmbox. This permission is above and beyond the permissions granted
* by the GPL license by which Rhythmbox is covered. If you modify this code
* you may extend this exception to your version of the code, but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
* Test client for out-of-process metadata reader.
*/
#include <config.h>
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "rb-metadata.h"
#include "rb-metadata-dbus.h"
#include "rb-debug.h"
static RBMetaData *md = NULL;
static gboolean debug = FALSE;
static gboolean can_save = FALSE;
static GOptionEntry entries [] = {
{ "debug", 0, 0, G_OPTION_ARG_NONE, &debug, NULL, NULL },
{ "can-save", 0, 0, G_OPTION_ARG_NONE, &can_save, NULL, NULL },
{ NULL }
};
static void
print_metadata_string (RBMetaData *md, RBMetaDataField field, const char *name)
{
GValue v = {0,};
if (rb_metadata_get (md, field, &v)) {
char *s;
s = g_strdup_value_contents (&v);
printf ("%s: %s\n", name, s);
g_free (s);
g_value_unset (&v);
}
}
static gboolean
check_can_save_cb (gpointer mt)
{
char *media_type = (char *)mt;
if (rb_metadata_can_save (md, media_type)) {
printf ("Can save %s\n", media_type);
} else {
printf ("Unable to save %s\n", media_type);
}
return FALSE;
}
static gboolean
load_metadata_cb (gpointer file)
{
char *uri = (char *)file;
char **missing_plugins;
char **plugin_descriptions;
GError *error = NULL;
RBMetaDataField f;
if (strncmp (uri, "file://", 7)) {
if (uri[0] == '/') {
uri = g_filename_to_uri (uri, NULL, NULL);
} else {
char buf[1024];
if (getcwd (buf, sizeof (buf)) != NULL) {
char *filename;
filename = g_build_filename (buf, uri, NULL);
uri = g_filename_to_uri (filename, NULL, NULL);
g_free (filename);
}
}
}
printf ("%s\n", (const char *)uri);
rb_metadata_load (md, (const char *)uri, &error);
if (error) {
printf ("error: %s\n", error->message);
g_clear_error (&error);
}
printf ("type: %s\n", rb_metadata_get_media_type (md));
for (f =(RBMetaDataField)0; f < RB_METADATA_FIELD_LAST; f++)
print_metadata_string (md, f, rb_metadata_get_field_name (f));
printf ("has audio: %d\n", rb_metadata_has_audio (md));
printf ("has video: %d\n", rb_metadata_has_video (md));
printf ("has other data: %d\n", rb_metadata_has_other_data (md));
if (rb_metadata_get_missing_plugins (md, &missing_plugins, &plugin_descriptions)) {
int i = 0;
g_print ("missing plugins:\n");
while (missing_plugins[i] != NULL) {
g_print ("\t%s (%s)\n", missing_plugins[i], plugin_descriptions[i]);
i++;
}
g_strfreev (missing_plugins);
}
printf ("---\n");
return FALSE;
}
static gboolean
bye (gpointer nah)
{
g_main_loop_quit ((GMainLoop *)nah);
return FALSE;
}
int main(int argc, char **argv)
{
GMainLoop *loop;
int filecount = 0;
GOptionContext *context;
gboolean retval;
GError *error = NULL;
setlocale (LC_ALL, "");
context = g_option_context_new (NULL);
g_option_context_add_main_entries (context, entries, NULL);
retval = g_option_context_parse (context, &argc, &argv, &error);
g_option_context_free (context);
if (! retval) {
g_warning ("%s", error->message);
g_error_free (error);
exit (1);
}
if (debug) {
rb_debug_init (TRUE);
}
loop = g_main_loop_new (NULL, FALSE);
md = rb_metadata_new ();
while (argv[1] != NULL) {
if (can_save) {
g_idle_add (check_can_save_cb, argv[1]);
} else {
g_idle_add (load_metadata_cb, argv[1]);
}
argv++;
filecount++;
}
g_idle_add (bye, loop);
g_main_loop_run (loop);
if (can_save) {
printf ("%d file type(s) checked\n", filecount);
} else {
printf ("%d file(s) read\n", filecount);
}
g_object_unref (G_OBJECT (md));
return 0;
}
|