[totem-pl-parser] Parse links to video websites
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [totem-pl-parser] Parse links to video websites
- Date: Tue, 14 Dec 2010 14:06:37 +0000 (UTC)
commit e3feb714f97c10fda5a7723a5567546c136fff81
Author: Bastien Nocera <hadess hadess net>
Date: Wed Nov 24 16:24:14 2010 +0000
Parse links to video websites
And load them up as videos. Add totem_pl_parser_can_parse_from_uri
that could be used with the mini parser.
Expand the starttime parsing to include the YouTube format.
https://bugzilla.gnome.org/show_bug.cgi?id=635709
configure.in | 25 +++++++
plparse/Makefile.am | 2 +
plparse/plparser-mini.symbols | 1 +
plparse/plparser.symbols | 1 +
plparse/tests/parser.c | 14 ++++
plparse/totem-pl-parser-mini.h | 2 +
plparse/totem-pl-parser-videosite.c | 132 +++++++++++++++++++++++++++++++++++
plparse/totem-pl-parser-videosite.h | 49 +++++++++++++
plparse/totem-pl-parser.c | 40 +++++++++++
9 files changed, 266 insertions(+), 0 deletions(-)
---
diff --git a/configure.in b/configure.in
index 2cc69a6..af47014 100644
--- a/configure.in
+++ b/configure.in
@@ -100,6 +100,25 @@ else
**************************************************************"
fi
+enable_quvi=auto
+AC_ARG_ENABLE(enable-quvi,
+ AS_HELP_STRING([--enable-quvi],
+ [Enable libquvi support (default is auto).]),
+ [enable_quvi=$enableval],
+ [enable_quvi=auto])
+if test "x$enable_quvi" != "xno" ; then
+ PKG_CHECK_MODULES(QUVI,
+ libquvi,
+ [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"
+ AC_DEFINE(HAVE_QUVI, 1, [libquvi available in the system])
+ fi
+fi
+
dnl Check for packages for building libtotem-plparser.la
PKG_CHECK_MODULES(TOTEM_PLPARSER, [$pkg_modules])
AC_SUBST(TOTEM_PLPARSER_CFLAGS)
@@ -151,6 +170,12 @@ docs/reference/version.xml
AC_OUTPUT
+if test "x$have_quvi" = "xyes"; then
+ AC_MSG_NOTICE([** Quvi video link parsing enabled])
+else
+ AC_MSG_NOTICE([ Quvi video link parsing disabled])
+fi
+
echo "
$gmime_message
"
diff --git a/plparse/Makefile.am b/plparse/Makefile.am
index ac4a18c..8ef1233 100644
--- a/plparse/Makefile.am
+++ b/plparse/Makefile.am
@@ -33,6 +33,7 @@ plparser_sources = \
totem-pl-parser-podcast.c \
totem-pl-parser-qt.c \
totem-pl-parser-smil.c \
+ totem-pl-parser-videosite.c \
totem-pl-parser-wm.c \
totem-pl-parser-xspf.c
@@ -52,6 +53,7 @@ dist_libtotem_plparser_la_SOURCES = \
totem-pl-parser-private.h \
totem-pl-parser-qt.h \
totem-pl-parser-smil.h \
+ totem-pl-parser-videosite.h \
totem-pl-parser-wm.h \
totem-pl-parser-xspf.h \
totem-pl-playlist.c \
diff --git a/plparse/plparser-mini.symbols b/plparse/plparser-mini.symbols
index 40de6c7..5a117a2 100644
--- a/plparse/plparser-mini.symbols
+++ b/plparse/plparser-mini.symbols
@@ -1,2 +1,3 @@
totem_pl_parser_can_parse_from_data
totem_pl_parser_can_parse_from_filename
+totem_pl_parser_can_parse_from_uri
diff --git a/plparse/plparser.symbols b/plparse/plparser.symbols
index ec58c94..bb51a43 100644
--- a/plparse/plparser.symbols
+++ b/plparse/plparser.symbols
@@ -10,6 +10,7 @@ totem_pl_parser_add_ignored_mimetype
totem_pl_parser_add_ignored_scheme
totem_pl_parser_can_parse_from_data
totem_pl_parser_can_parse_from_filename
+totem_pl_parser_can_parse_from_uri
totem_pl_parser_error_get_type
totem_pl_parser_error_quark
totem_pl_parser_get_type
diff --git a/plparse/tests/parser.c b/plparse/tests/parser.c
index a73c033..64ab3f6 100644
--- a/plparse/tests/parser.c
+++ b/plparse/tests/parser.c
@@ -134,6 +134,8 @@ test_duration (void)
g_assert_cmpint (totem_pl_parser_parse_duration ("01:00:01.01", verbose), ==, 3601);
g_assert_cmpint (totem_pl_parser_parse_duration ("01:00.01", verbose), ==, 60);
g_assert_cmpint (totem_pl_parser_parse_duration ("24.59", verbose), ==, 1499);
+ g_assert_cmpint (totem_pl_parser_parse_duration ("02m25s", verbose), ==, 145);
+ g_assert_cmpint (totem_pl_parser_parse_duration ("2m25s", verbose), ==, 145);
}
static void
@@ -210,6 +212,17 @@ test_data_get_data (const char *uri, guint *len)
}
static void
+test_videosite (void)
+{
+#ifdef HAVE_QUVI
+ char *uri = "http://www.youtube.com/watch?v=oMLCrzy9TEs";
+
+ g_test_message ("Testing data parsing \"%s\"...", uri);
+ g_assert (totem_pl_parser_can_parse_from_uri (uri, TRUE));
+#endif
+}
+
+static void
test_parsability (void)
{
guint i;
@@ -915,6 +928,7 @@ main (int argc, char *argv[])
g_test_add_func ("/parser/relative", test_relative);
g_test_add_func ("/parser/resolution", test_resolution);
g_test_add_func ("/parser/parsability", test_parsability);
+ g_test_add_func ("/parser/videosite", test_videosite);
g_test_add_func ("/parser/parsing/hadess", test_parsing_hadess);
g_test_add_func ("/parser/parsing/nonexistent_files", test_parsing_nonexistent_files);
g_test_add_func ("/parser/parsing/broken_asx", test_parsing_broken_asx);
diff --git a/plparse/totem-pl-parser-mini.h b/plparse/totem-pl-parser-mini.h
index c1ec9e4..9a19429 100644
--- a/plparse/totem-pl-parser-mini.h
+++ b/plparse/totem-pl-parser-mini.h
@@ -32,6 +32,8 @@ gboolean totem_pl_parser_can_parse_from_data (const char *data,
gboolean debug);
gboolean totem_pl_parser_can_parse_from_filename (const char *filename,
gboolean debug);
+gboolean totem_pl_parser_can_parse_from_uri (const char *uri,
+ gboolean debug);
G_END_DECLS
diff --git a/plparse/totem-pl-parser-videosite.c b/plparse/totem-pl-parser-videosite.c
new file mode 100644
index 0000000..0a09966
--- /dev/null
+++ b/plparse/totem-pl-parser-videosite.c
@@ -0,0 +1,132 @@
+/*
+ Copyright (C) 2010 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 <string.h>
+#include <glib.h>
+
+#ifndef TOTEM_PL_PARSER_MINI
+#include "totem-disc.h"
+#endif /* !TOTEM_PL_PARSER_MINI */
+
+#if HAVE_QUVI
+#include <quvi/quvi.h>
+#endif
+
+#include "totem-pl-parser-mini.h"
+#include "totem-pl-parser-videosite.h"
+#include "totem-pl-parser-private.h"
+
+gboolean
+totem_pl_parser_is_videosite (const char *uri, gboolean debug)
+{
+ quvi_t handle;
+ QUVIcode rc;
+
+ if (quvi_init (&handle) != QUVI_OK)
+ return FALSE;
+
+ rc = quvi_supported(handle, (char *) uri);
+ quvi_close (&handle);
+
+ if (debug)
+ g_print ("Checking videosite for URI '%s' returned %d (%s)",
+ uri, rc, (rc == QUVI_OK) ? "true" : "false");
+
+ return (rc == QUVI_OK);
+}
+
+#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,
+ GFile *base_file,
+ TotemPlParseData *parse_data,
+ gpointer data)
+{
+#if HAVE_QUVI
+ QUVIcode rc;
+ quvi_t handle;
+ quvi_video_t v;
+ 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;
+
+ if (quvi_init (&handle) != QUVI_OK)
+ return TOTEM_PL_PARSER_RESULT_ERROR;
+
+ 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", uri, rc);
+ }
+ g_free (uri);
+ quvi_close (&handle);
+ return TOTEM_PL_PARSER_RESULT_ERROR;
+ }
+
+ getprop (QUVIPROP_VIDEOURL, video_uri);
+ if (quvi_getprop (v, QUVIPROP_VIDEOFILELENGTH, &length) == QUVI_OK)
+ length_str = g_strdup_printf ("%f", length);
+ else
+ length_str = NULL;
+ getprop (QUVIPROP_PAGETITLE, title);
+ getprop (QUVIPROP_VIDEOID, id);
+ getprop (QUVIPROP_PAGEURL, page_uri);
+ getprop (QUVIPROP_STARTTIME, starttime);
+
+ length_str = g_strdup_printf ("%d", (int) length);
+ 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,
+ NULL);
+ g_free (uri);
+ g_free (length_str);
+
+ quvi_parse_close (&v);
+ quvi_close (&handle);
+
+ return TOTEM_PL_PARSER_RESULT_SUCCESS;
+#else
+ return TOTEM_PL_PARSER_RESULT_UNHANDLED;
+#endif /* !HAVE_QUVI */
+}
+
+#endif /* !TOTEM_PL_PARSER_MINI */
+
diff --git a/plparse/totem-pl-parser-videosite.h b/plparse/totem-pl-parser-videosite.h
new file mode 100644
index 0000000..ef21514
--- /dev/null
+++ b/plparse/totem-pl-parser-videosite.h
@@ -0,0 +1,49 @@
+/*
+ Copyright (C) 2010 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>
+ */
+
+#ifndef TOTEM_PL_PARSER_VIDEOSITE_H
+#define TOTEM_PL_PARSER_VIDEOSITE_H
+
+G_BEGIN_DECLS
+
+#ifndef TOTEM_PL_PARSER_MINI
+#include "totem-pl-parser.h"
+#include "totem-pl-parser-private.h"
+#include <gio/gio.h>
+#else
+#include "totem-pl-parser-mini.h"
+#endif /* !TOTEM_PL_PARSER_MINI */
+
+gboolean totem_pl_parser_is_videosite (const char *uri, gboolean debug);
+
+#ifndef TOTEM_PL_PARSER_MINI
+
+TotemPlParserResult totem_pl_parser_add_videosite (TotemPlParser *parser,
+ GFile *file,
+ GFile *base_file,
+ TotemPlParseData *parse_data,
+ gpointer data);
+
+#endif /* !TOTEM_PL_PARSER_MINI */
+
+G_END_DECLS
+
+#endif /* TOTEM_PL_PARSER_VIDEOSITE_H */
diff --git a/plparse/totem-pl-parser.c b/plparse/totem-pl-parser.c
index c8f577c..67c4db4 100644
--- a/plparse/totem-pl-parser.c
+++ b/plparse/totem-pl-parser.c
@@ -154,6 +154,10 @@
#include "totem-pl-parser-misc.h"
#include "totem-pl-parser-private.h"
+#ifdef HAVE_QUVI
+#include "totem-pl-parser-videosite.h"
+#endif
+
#define READ_CHUNK_SIZE 8192
#define RECURSE_LEVEL_MAX 4
@@ -1788,6 +1792,20 @@ totem_pl_parser_parse_internal (TotemPlParser *parser,
if (!parse_data->recurse && parse_data->recurse_level > 0)
return TOTEM_PL_PARSER_RESULT_UNHANDLED;
+#if HAVE_QUVI
+ /* Should we try to parse it with quvi? */
+ if (g_file_has_uri_scheme (file, "http")) {
+ char *url;
+ url = g_file_get_uri (file);
+ if (url != NULL && totem_pl_parser_is_videosite (url, parser->priv->debug) != FALSE) {
+ ret = totem_pl_parser_add_videosite (parser, file, base_file, parse_data, NULL);
+ if (ret == TOTEM_PL_PARSER_RESULT_SUCCESS)
+ return ret;
+ }
+ g_free (url);
+ }
+#endif /* HAVE_QUVI */
+
/* In force mode we want to get the data */
if (parse_data->force != FALSE) {
mimetype = my_g_file_info_get_mime_type_with_data (file, &data, parser);
@@ -2253,6 +2271,11 @@ totem_pl_parser_parse_duration (const char *duration, gboolean debug)
D(g_print ("Used broken float format (00.00)\n"));
return minutes * 60 + seconds;
}
+ /* YouTube format */
+ if (sscanf (duration, "%dm%ds", &minutes, &seconds) == 2) {
+ D(g_print ("Used YouTube format\n"));
+ return minutes * 60 + seconds;
+ }
/* PLS files format */
if (sscanf (duration, "%d", &seconds) == 1) {
D(g_print ("Used PLS format\n"));
@@ -2442,6 +2465,23 @@ totem_pl_parser_can_parse_from_filename (const char *filename, gboolean debug)
return retval;
}
+/**
+ * totem_pl_parser_can_parse_from_uri:
+ * @uri: the remote URI to check for parsability
+ * @debug: %TRUE if debug statements should be printed
+ *
+ * Checks if the remote URI can be parsed. Note that this does
+ * not actually try to open the remote URI, or deduce its mime-type
+ * from filename, as this would bring too many false positives.
+ *
+ * Return value: %TRUE if @uri could be parsed
+ **/
+gboolean
+totem_pl_parser_can_parse_from_uri (const char *uri, gboolean debug)
+{
+ return totem_pl_parser_is_videosite (uri, debug);
+}
+
#ifndef TOTEM_PL_PARSER_MINI
GType
totem_pl_parser_metadata_get_type (void)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]