[Xfce4-commits] <tumbler:nick/omdb-thumbnailer> Add omdb thumbnailer.
Nick Schermer
noreply at xfce.org
Mon Dec 10 21:04:02 CET 2012
Updating branch refs/heads/nick/omdb-thumbnailer
to 04eeb1e76afb7843ac9445dfae78255fcb5be32d (commit)
from 089c57799b024cd3e5ccb0eff38d793776938840 (commit)
commit 04eeb1e76afb7843ac9445dfae78255fcb5be32d
Author: Nick Schermer <nick at xfce.org>
Date: Mon Dec 10 17:43:35 2012 +0100
Add omdb thumbnailer.
Thumbnailer tries to make something nice of the
filename and pass that to omdbapi.com. The returned
XML is used to look for a posted on imdb.com.
acinclude.m4 | 20 +
configure.ac | 9 +-
plugins/Makefile.am | 1 +
.../Makefile.am | 28 +-
.../omdb-thumbnailer-plugin.c} | 14 +-
.../omdb-thumbnailer-provider.c} | 72 ++--
.../omdb-thumbnailer/omdb-thumbnailer-provider.h | 43 ++
plugins/omdb-thumbnailer/omdb-thumbnailer.c | 441 ++++++++++++++++++++
plugins/omdb-thumbnailer/omdb-thumbnailer.h | 43 ++
9 files changed, 618 insertions(+), 53 deletions(-)
diff --git a/acinclude.m4 b/acinclude.m4
index e84b8c3..042cdff 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -241,6 +241,26 @@ AC_MSG_RESULT([$ac_tumbler_raw_thumbnailer])
+dnl TUMBLER_OMDB_THUMBNAILER()
+dnl
+dnl Check whether to build and install the Open Movie Database thumbnailer plugin.
+dnl
+AC_DEFUN([TUMBLER_OMDB_THUMBNAILER],
+[
+AC_ARG_ENABLE([pixbuf-thumbnailer], [AC_HELP_STRING([--disable-omdb-thumbnailer], [Don't build the Open Movie Database thumbnailer plugin])],
+ [ac_tumbler_omdb_thumbnailer=$enableval], [ac_tumbler_omdb_thumbnailer=yes])
+if test x"$ac_tumbler_omdb_thumbnailer" = x"yes"; then
+ dnl Check for gdk-pixbuf
+ PKG_CHECK_MODULES([GDK_PIXBUF], [gdk-pixbuf-2.0 >= 2.14], [], [ac_tumbler_omdb_thumbnailer=no])
+fi
+
+AC_MSG_CHECKING([whether to build the Open Movie Database thumbnailer plugin])
+AM_CONDITIONAL([TUMBLER_OMDB_THUMBNAILER], [test x"$ac_tumbler_omdb_thumbnailer" = x"yes"])
+AC_MSG_RESULT([$ac_tumbler_omdb_thumbnailer])
+])
+
+
+
dnl TUMBLER_XDG_CACHE()
dnl
dnl Check whether to build and install the freedesktop.org cache plugin.
diff --git a/configure.ac b/configure.ac
index f41c3a3..da47395 100644
--- a/configure.ac
+++ b/configure.ac
@@ -157,6 +157,7 @@ TUMBLER_PIXBUF_THUMBNAILER()
TUMBLER_FFMPEG_THUMBNAILER()
TUMBLER_GSTREAMER_THUMBNAILER()
TUMBLER_ODF_THUMBNAILER()
+TUMBLER_OMDB_THUMBNAILER()
TUMBLER_POPPLER_THUMBNAILER()
TUMBLER_RAW_THUMBNAILER()
TUMBLER_XDG_CACHE()
@@ -190,6 +191,7 @@ plugins/jpeg-thumbnailer/Makefile
plugins/pixbuf-thumbnailer/Makefile
plugins/ffmpeg-thumbnailer/Makefile
plugins/odf-thumbnailer/Makefile
+plugins/omdb-thumbnailer/Makefile
plugins/poppler-thumbnailer/Makefile
plugins/raw-thumbnailer/Makefile
plugins/xdg-cache/Makefile
@@ -206,7 +208,7 @@ dnl ***************************
echo
echo "Build Configuration:"
echo
-echo " * Debug: $enable_debug"
+echo " * Debug: $enable_debug"
echo
echo "Plugins:"
echo
@@ -235,6 +237,11 @@ echo " * Video thumbnailer plugin using GStreamer: yes"
else
echo " * Video thumbnailer plugin using GStreamer: no"
fi
+if test x"$ac_tumbler_omdb_thumbnailer" = x"yes"; then
+echo " * Video thumbnailer plugin using omdbapi.com: yes"
+else
+echo " * Video thumbnailer plugin using omdbapi.com: no"
+fi
if test x"$ac_tumbler_odf_thumbnailer" = x"yes"; then
echo " * ODF thumbnailer plugin using libgsf: yes"
else
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index aec18cc..e588846 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -24,6 +24,7 @@ SUBDIRS = \
pixbuf-thumbnailer \
ffmpeg-thumbnailer \
odf-thumbnailer \
+ omdb-thumbnailer \
poppler-thumbnailer \
raw-thumbnailer \
xdg-cache
diff --git a/plugins/pixbuf-thumbnailer/Makefile.am b/plugins/omdb-thumbnailer/Makefile.am
similarity index 72%
copy from plugins/pixbuf-thumbnailer/Makefile.am
copy to plugins/omdb-thumbnailer/Makefile.am
index 2852a46..f437750 100644
--- a/plugins/pixbuf-thumbnailer/Makefile.am
+++ b/plugins/omdb-thumbnailer/Makefile.am
@@ -1,6 +1,6 @@
# vi:set ts=8 sw=8 noet ai nocindent:
# -
-# Copyright (c) 2009-2012 Jannis Pohlmann <jannis at xfce.org>
+# Copyright (c) 2012 Nick Schermer <nick at xfce.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
@@ -17,25 +17,25 @@
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
-if TUMBLER_PIXBUF_THUMBNAILER
+if TUMBLER_OMDB_THUMBNAILER
tumbler_plugindir = $(libdir)/tumbler-$(TUMBLER_VERSION_API)/plugins
tumbler_plugin_LTLIBRARIES = \
- tumbler-pixbuf-thumbnailer.la
+ tumbler-omdb-thumbnailer.la
-tumbler_pixbuf_thumbnailer_la_SOURCES = \
- pixbuf-thumbnailer-plugin.c \
- pixbuf-thumbnailer-provider.c \
- pixbuf-thumbnailer-provider.h \
- pixbuf-thumbnailer.c \
- pixbuf-thumbnailer.h
+tumbler_omdb_thumbnailer_la_SOURCES = \
+ omdb-thumbnailer-plugin.c \
+ omdb-thumbnailer-provider.c \
+ omdb-thumbnailer-provider.h \
+ omdb-thumbnailer.c \
+ omdb-thumbnailer.h
-tumbler_pixbuf_thumbnailer_la_CFLAGS = \
+tumbler_omdb_thumbnailer_la_CFLAGS = \
-I$(top_builddir) \
-I$(top_builddir)/plugins \
-I$(top_srcdir) \
-I$(top_srcdir)/plugins \
- -DG_LOG_DOMAIN=\"tumbler-pixbuf-thumbnailer\" \
+ -DG_LOG_DOMAIN=\"tumbler-omdb-thumbnailer\" \
-DPACKAGE_LOCALE_DIR=\"$(localedir)\" \
$(GDK_PIXBUF_CFLAGS) \
$(GIO_CFLAGS) \
@@ -43,20 +43,20 @@ tumbler_pixbuf_thumbnailer_la_CFLAGS = \
$(PLATFORM_CFLAGS) \
$(PLATFORM_CPPFLAGS)
-tumbler_pixbuf_thumbnailer_la_LDFLAGS = \
+tumbler_omdb_thumbnailer_la_LDFLAGS = \
-avoid-version \
-export-dynamic \
-module \
$(PLATFORM_LDFLAGS)
-tumbler_pixbuf_thumbnailer_la_LIBADD = \
+tumbler_omdb_thumbnailer_la_LIBADD = \
$(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la \
$(GDK_PIXBUF_LIBS) \
$(GIO_LIBS) \
$(GLIB_LIBS) \
-lm
-tumbler_pixbuf_thumbnailer_la_DEPENDENCIES = \
+tumbler_omdb_thumbnailer_la_DEPENDENCIES = \
$(top_builddir)/tumbler/libtumbler-$(TUMBLER_VERSION_API).la
endif
diff --git a/plugins/odf-thumbnailer/odf-thumbnailer-plugin.c b/plugins/omdb-thumbnailer/omdb-thumbnailer-plugin.c
similarity index 85%
copy from plugins/odf-thumbnailer/odf-thumbnailer-plugin.c
copy to plugins/omdb-thumbnailer/omdb-thumbnailer-plugin.c
index 3463c5a..d85b8fe 100644
--- a/plugins/odf-thumbnailer/odf-thumbnailer-plugin.c
+++ b/plugins/omdb-thumbnailer/omdb-thumbnailer-plugin.c
@@ -29,8 +29,8 @@
#include <tumbler/tumbler.h>
-#include <odf-thumbnailer/odf-thumbnailer-provider.h>
-#include <odf-thumbnailer/odf-thumbnailer.h>
+#include <omdb-thumbnailer/omdb-thumbnailer-provider.h>
+#include <omdb-thumbnailer/omdb-thumbnailer.h>
@@ -61,15 +61,15 @@ tumbler_plugin_initialize (TumblerProviderPlugin *plugin)
}
#ifdef DEBUG
- g_message (_("Initializing the Tumbler ODF Thumbnailer plugin"));
+ g_message (_("Initializing the Tumbler OMDB Thumbnailer plugin"));
#endif
/* register the types provided by this plugin */
- odf_thumbnailer_register (plugin);
- odf_thumbnailer_provider_register (plugin);
+ omdb_thumbnailer_register (plugin);
+ omdb_thumbnailer_provider_register (plugin);
/* set up the plugin provider type list */
- type_list[0] = TYPE_ODF_THUMBNAILER_PROVIDER;
+ type_list[0] = TYPE_OMDB_THUMBNAILER_PROVIDER;
}
@@ -78,7 +78,7 @@ void
tumbler_plugin_shutdown (void)
{
#ifdef DEBUG
- g_message (_("Shutting down the Tumbler ODF Thumbnailer plugin"));
+ g_message (_("Shutting down the Tumbler OMDB Thumbnailer plugin"));
#endif
}
diff --git a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c b/plugins/omdb-thumbnailer/omdb-thumbnailer-provider.c
similarity index 52%
copy from plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c
copy to plugins/omdb-thumbnailer/omdb-thumbnailer-provider.c
index b76adee..2dd54f3 100644
--- a/plugins/ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.c
+++ b/plugins/omdb-thumbnailer/omdb-thumbnailer-provider.c
@@ -1,7 +1,6 @@
/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
- * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
- * Copyright (c) 2010 Lionel Le Folgoc <mrpouit at ubuntu.com>
+ * Copyright (c) 2012 Nick Schermer <nick at xfce.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -30,106 +29,117 @@
#include <tumbler/tumbler.h>
-#include <ffmpeg-thumbnailer/ffmpeg-thumbnailer-provider.h>
-#include <ffmpeg-thumbnailer/ffmpeg-thumbnailer.h>
+#include <omdb-thumbnailer/omdb-thumbnailer-provider.h>
+#include <omdb-thumbnailer/omdb-thumbnailer.h>
-static void ffmpeg_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface);
-static GList *ffmpeg_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider);
+static void omdb_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface);
+static GList *omdb_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider);
-struct _FfmpegThumbnailerProviderClass
+struct _OmdbThumbnailerProviderClass
{
GObjectClass __parent__;
};
-struct _FfmpegThumbnailerProvider
+struct _OmdbThumbnailerProvider
{
GObject __parent__;
};
-G_DEFINE_DYNAMIC_TYPE_EXTENDED (FfmpegThumbnailerProvider,
- ffmpeg_thumbnailer_provider,
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (OmdbThumbnailerProvider,
+ omdb_thumbnailer_provider,
G_TYPE_OBJECT,
0,
TUMBLER_ADD_INTERFACE (TUMBLER_TYPE_THUMBNAILER_PROVIDER,
- ffmpeg_thumbnailer_provider_thumbnailer_provider_init));
+ omdb_thumbnailer_provider_thumbnailer_provider_init));
void
-ffmpeg_thumbnailer_provider_register (TumblerProviderPlugin *plugin)
+omdb_thumbnailer_provider_register (TumblerProviderPlugin *plugin)
{
- ffmpeg_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin));
+ omdb_thumbnailer_provider_register_type (G_TYPE_MODULE (plugin));
}
static void
-ffmpeg_thumbnailer_provider_class_init (FfmpegThumbnailerProviderClass *klass)
+omdb_thumbnailer_provider_class_init (OmdbThumbnailerProviderClass *klass)
{
}
static void
-ffmpeg_thumbnailer_provider_class_finalize (FfmpegThumbnailerProviderClass *klass)
+omdb_thumbnailer_provider_class_finalize (OmdbThumbnailerProviderClass *klass)
{
}
static void
-ffmpeg_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface)
+omdb_thumbnailer_provider_thumbnailer_provider_init (TumblerThumbnailerProviderIface *iface)
{
- iface->get_thumbnailers = ffmpeg_thumbnailer_provider_get_thumbnailers;
+ iface->get_thumbnailers = omdb_thumbnailer_provider_get_thumbnailers;
}
static void
-ffmpeg_thumbnailer_provider_init (FfmpegThumbnailerProvider *provider)
+omdb_thumbnailer_provider_init (OmdbThumbnailerProvider *provider)
{
}
static GList *
-ffmpeg_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
+omdb_thumbnailer_provider_get_thumbnailers (TumblerThumbnailerProvider *provider)
{
static const gchar *mime_types[] =
{
+ "application/asx",
+ "application/ogg",
+ "application/x-flash-video",
+ "application/x-ms-wmp",
+ "application/x-ms-wms",
+ "application/x-ogg",
+ "video/3gpp",
+ "video/divx",
+ "video/flv",
"video/jpeg",
"video/mp4",
- "video/mp2t",
"video/mpeg",
+ "video/ogg",
"video/quicktime",
+ "video/x-flv",
+ "video/x-m4v",
+ "video/x-matroska",
"video/x-ms-asf",
"video/x-ms-wm",
+ "video/x-ms-wmp",
"video/x-ms-wmv",
+ "video/x-ms-wvx",
"video/x-msvideo",
- "video/x-flv",
- "application/x-flash-video",
- "application/vnd.rn-realmedia",
- "video/3gpp",
- "video/x-matroska",
- "video/ogg",
+ "video/x-ogg",
+ "video/x-wmv",
NULL
};
- FfmpegThumbnailer *thumbnailer;
- GList *thumbnailers = NULL;
- GStrv uri_schemes;
+ OmdbThumbnailer *thumbnailer;
+ GList *thumbnailers = NULL;
+ GStrv uri_schemes;
/* determine the URI schemes supported by GIO */
uri_schemes = tumbler_util_get_supported_uri_schemes ();
/* create the pixbuf thumbnailer */
- thumbnailer = g_object_new (TYPE_FFMPEG_THUMBNAILER,
- "uri-schemes", uri_schemes, "mime-types", mime_types,
+ thumbnailer = g_object_new (TYPE_OMDB_THUMBNAILER,
+ "uri-schemes", uri_schemes,
+ "mime-types", mime_types,
NULL);
/* add the thumbnailer to the list */
diff --git a/plugins/omdb-thumbnailer/omdb-thumbnailer-provider.h b/plugins/omdb-thumbnailer/omdb-thumbnailer-provider.h
new file mode 100644
index 0000000..c2be23d
--- /dev/null
+++ b/plugins/omdb-thumbnailer/omdb-thumbnailer-provider.h
@@ -0,0 +1,43 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2009 Jannis Pohlmann <jannis at xfce.org>
+ *
+ * This 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.
+ *
+ * This 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __OMDB_THUMBNAILER_PROVIDER_H__
+#define __OMDB_THUMBNAILER_PROVIDER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TYPE_OMDB_THUMBNAILER_PROVIDER (omdb_thumbnailer_provider_get_type ())
+#define OMDB_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_OMDB_THUMBNAILER_PROVIDER, OmdbThumbnailerProvider))
+#define OMDB_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_OMDB_THUMBNAILER_PROVIDER, OmdbThumbnailerProviderClass))
+#define IS_OMDB_THUMBNAILER_PROVIDER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_OMDB_THUMBNAILER_PROVIDER))
+#define IS_OMDB_THUMBNAILER_PROVIDER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_OMDB_THUMBNAILER_PROVIDER)
+#define OMDB_THUMBNAILER_PROVIDER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_OMDB_THUMBNAILER_PROVIDER, OmdbThumbnailerProviderClass))
+
+typedef struct _OmdbThumbnailerProviderClass OmdbThumbnailerProviderClass;
+typedef struct _OmdbThumbnailerProvider OmdbThumbnailerProvider;
+
+GType omdb_thumbnailer_provider_get_type (void) G_GNUC_CONST;
+void omdb_thumbnailer_provider_register (TumblerProviderPlugin *plugin);
+
+G_END_DECLS
+
+#endif /* !__OMDB_THUMBNAILER_PROVIDER_H__ */
diff --git a/plugins/omdb-thumbnailer/omdb-thumbnailer.c b/plugins/omdb-thumbnailer/omdb-thumbnailer.c
new file mode 100644
index 0000000..66d048b
--- /dev/null
+++ b/plugins/omdb-thumbnailer/omdb-thumbnailer.c
@@ -0,0 +1,441 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2012 Nick Schermer <nick at xfce.org>
+ *
+ * This 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.
+ *
+ * This 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ * Parts are based on the gsf-office-thumbnailer in libgsf, which is
+ * written by Federico Mena-Quintero <federico at novell.com>.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <math.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <glib-object.h>
+
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <tumbler/tumbler.h>
+
+#include <omdb-thumbnailer/omdb-thumbnailer.h>
+
+
+
+#define SERIES_PATTERN "\\b((?:s\\d{1,2}e\\d{1,2}|\\d{1,2}x\\d{1,2}))\\b"
+#define ABBREV_PATTERN "\\b(\\w{1,}(?:rip|scr)|r5|hdtv|(?:480|720|1080)p|\\.(?:avi|mpe?g|mkv|ts))\\b"
+#define YEAR_PATTERN "\\b(\\d{4})\\b"
+#define OMDB_URI "http://www.omdbapi.com/?r=xml&t="
+
+
+static void omdb_thumbnailer_finalize (GObject *object);
+static void omdb_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
+ GCancellable *cancellable,
+ TumblerFileInfo *info);
+
+
+
+struct _OmdbThumbnailerClass
+{
+ TumblerAbstractThumbnailerClass __parent__;
+};
+
+struct _OmdbThumbnailer
+{
+ TumblerAbstractThumbnailer __parent__;
+
+ /* precompiled */
+ GRegex *series_regex;
+ GRegex *abbrev_regex;
+ GRegex *year_regex;
+};
+
+
+
+G_DEFINE_DYNAMIC_TYPE (OmdbThumbnailer,
+ omdb_thumbnailer,
+ TUMBLER_TYPE_ABSTRACT_THUMBNAILER);
+
+
+
+void
+omdb_thumbnailer_register (TumblerProviderPlugin *plugin)
+{
+ omdb_thumbnailer_register_type (G_TYPE_MODULE (plugin));
+}
+
+
+
+static void
+omdb_thumbnailer_class_init (OmdbThumbnailerClass *klass)
+{
+ TumblerAbstractThumbnailerClass *abstractthumbnailer_class;
+ GObjectClass *gobject_class;
+
+ abstractthumbnailer_class = TUMBLER_ABSTRACT_THUMBNAILER_CLASS (klass);
+ abstractthumbnailer_class->create = omdb_thumbnailer_create;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = omdb_thumbnailer_finalize;
+}
+
+
+
+static void
+omdb_thumbnailer_class_finalize (OmdbThumbnailerClass *klass)
+{
+}
+
+
+
+static void
+omdb_thumbnailer_init (OmdbThumbnailer *thumbnailer)
+{
+ /* prepare the regular expressions */
+ thumbnailer->series_regex = g_regex_new (SERIES_PATTERN, G_REGEX_CASELESS, 0, NULL);
+ thumbnailer->abbrev_regex = g_regex_new (ABBREV_PATTERN, G_REGEX_CASELESS, 0, NULL);
+ thumbnailer->year_regex = g_regex_new (YEAR_PATTERN, 0, 0, NULL);
+}
+
+
+
+static void
+omdb_thumbnailer_finalize (GObject *object)
+{
+ OmdbThumbnailer *omdb = OMDB_THUMBNAILER (object);
+
+ /* cleanup */
+ g_regex_unref (omdb->series_regex);
+ g_regex_unref (omdb->abbrev_regex);
+ g_regex_unref (omdb->year_regex);
+
+ (*G_OBJECT_CLASS (omdb_thumbnailer_parent_class)->finalize) (object);
+}
+
+
+
+static void
+omdb_thumbnailer_size_prepared (GdkPixbufLoader *loader,
+ gint source_width,
+ gint source_height,
+ TumblerThumbnail *thumbnail)
+{
+ TumblerThumbnailFlavor *flavor;
+ gint dest_width;
+ gint dest_height;
+ gdouble hratio;
+ gdouble wratio;
+
+ g_return_if_fail (GDK_IS_PIXBUF_LOADER (loader));
+ g_return_if_fail (TUMBLER_IS_THUMBNAIL (thumbnail));
+
+ /* get the destination size */
+ flavor = tumbler_thumbnail_get_flavor (thumbnail);
+ tumbler_thumbnail_flavor_get_size (flavor, &dest_width, &dest_height);
+ g_object_unref (flavor);
+
+ if (source_width <= dest_width && source_height <= dest_height)
+ {
+ /* do not scale the image */
+ dest_width = source_width;
+ dest_height = source_height;
+ }
+ else
+ {
+ /* determine which axis needs to be scaled down more */
+ wratio = (gdouble) source_width / (gdouble) dest_width;
+ hratio = (gdouble) source_height / (gdouble) dest_height;
+
+ /* adjust the other axis */
+ if (hratio > wratio)
+ dest_width = rint (source_width / hratio);
+ else
+ dest_height = rint (source_height / wratio);
+ }
+
+ gdk_pixbuf_loader_set_size (loader, MAX (dest_width, 1), MAX (dest_height, 1));
+}
+
+
+
+static GdkPixbuf *
+mdb_thumbnailer_load_poster_pixbuf (GFile *gfile,
+ TumblerThumbnail *thumbnail,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gchar *data;
+ GdkPixbufLoader *loader;
+ gsize len;
+ GdkPixbuf *pixbuf = NULL;
+
+ g_return_val_if_fail (G_IS_FILE (gfile), NULL);
+ g_return_val_if_fail (G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail (TUMBLER_IS_THUMBNAIL (thumbnail), NULL);
+
+ /* load the jpg image from imdb.com */
+ if (!g_file_load_contents (gfile, cancellable, &data, &len, NULL, error))
+ return NULL;
+
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ g_free (data);
+ return NULL;
+ }
+
+ if (G_LIKELY (data != NULL))
+ {
+ /* create a loader */
+ loader = gdk_pixbuf_loader_new ();
+ g_signal_connect (loader, "size-prepared",
+ G_CALLBACK (omdb_thumbnailer_size_prepared), thumbnail);
+
+ /* write the jpg data into the loader */
+ if (gdk_pixbuf_loader_write (loader, (const guchar *) data, len, error)
+ && gdk_pixbuf_loader_close (loader, error))
+ {
+ /* take the pixbuf */
+ pixbuf = gdk_pixbuf_loader_get_pixbuf (loader);
+ if (G_LIKELY (pixbuf != NULL))
+ g_object_ref (pixbuf);
+ }
+
+ g_object_unref (loader);
+ g_free (data);
+ }
+
+ return pixbuf;
+}
+
+
+
+static GFile *
+omdb_thumbnailer_load_metadata_poster (GFile *gfile,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gchar *data;
+ const gchar *p;
+ const gchar *k = NULL;
+ gchar *uri;
+ GFile *poster_gfile = NULL;
+
+ g_return_val_if_fail (G_IS_FILE (gfile), NULL);
+ g_return_val_if_fail (G_IS_CANCELLABLE (cancellable), NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ /* load movie metadata from omdbapi.com */
+ if (!g_file_load_contents (gfile, cancellable, &data, NULL, NULL, error))
+ return NULL;
+
+ if (g_cancellable_is_cancelled (cancellable))
+ {
+ g_free (data);
+ return NULL;
+ }
+
+ if (G_LIKELY (data != NULL))
+ {
+ /* look for the poster start and end pointers */
+ p = strstr (data, "poster=\"http://");
+ if (p != NULL)
+ {
+ p += 8; /* advance to http */
+ k = strchr (p, '"');
+ }
+
+ if (p != NULL && k != NULL)
+ {
+ /* extract the imdb poster url from the xml */
+ uri = g_strndup (p, k - p);
+ poster_gfile = g_file_new_for_uri (uri);
+ g_assert (g_file_has_uri_scheme (poster_gfile, "http"));
+ g_free (uri);
+ }
+
+ g_free (data);
+ }
+
+ if (poster_gfile == NULL)
+ {
+ /* nothing in the xml */
+ uri = g_file_get_uri (G_FILE (gfile));
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ _("No poster key in XML from \"%s\""), uri);
+ g_free (uri);
+ }
+
+ return poster_gfile;
+}
+
+
+
+static void
+omdb_thumbnailer_create (TumblerAbstractThumbnailer *thumbnailer,
+ GCancellable *cancellable,
+ TumblerFileInfo *info)
+{
+ OmdbThumbnailer *omdb = OMDB_THUMBNAILER (thumbnailer);
+ const gchar *uri;
+ GFile *gfile;
+ gchar *basename;
+ gboolean is_series;
+ GMatchInfo *match_info;
+ gint start_pos;
+ gint end_pos;
+ GString *query;
+ gchar *year = NULL;
+ guint title_len = 0;
+ gboolean append_space;
+ const gchar *p;
+ gunichar uchar;
+ TumblerThumbnail *thumbnail;
+ TumblerImageData data;
+ GFile *poster_gfile;
+ GError *error = NULL;
+ GdkPixbuf *pixbuf;
+
+ uri = tumbler_file_info_get_uri (info);
+ gfile = g_file_new_for_uri (uri);
+ basename = g_file_get_basename (gfile);
+ g_object_unref (gfile);
+
+ thumbnail = tumbler_file_info_get_thumbnail (info);
+
+ /* check if the basename matches looks like a serie */
+ is_series = g_regex_match (omdb->series_regex, basename, 0, &match_info);
+
+ /* if this is not a serie, look for other filename crap */
+ if (is_series
+ || g_regex_match (omdb->abbrev_regex, basename, 0, &match_info))
+ {
+ /* remove series or abbrev suffix from the filename */
+ if (g_match_info_fetch_pos (match_info, 0, &start_pos, NULL)
+ && start_pos > 0)
+ basename[start_pos] = '\0';
+ g_match_info_free (match_info);
+
+ if (!is_series)
+ {
+ /* for non-series, look for a year in the title */
+ if (g_regex_match (omdb->year_regex, basename, 0, &match_info))
+ {
+ /* store year and remove the suffix from the title */
+ if (g_match_info_fetch_pos (match_info, 0, &start_pos, &end_pos)
+ && start_pos > 0
+ && end_pos > start_pos)
+ {
+ year = g_strndup (basename + start_pos, end_pos - start_pos);
+ basename[start_pos] = '\0';
+ }
+ g_match_info_free (match_info);
+ }
+ }
+ }
+
+ /* initial query for omdb */
+ query = g_string_new (OMDB_URI);
+
+ /* append the possible title part of the filename */
+ for (p = basename, append_space = FALSE; *p != '\0'; p = g_utf8_next_char (p))
+ {
+ uchar = g_utf8_get_char (p);
+ if (g_unichar_isalnum (uchar)
+ || uchar == '\'')
+ {
+ if (append_space)
+ {
+ g_string_append_c (query, '+');
+ append_space = FALSE;
+ }
+
+ /* append the char */
+ g_string_append_unichar (query, uchar);
+ title_len++;
+ }
+ else if (title_len > 0)
+ {
+ /* start with a space next time we append a char */
+ append_space = TRUE;
+ }
+ }
+
+ if (G_LIKELY (title_len >= 2))
+ {
+ /* append year if we found one */
+ if (year != NULL)
+ g_string_append_printf (query, "&y=%s", year);
+
+ /* load the poster uri from the metadata */
+ gfile = g_file_new_for_uri (query->str);
+ poster_gfile = omdb_thumbnailer_load_metadata_poster (gfile, cancellable, &error);
+ g_object_unref (gfile);
+
+ if (poster_gfile != NULL)
+ {
+ /* load the image from imdb */
+ pixbuf = mdb_thumbnailer_load_poster_pixbuf (poster_gfile, thumbnail, cancellable, &error);
+ g_object_unref (poster_gfile);
+
+ if (G_LIKELY (pixbuf != NULL))
+ {
+ /* prepare the image data */
+ data.data = gdk_pixbuf_get_pixels (pixbuf);
+ data.has_alpha = gdk_pixbuf_get_has_alpha (pixbuf);
+ data.bits_per_sample = gdk_pixbuf_get_bits_per_sample (pixbuf);
+ data.width = gdk_pixbuf_get_width (pixbuf);
+ data.height = gdk_pixbuf_get_height (pixbuf);
+ data.rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+ data.colorspace = (TumblerColorspace) gdk_pixbuf_get_colorspace (pixbuf);
+
+ tumbler_thumbnail_save_image_data (thumbnail, &data,
+ tumbler_file_info_get_mtime (info),
+ cancellable, &error);
+
+ g_object_unref (pixbuf);
+ }
+ }
+ }
+ else
+ {
+ g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_INVALID_FILENAME,
+ _("Movie title is too short"));
+ }
+
+ /* return the status */
+ if (error != NULL)
+ {
+ g_signal_emit_by_name (thumbnailer, "error",
+ tumbler_file_info_get_uri (info),
+ error->code, error->message);
+ g_error_free (error);
+ }
+ else
+ {
+ g_signal_emit_by_name (thumbnailer, "ready",
+ tumbler_file_info_get_uri (info));
+ }
+
+ /* cleanup */
+ g_free (basename);
+ g_string_free (query, TRUE);
+ g_free (year);
+ g_object_unref (thumbnail);
+}
diff --git a/plugins/omdb-thumbnailer/omdb-thumbnailer.h b/plugins/omdb-thumbnailer/omdb-thumbnailer.h
new file mode 100644
index 0000000..bff0e1f
--- /dev/null
+++ b/plugins/omdb-thumbnailer/omdb-thumbnailer.h
@@ -0,0 +1,43 @@
+/* vi:set et ai sw=2 sts=2 ts=2: */
+/*-
+ * Copyright (c) 2012 Nick Schermer <nick at xfce.org>
+ *
+ * This 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.
+ *
+ * This 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 this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __OMDB_THUMBNAILER_H__
+#define __OMDB_THUMBNAILER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define TYPE_OMDB_THUMBNAILER (omdb_thumbnailer_get_type ())
+#define OMDB_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_OMDB_THUMBNAILER, OmdbThumbnailer))
+#define OMDB_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_OMDB_THUMBNAILER, OmdbThumbnailerClass))
+#define IS_OMDB_THUMBNAILER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_OMDB_THUMBNAILER))
+#define IS_OMDB_THUMBNAILER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_OMDB_THUMBNAILER)
+#define OMDB_THUMBNAILER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_OMDB_THUMBNAILER, OmdbThumbnailerClass))
+
+typedef struct _OmdbThumbnailerClass OmdbThumbnailerClass;
+typedef struct _OmdbThumbnailer OmdbThumbnailer;
+
+GType omdb_thumbnailer_get_type (void) G_GNUC_CONST;
+void omdb_thumbnailer_register (TumblerProviderPlugin *plugin);
+
+G_END_DECLS
+
+#endif /* !__OMDB_THUMBNAILER_H__ */
More information about the Xfce4-commits
mailing list