[totem-pl-parser] plparse: Port to libquvi 0.9



commit 24970018abfcedcaa4965e1f0f987aaf63323f31
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Jun 21 13:08:36 2013 +0200

    plparse: Port to libquvi 0.9
    
    https://bugzilla.gnome.org/show_bug.cgi?id=700768

 configure.ac                          |    9 +-
 plparse/Makefile.am                   |    9 ++
 plparse/totem-pl-parser-videosite.c   |  162 +++++++++++++---------------
 plparse/videosite-parser.c            |  187 +++++++++++++++++++++++++++++++++
 totem-plparser-mini-uninstalled.pc.in |    2 +-
 totem-plparser-mini.pc.in             |    2 +-
 totem-plparser-uninstalled.pc.in      |    2 +-
 totem-plparser.pc.in                  |    2 +-
 8 files changed, 281 insertions(+), 94 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index e43a528..8e87dd0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@ AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
 # Requirements
 GLIB_REQS=2.31.0
 GIO_REQS=2.24.0
-QUVI_REQS=0.2.15
+QUVI_REQS=0.9.1
 LIBARCHIVE_REQS=2.8.4
 
 # Before making a release, the PLPARSER_LT_VERSION string should be modified.
@@ -113,18 +113,19 @@ AC_ARG_ENABLE(quvi,
                             [enable_quvi=auto])
 if test "x$enable_quvi" != "xno" ; then
        PKG_CHECK_MODULES(QUVI,
-                         libquvi >= $QUVI_REQS,
+                         libquvi-0.9 >= $QUVI_REQS glib-2.0,
                          [have_quvi=yes], [have_quvi=no])
        if test "x$enable_quvi" = "xyes" -a "x$have_quvi" = "xno" ; then
                AC_MSG_ERROR([Quvi support requested but not available.])
        fi
        if test "x$have_quvi" = "xyes" ; then
-               pkg_modules="$pkg_modules libquvi"
-               QUVI="libquvi"
+               pkg_modules="$pkg_modules libquvi-0.9"
+               QUVI="libquvi-0.9"
                AC_DEFINE(HAVE_QUVI, 1, [libquvi available in the system])
        fi
 fi
 AC_SUBST(QUVI, $QUVI)
+AM_CONDITIONAL([HAVE_QUVI], [test "$have_quvi" = "yes"])
 
 ##################################
 # Checking libarchive dependency
diff --git a/plparse/Makefile.am b/plparse/Makefile.am
index f2cd2b1..13ba011 100644
--- a/plparse/Makefile.am
+++ b/plparse/Makefile.am
@@ -69,6 +69,7 @@ libtotem_plparser_la_CPPFLAGS = \
        -I$(top_srcdir)/lib                     \
        -I$(top_builddir)/plparse               \
        -DGNOMELOCALEDIR=\""$(datadir)/locale"\"\
+       -DLIBEXECDIR=\""$(libexecdir)"\"        \
        $(DISABLE_DEPRECATED)                   \
        $(AM_CPPFLAGS)
 
@@ -130,6 +131,7 @@ libtotem_plparser_mini_la_CPPFLAGS = \
        -I$(top_srcdir)/lib             \
        -I$(top_builddir)/plparse       \
        -DTOTEM_PL_PARSER_MINI          \
+       -DLIBEXECDIR=\""$(libexecdir)"\"\
        $(DISABLE_DEPRECATED)           \
        $(AM_CPPFLAGS)
 
@@ -180,6 +182,13 @@ EXTRA_DIST =                               \
        plparser.symbols                \
        plparser-mini.symbols
 
+if HAVE_QUVI
+libexec_PROGRAMS = totem-pl-parser-videosite
+totem_pl_parser_videosite_SOURCES = videosite-parser.c
+totem_pl_parser_videosite_CFLAGS = $(QUVI_CFLAGS) -DLIBEXECDIR=\""$(libexecdir)"\"
+totem_pl_parser_videosite_LDADD = $(QUVI_LIBS)
+endif
+
 # Introspection
 -include $(INTROSPECTION_MAKEFILE)
 INTROSPECTION_GIRS =
diff --git a/plparse/totem-pl-parser-videosite.c b/plparse/totem-pl-parser-videosite.c
index 631f4ca..743ef7f 100644
--- a/plparse/totem-pl-parser-videosite.c
+++ b/plparse/totem-pl-parser-videosite.c
@@ -24,36 +24,41 @@
 #include <string.h>
 #include <glib.h>
 
-#ifndef TOTEM_PL_PARSER_MINI
-#include "totem-disc.h"
-#endif /* !TOTEM_PL_PARSER_MINI */
-
-#ifdef HAVE_QUVI
-#include <quvi/quvi.h>
-#endif /* HAVE_QUVI */
-
 #include "totem-pl-parser-mini.h"
 #include "totem-pl-parser-videosite.h"
 #include "totem-pl-parser-private.h"
 
+#define BASE 20
+
 gboolean
 totem_pl_parser_is_videosite (const char *uri, gboolean debug)
 {
 #ifdef HAVE_QUVI
-       quvi_t handle;
-       QUVIcode rc;
-
-       if (quvi_init (&handle) != QUVI_OK)
-               return FALSE;
-
-       rc = quvi_supported(handle, (char *) uri);
-       quvi_close (&handle);
-
+       const char *args[] = {
+               LIBEXECDIR "/totem-pl-parser-videosite",
+               "--check",
+               "--url",
+               NULL,
+               NULL
+       };
+       char *out;
+
+       args[3] = uri;
+       g_spawn_sync (NULL,
+                     (char **) args,
+                     NULL,
+                     0,
+                     NULL,
+                     NULL,
+                     &out,
+                     NULL,
+                     NULL,
+                     NULL);
        if (debug)
-               g_print ("Checking videosite for URI '%s' returned %d (%s)\n",
-                        uri, rc, (rc == QUVI_OK) ? "true" : "false");
+               g_print ("Checking videosite for URI '%s' returned '%s' (%s)\n",
+                        uri, out, g_strcmp0 (out, "TRUE") == 0 ? "true" : "false");
 
-       return (rc == QUVI_OK);
+       return (g_strcmp0 (out, "TRUE") == 0);
 #else
        return FALSE;
 #endif /* HAVE_QUVI */
@@ -61,10 +66,6 @@ totem_pl_parser_is_videosite (const char *uri, gboolean debug)
 
 #ifndef TOTEM_PL_PARSER_MINI
 
-#define getprop(prop, p)                                       \
-       if (quvi_getprop (v, prop, &p) != QUVI_OK)              \
-               p = NULL;
-
 TotemPlParserResult
 totem_pl_parser_add_videosite (TotemPlParser *parser,
                               GFile *file,
@@ -73,75 +74,64 @@ totem_pl_parser_add_videosite (TotemPlParser *parser,
                               gpointer data)
 {
 #ifdef HAVE_QUVI
-       QUVIcode rc;
-       quvi_t handle;
-       quvi_media_t v;
+       const char *args[] = {
+               LIBEXECDIR "/totem-pl-parser-videosite",
+               "--url",
+               NULL,
+               NULL
+       };
        char *uri;
-       /* properties */
-       const char *video_uri;
-       double length;
-       char *length_str;
-       const char *title;
-       const char *id;
-       const char *page_uri;
-       const char *starttime;
-       const char *content_type;
-       const char *thumb_url;
-       double duration;
-       char *duration_str;
-
-       if (quvi_init (&handle) != QUVI_OK)
-               return TOTEM_PL_PARSER_RESULT_ERROR;
-
-       quvi_setopt(handle, QUVIOPT_NOVERIFY, TRUE);
-       quvi_setopt(handle, QUVIOPT_FORMAT, "best");
+       char *out = NULL;
+       char **lines;
+       guint i;
+       GHashTable *ht;
+       char *new_uri = NULL;
 
        uri = g_file_get_uri (file);
-       rc = quvi_parse(handle, uri, &v);
-       if (rc != QUVI_OK) {
-               if (totem_pl_parser_is_debugging_enabled (parser))
-                       g_print ("quvi_parse for '%s' returned %d\n", uri, rc);
-               g_free (uri);
-               quvi_close (&handle);
-               if (rc == QUVI_NOSUPPORT)
+
+       args[2] = uri;
+       g_spawn_sync (NULL,
+                     (char **) args,
+                     NULL,
+                     0,
+                     NULL,
+                     NULL,
+                     &out,
+                     NULL,
+                     NULL,
+                     NULL);
+       if (totem_pl_parser_is_debugging_enabled (parser))
+               g_print ("Parsing videosite for URI '%s' returned '%s'\n", uri, out);
+
+       if (out != NULL) {
+               if (g_str_equal (out, "TOTEM_PL_PARSER_RESULT_ERROR"))
+                       return TOTEM_PL_PARSER_RESULT_ERROR;
+               if (g_str_equal (out, "TOTEM_PL_PARSER_RESULT_UNHANDLED"))
                        return TOTEM_PL_PARSER_RESULT_UNHANDLED;
+       } else {
+               /* totem-pl-parser-videosite failed to launch */
                return TOTEM_PL_PARSER_RESULT_ERROR;
        }
 
-       getprop (QUVIPROP_MEDIAURL, video_uri);
-       if (quvi_getprop (v, QUVIPROP_MEDIACONTENTLENGTH, &length) == QUVI_OK && length)
-               length_str = g_strdup_printf ("%f", length);
-       else
-               length_str = NULL;
-       getprop (QUVIPROP_PAGETITLE, title);
-       getprop (QUVIPROP_MEDIAID, id);
-       getprop (QUVIPROP_PAGEURL, page_uri);
-       getprop (QUVIPROP_STARTTIME, starttime);
-       getprop (QUVIPROP_MEDIACONTENTTYPE, content_type);
-       getprop (QUVIPROP_MEDIATHUMBNAILURL, thumb_url);
-       if (quvi_getprop (v, QUVIPROP_MEDIADURATION, &duration) == QUVI_OK && duration)
-               duration_str = g_strdup_printf ("%f", duration);
-       else
-               duration_str = NULL;
-
-       if (video_uri != NULL)
-               totem_pl_parser_add_uri (parser,
-                                        TOTEM_PL_PARSER_FIELD_TITLE, title,
-                                        TOTEM_PL_PARSER_FIELD_ID, id,
-                                        TOTEM_PL_PARSER_FIELD_MOREINFO, page_uri,
-                                        TOTEM_PL_PARSER_FIELD_URI, video_uri,
-                                        TOTEM_PL_PARSER_FIELD_FILESIZE, length_str,
-                                        TOTEM_PL_PARSER_FIELD_STARTTIME, starttime,
-                                        TOTEM_PL_PARSER_FIELD_CONTENT_TYPE, content_type,
-                                        TOTEM_PL_PARSER_FIELD_IMAGE_URI, thumb_url,
-                                        TOTEM_PL_PARSER_FIELD_DURATION, duration_str,
-                                        NULL);
-       g_free (uri);
-       g_free (length_str);
-       g_free (duration_str);
-
-       quvi_parse_close (&v);
-       quvi_close (&handle);
+       ht = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+       lines = g_strsplit (out, "\n", -1);
+       g_free (out);
+       for (i = 0; lines[i] != NULL && *lines[i] != '\0'; i++) {
+               char **line;
+
+               line = g_strsplit (lines[i], "=", 2);
+               if (g_strcmp0 (line[0], TOTEM_PL_PARSER_FIELD_URI) == 0) {
+                       if (new_uri == NULL)
+                               new_uri = g_strdup (line[1]);
+               } else {
+                       g_hash_table_insert (ht, g_strdup (line[0]), g_strdup (line[1]));
+               }
+               g_strfreev (line);
+       }
+       g_strfreev (lines);
+
+       totem_pl_parser_add_hash_table (parser, ht, new_uri, FALSE);
+       g_free (new_uri);
 
        return TOTEM_PL_PARSER_RESULT_SUCCESS;
 #else
diff --git a/plparse/videosite-parser.c b/plparse/videosite-parser.c
new file mode 100644
index 0000000..657e177
--- /dev/null
+++ b/plparse/videosite-parser.c
@@ -0,0 +1,187 @@
+/*
+   Copyright (C) 2013 Bastien Nocera <hadess hadess net>
+
+   The Gnome Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301  USA.
+
+   Author: Bastien Nocera <hadess hadess net>
+ */
+
+#include "config.h"
+
+#include <glib.h>
+#include <quvi.h>
+#include "totem-pl-parser.h"
+
+#define BASE 20
+
+static char *url = NULL;
+static gboolean check = FALSE;
+static gboolean debug = FALSE;
+
+const GOptionEntry options[] = {
+       { "url", 'u', 0, G_OPTION_ARG_FILENAME, &url, "URL of the video site page", NULL },
+       { "check", 'c', 0, G_OPTION_ARG_NONE, &check, "Check whether this URL is supported", NULL },
+       { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, "Turn on debug mode", NULL },
+       { NULL }
+};
+
+static gboolean
+supports_uri (const char *uri)
+{
+       quvi_t q;
+       QuviBoolean r;
+
+       q = quvi_new ();
+       r = quvi_supports (q, uri, QUVI_SUPPORTS_MODE_OFFLINE, QUVI_SUPPORTS_TYPE_ANY);
+       quvi_free (q);
+
+       return r;
+}
+
+static struct {
+       const char *container;
+       const char *content_type;
+} containers [] = {
+       { "webm", "video/webm" },
+};
+
+static const char *
+container_to_content_type (const char *container)
+{
+       guint i;
+
+       if (container == NULL)
+               return NULL;
+       for (i = 0; i < G_N_ELEMENTS (containers); i++) {
+               if (g_str_equal (container, containers[i].container))
+                       return containers[i].content_type;
+       }
+       return NULL;
+}
+
+static void
+print (const char *name,
+       const char *value)
+{
+       g_return_if_fail (name != NULL);
+
+       if (value == NULL)
+               return;
+
+       g_print ("%s=%s\n", name, value);
+}
+
+static void
+parse_videosite (const char *uri)
+{
+       quvi_t q;
+       quvi_media_t qm;
+       /* properties */
+       const char *video_uri;
+       const char *title;
+       const char *id;
+       const char *content_type;
+       const char *thumb_url;
+       const char *container;
+       double duration;
+       double starttime;
+       char *duration_str = NULL;
+       char *starttime_str = NULL;
+
+       if (!supports_uri (uri)) {
+               g_print ("TOTEM_PL_PARSER_RESULT_UNHANDLED");
+               return;
+       }
+
+       q = quvi_new ();
+       qm = quvi_media_new (q, uri);
+
+       /* Empty results list? */
+       if (quvi_media_stream_next(qm) != QUVI_TRUE) {
+               if (debug)
+                       g_print ("Parsing '%s' failed with error: %s\n",
+                                uri, quvi_errmsg (q));
+               g_print ("TOTEM_PL_PARSER_RESULT_ERROR");
+               goto out;
+       }
+
+       /* Choose the best stream */
+       quvi_media_stream_choose_best (qm);
+
+       quvi_media_get (qm, QUVI_MEDIA_PROPERTY_TITLE, &title);
+       quvi_media_get (qm, QUVI_MEDIA_PROPERTY_ID, &id);
+       quvi_media_get (qm, QUVI_MEDIA_PROPERTY_THUMBNAIL_URL, &thumb_url);
+       quvi_media_get (qm, QUVI_MEDIA_PROPERTY_DURATION_MS, &duration);
+       if (duration)
+               duration_str = g_strdup_printf ("%f", duration);
+       quvi_media_get (qm, QUVI_MEDIA_STREAM_PROPERTY_URL, &video_uri);
+       quvi_media_get (qm, QUVI_MEDIA_PROPERTY_START_TIME_MS, &starttime);
+       if (starttime)
+               starttime_str = g_strdup_printf ("%f", starttime);
+
+       quvi_media_get (qm, QUVI_MEDIA_STREAM_PROPERTY_CONTAINER, &container);
+       content_type = container_to_content_type (container);
+
+       if (video_uri != NULL) {
+               print (TOTEM_PL_PARSER_FIELD_TITLE, title);
+               print (TOTEM_PL_PARSER_FIELD_ID, id);
+               print (TOTEM_PL_PARSER_FIELD_MOREINFO, uri);
+               print (TOTEM_PL_PARSER_FIELD_URI, video_uri);
+               print (TOTEM_PL_PARSER_FIELD_STARTTIME, starttime_str);
+               print (TOTEM_PL_PARSER_FIELD_CONTENT_TYPE, content_type);
+               print (TOTEM_PL_PARSER_FIELD_IMAGE_URI, thumb_url);
+               print (TOTEM_PL_PARSER_FIELD_DURATION, duration_str);
+       }
+
+       g_free (starttime_str);
+       g_free (duration_str);
+
+out:
+       quvi_media_free (qm);
+       quvi_free (q);
+}
+
+int main (int argc, char **argv)
+{
+       GOptionContext *context;
+
+       context = g_option_context_new (NULL);
+       g_option_context_set_summary (context, "totem-pl-parser libquvi Helper");
+       g_option_context_add_main_entries (context, options, NULL);
+       g_option_context_parse (context, &argc, &argv, NULL);
+
+       if (url == NULL) {
+               char *txt;
+
+               txt = g_option_context_get_help (context, FALSE, NULL);
+               g_print ("%s", txt);
+               g_free (txt);
+
+               g_option_context_free (context);
+
+               return 1;
+       }
+       g_option_context_free (context);
+
+       if (check) {
+               g_print ("%s", supports_uri (url) ? "TRUE" : "FALSE");
+               return 0;
+       }
+
+       parse_videosite (url);
+
+       return 0;
+}
diff --git a/totem-plparser-mini-uninstalled.pc.in b/totem-plparser-mini-uninstalled.pc.in
index cb6c437..fb22f66 100644
--- a/totem-plparser-mini-uninstalled.pc.in
+++ b/totem-plparser-mini-uninstalled.pc.in
@@ -7,6 +7,6 @@ Name: totem-plparser
 Description: Totem Playlist Parser library
 Version: @VERSION@
 Requires: glib-2.0 gobject-2.0 gio-2.0
-Requires.private: gthread-2.0 @QUVI@
+Requires.private: gthread-2.0
 Libs: ${pc_top_builddir}/${pcfiledir}/plparse/libtotem-plparser-mini.la
 Cflags: -I${pc_top_builddir}/${pcfiledir}/plparse
diff --git a/totem-plparser-mini.pc.in b/totem-plparser-mini.pc.in
index 777b93b..29ae520 100644
--- a/totem-plparser-mini.pc.in
+++ b/totem-plparser-mini.pc.in
@@ -7,6 +7,6 @@ Name: totem-plparser-mini
 Description: Totem Playlist Parser library, mini version
 Version: @VERSION@
 Requires: glib-2.0 gobject-2.0 gio-2.0
-Requires.private: gthread-2.0 @QUVI@
+Requires.private: gthread-2.0
 Libs: -L${libdir} -ltotem-plparser-mini
 Cflags: -I${includedir}/totem-pl-parser/1/plparser
diff --git a/totem-plparser-uninstalled.pc.in b/totem-plparser-uninstalled.pc.in
index 6a3d0be..7264037 100644
--- a/totem-plparser-uninstalled.pc.in
+++ b/totem-plparser-uninstalled.pc.in
@@ -7,7 +7,7 @@ Name: totem-plparser
 Description: Totem Playlist Parser library
 Version: @VERSION@
 Requires: glib-2.0 gobject-2.0 gio-2.0
-Requires.private: gthread-2.0 libxml-2.0 @GMIME@ @QUVI@
+Requires.private: gthread-2.0 libxml-2.0 @GMIME@
 Libs: ${pc_top_builddir}/${pcfiledir}/plparse/libtotem-plparser.la
 Libs.private: @LIBGCRYPT_LIBS@
 Cflags: -I${pc_top_builddir}/${pcfiledir}/plparse @LIBGCRYPT_CFLAGS@
diff --git a/totem-plparser.pc.in b/totem-plparser.pc.in
index abf3cdd..16f9240 100644
--- a/totem-plparser.pc.in
+++ b/totem-plparser.pc.in
@@ -7,7 +7,7 @@ Name: totem-plparser
 Description: Totem Playlist Parser library
 Version: @VERSION@
 Requires: glib-2.0 gobject-2.0 gio-2.0
-Requires.private: gthread-2.0 libxml-2.0 @GMIME@ @QUVI@ @ARCHIVE@
+Requires.private: gthread-2.0 libxml-2.0 @GMIME@ @ARCHIVE@
 Libs: -L${libdir} -ltotem-plparser
 Libs.private: @LIBGCRYPT_LIBS@
 Cflags: -I${includedir}/totem-pl-parser/1/plparser @LIBGCRYPT_CFLAGS@


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]