[grilo-plugins] youtube: Use totem-pl-parser to resolve URI



commit c03a80506c18c95cd44f4e38202ca62f1104578c
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Jul 8 09:52:09 2013 +0200

    youtube: Use totem-pl-parser to resolve URI
    
    Instead of libquvi directly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703396

 configure.ac              |   10 ++++----
 src/youtube/grl-youtube.c |   57 ++++++++++++++++++--------------------------
 2 files changed, 28 insertions(+), 39 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f5545c7..350c3f4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -464,14 +464,14 @@ AC_ARG_ENABLE(youtube,
                         if test "x$HAVE_GDATA" = "xno"; then
                            AC_MSG_ERROR([libgdata not found, install it or use --disable-youtube])
                         fi
-                        if test "x$HAVE_QUVI" = "xno"; then
-                           AC_MSG_ERROR([libquvi not found, install it or use --disable-youtube])
+                        if test "x$HAVE_TOTEM_PL_PARSER" = "xno"; then
+                           AC_MSG_ERROR([totem-pl-parser not found, install it or use --disable-youtube])
                         fi
                         ;;
                 esac
         ],
         [
-                if test "x$HAVE_GRLNET" = "xyes" -a "x$HAVE_XML" = "xyes" -a "x$HAVE_GDATA" = "xyes" -a 
"x$HAVE_QUVI" = "xyes"; then
+                if test "x$HAVE_GRLNET" = "xyes" -a "x$HAVE_XML" = "xyes" -a "x$HAVE_GDATA" = "xyes" -a 
"x$HAVE_TOTEM_PL_PARSER" = "xyes"; then
                    enable_youtube=yes
                 else
                    enable_youtube=no
@@ -489,9 +489,9 @@ YOUTUBE_PLUGIN_ID="grl-youtube"
 AC_SUBST(YOUTUBE_PLUGIN_ID)
 AC_DEFINE_UNQUOTED([YOUTUBE_PLUGIN_ID], ["$YOUTUBE_PLUGIN_ID"], [YouTube plugin ID])
 
-DEPS_YOUTUBE_CFLAGS="$DEPS_CFLAGS $GRLNET_CFLAGS $XML_CFLAGS $GTHREAD_CFLAGS $GDATA_CFLAGS $QUVI_CFLAGS"
+DEPS_YOUTUBE_CFLAGS="$DEPS_CFLAGS $GRLNET_CFLAGS $XML_CFLAGS $GTHREAD_CFLAGS $GDATA_CFLAGS 
$TOTEM_PL_PARSER_CFLAGS"
 AC_SUBST(DEPS_YOUTUBE_CFLAGS)
-DEPS_YOUTUBE_LIBS="$DEPS_LIBS $GRLNET_LIBS $XML_LIBS $GTHREAD_LIBS $GDATA_LIBS $QUVI_LIBS"
+DEPS_YOUTUBE_LIBS="$DEPS_LIBS $GRLNET_LIBS $XML_LIBS $GTHREAD_LIBS $GDATA_LIBS $TOTEM_PL_PARSER_LIBS"
 AC_SUBST(DEPS_YOUTUBE_LIBS)
 
 # ----------------------------------------------------------
diff --git a/src/youtube/grl-youtube.c b/src/youtube/grl-youtube.c
index 5b81bbf..b14527e 100644
--- a/src/youtube/grl-youtube.c
+++ b/src/youtube/grl-youtube.c
@@ -29,7 +29,7 @@
 #include <glib/gi18n-lib.h>
 #include <net/grl-net.h>
 #include <gdata/gdata.h>
-#include <quvi/quvi.h>
+#include <totem-pl-parser.h>
 #include <string.h>
 
 #include "grl-youtube.h"
@@ -175,7 +175,6 @@ typedef enum {
 
 struct _GrlYoutubeSourcePriv {
   GDataService *service;
-  quvi_t quvi_handle;
 
   GrlNetWc *wc;
 };
@@ -344,17 +343,6 @@ grl_youtube_source_new (const gchar *api_key, const gchar *client_id, const gcha
                                              "supported-media", GRL_MEDIA_TYPE_VIDEO,
                                             NULL));
 
-  /* Set up quvi */
-  if (quvi_init (&(source->priv->quvi_handle)) != QUVI_OK) {
-    source->priv->quvi_handle = NULL;
-  } else {
-    if (format)
-      quvi_setopt (source->priv->quvi_handle, QUVIOPT_FORMAT, format);
-    else
-      quvi_setopt (source->priv->quvi_handle, QUVIOPT_FORMAT, "mp4_360p");
-    quvi_setopt (source->priv->quvi_handle, QUVIOPT_NOVERIFY);
-  }
-
   ytsrc = source;
 
   return source;
@@ -430,15 +418,21 @@ grl_youtube_source_finalize (GObject *object)
   if (self->priv->service)
     g_object_unref (self->priv->service);
 
-  if (self->priv->quvi_handle)
-    quvi_close (&(self->priv->quvi_handle));
-
   G_OBJECT_CLASS (grl_youtube_source_parent_class)->finalize (object);
 }
 
 /* ======================= Utilities ==================== */
 
 static void
+entry_parsed_cb (TotemPlParser *parser,
+                 const char    *uri,
+                 GHashTable    *metadata,
+                 GrlMedia      *media)
+{
+  grl_media_set_url (media, uri);
+}
+
+static void
 release_operation_data (guint operation_id)
 {
   GCancellable *cancellable = grl_operation_get_data (operation_id);
@@ -551,9 +545,6 @@ build_media_from_entry (GrlYoutubeSource *source,
   GDataMediaThumbnail *thumbnail;
   GrlMedia *media;
   GList *iter;
-  quvi_media_t v;
-  QUVIcode rc;
-  gchar *url;
 
   if (!content) {
     media = grl_media_video_new ();
@@ -609,21 +600,19 @@ build_media_from_entry (GrlYoutubeSource *source,
       gdouble average;
       gdata_youtube_video_get_rating (video, NULL, NULL, NULL, &average);
       grl_media_set_rating (media, average, 5.00);
-    } else if (key == GRL_METADATA_KEY_URL && source->priv->quvi_handle) {
-      rc = quvi_parse (source->priv->quvi_handle,
-                       (char *) gdata_youtube_video_get_player_uri (video),
-                       &v);
-      if (rc == QUVI_OK) {
-        rc = quvi_getprop (v, QUVIPROP_MEDIAURL, &url);
-        if (rc == QUVI_OK) {
-          grl_media_set_url (media, url);
-        }
-        quvi_parse_close (&v);
-      }
-      else {
-       GRL_WARNING ("Failed to get video URL. libquvi error '%s'",
-                    quvi_strerror (source->priv->quvi_handle, rc));
-      }
+    } else if (key == GRL_METADATA_KEY_URL) {
+      TotemPlParser *parser;
+      TotemPlParserResult res;
+
+      parser = totem_pl_parser_new ();
+      g_signal_connect (parser, "entry-parsed",
+                        G_CALLBACK (entry_parsed_cb), media);
+      res = totem_pl_parser_parse (parser,
+                                   (char *) gdata_youtube_video_get_player_uri (video),
+                                   FALSE);
+      if (res != TOTEM_PL_PARSER_RESULT_SUCCESS)
+       GRL_WARNING ("Failed to get video URL. totem-pl-parser error '%d'", res);
+      g_clear_object (&parser);
     } else if (key == GRL_METADATA_KEY_EXTERNAL_PLAYER) {
       GDataYouTubeContent *youtube_content;
       youtube_content =


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