[tracker] Playlist to TTL translation tool
- From: Ivan Frade <ifrade src gnome org>
- To: svn-commits-list gnome org
- Subject: [tracker] Playlist to TTL translation tool
- Date: Mon, 13 Jul 2009 11:26:45 +0000 (UTC)
commit 4372664f081f8a6c71c605cbba92559833c2535e
Author: Ivan Frade <ivan frade nokia com>
Date: Mon Jul 13 14:16:09 2009 +0300
Playlist to TTL translation tool
Small program to translate a playlist into turtle format.
configure.ac | 1 +
utils/Makefile.am | 1 +
utils/playlists/Makefile.am | 19 +++++++
utils/playlists/playlist2ttl.c | 117 ++++++++++++++++++++++++++++++++++++++++
4 files changed, 138 insertions(+), 0 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d204634..b3b31a5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1449,6 +1449,7 @@ AC_CONFIG_FILES([
utils/albumart/Makefile
utils/tracker-fts/Makefile
utils/services/Makefile
+ utils/playlists/Makefile
])
AC_OUTPUT
diff --git a/utils/Makefile.am b/utils/Makefile.am
index 4419038..0f2ec1b 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -3,4 +3,5 @@ include $(top_srcdir)/Makefile.decl
SUBDIRS = \
albumart \
services \
+ playlists \
tracker-fts
diff --git a/utils/playlists/Makefile.am b/utils/playlists/Makefile.am
new file mode 100644
index 0000000..fd1607e
--- /dev/null
+++ b/utils/playlists/Makefile.am
@@ -0,0 +1,19 @@
+include $(top_srcdir)/Makefile.decl
+
+noinst_PROGRAMS = playlist2ttl
+
+INCLUDES = \
+ -DG_LOG_DOMAIN=\"Tracker\" \
+ $(WARN_CFLAGS) \
+ $(GLIB2_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(TOTEM_PL_PARSER_CFLAGS)
+
+playlist2ttl_SOURCES = \
+ playlist2ttl.c
+
+playlist2ttl_LDADD = \
+ $(TOTEM_PL_PARSER_LIBS) \
+ $(GLIB2_LIBS) \
+ $(GIO_LIBS) \
+ $(GCOV_LIBS)
\ No newline at end of file
diff --git a/utils/playlists/playlist2ttl.c b/utils/playlists/playlist2ttl.c
new file mode 100644
index 0000000..844c26d
--- /dev/null
+++ b/utils/playlists/playlist2ttl.c
@@ -0,0 +1,117 @@
+#include <glib.h>
+#include <gio/gio.h>
+#include <totem-pl-parser.h>
+
+static gchar **filenames = NULL;
+
+typedef struct {
+ gint tracks ;
+ gchar *playlist;
+} PlaylistData;
+
+static GOptionEntry entries[] = {
+ { G_OPTION_REMAINING, 0, G_OPTION_FLAG_FILENAME, G_OPTION_ARG_FILENAME_ARRAY, &filenames,
+ "FILE",
+ NULL
+ },
+ { NULL }
+};
+
+static void
+print_header ()
+{
+ g_print ("@prefix nmo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nmo#>.\n");
+ g_print ("@prefix nfo: <http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#>.\n");
+ g_print ("@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.\n");
+ g_print ("\n");
+}
+
+static void
+print_playlist_entry (const gchar *uri) {
+ g_print ("<%s> a nfo:MediaList .\n\n", uri);
+}
+
+static void
+entry_parsed (TotemPlParser *parser, const gchar *uri, GHashTable *metadata, gpointer user_data)
+{
+ PlaylistData *playlist_data = (PlaylistData *)user_data;
+
+ playlist_data->tracks += 1;
+
+ //uri = g_hash_table_lookup (metadata, TOTEM_PL_PARSER_FIELD_URI);
+ g_print ("<%s> nfo:hasMediaFileListEntry [ \n",
+ playlist_data->playlist);
+ g_print ("\t a nfo:MediaFileListEntry ; \n");
+ g_print ("\t nfo:listPosition %d ; \n", playlist_data->tracks);
+ g_print ("\t nfo:entryContent <%s> ] .\n\n", uri);
+}
+
+gint
+main (gint argc, gchar **argv)
+{
+ GFile *file;
+ GOptionContext *context = NULL;
+ gchar *uri;
+ PlaylistData playlist_data = { 0, NULL};
+ TotemPlParser *pl;
+ TotemPlParserResult result;
+ GError *error = NULL;
+
+ g_type_init ();
+
+ context = g_option_context_new ("- Parse a playlist and show info");
+
+ g_option_context_add_main_entries (context, entries, NULL);
+ g_option_context_parse (context, &argc, &argv, NULL);
+
+ if (!g_option_context_parse (context, &argc, &argv, &error) || !filenames) {
+ gchar *help;
+
+ g_printerr ("%s\n\n",
+ "Playlist filename is mandatory");
+
+ help = g_option_context_get_help (context, TRUE, NULL);
+ g_option_context_free (context);
+ g_printerr ("%s", help);
+ g_free (help);
+
+ return -1;
+ }
+
+ file = g_file_new_for_commandline_arg (filenames[0]);
+ uri = g_file_get_uri (file);
+
+ print_header ();
+ print_playlist_entry (uri);
+ playlist_data.playlist = uri;
+
+ pl = totem_pl_parser_new ();
+
+ g_object_set (pl, "recurse", FALSE, "disable-unsafe", TRUE, NULL);
+ g_signal_connect (G_OBJECT (pl), "entry-parsed", G_CALLBACK (entry_parsed), &playlist_data);
+
+
+
+ result = totem_pl_parser_parse (pl, uri, FALSE);
+
+ switch (result) {
+ case TOTEM_PL_PARSER_RESULT_SUCCESS:
+ break;
+ case TOTEM_PL_PARSER_RESULT_IGNORED:
+ g_print ("Error: Ignored (%s)\n", uri);
+ break;
+ case TOTEM_PL_PARSER_RESULT_ERROR:
+ g_print ("Error: Failed parsing (%s)\n", uri);
+ break;
+ case TOTEM_PL_PARSER_RESULT_UNHANDLED:
+ g_print ("Error: Unhandled type (%s)\n", uri);
+ break;
+ default:
+ g_print ("Undefined result!?!?!");
+ }
+
+ g_object_unref (pl);
+
+ return 0;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]