Added the movie_info_provider layer, to abstract the concrete providers from the...
authorspenap <bulfaiter@gmail.com>
Sat, 14 Nov 2009 23:49:31 +0000 (23:49 +0000)
committerspenap <bulfaiter@gmail.com>
Sat, 14 Nov 2009 23:49:31 +0000 (23:49 +0000)
git-svn-id: file:///svnroot/maevies/trunk@12 a96798e0-47ce-444a-94a4-1d14e63744fc

Makefile.am
configure.ac
src/maevies_movie.c
src/movie_info_provider.c [new file with mode: 0644]
src/movie_info_provider.h [new file with mode: 0644]
src/tmdb_movie.c [new file with mode: 0644]
src/tmdb_movie.h [new file with mode: 0644]
src/watc_provider.h

index b700ca0..7c54656 100644 (file)
@@ -23,6 +23,8 @@ bin_PROGRAMS = \
 # Sources
 maevies_SOURCES = \
         src/main.c \
+        src/movie_info_provider.c \
+        src/tmdb_movie.c \
         src/extra_scenes_provider.c \
                src/watc_provider.c \
                src/maevies_movie.c \
index 205c42a..7f3508f 100644 (file)
@@ -13,7 +13,7 @@ AC_PREFIX_DEFAULT(/usr)
 
 CFLAGS="$CFLAGS -Wall -ansi -pedantic -Wmissing-prototypes -Wmissing-declarations"
 
-PKG_CHECK_MODULES(DEPS, gtk+-2.0 >= 2.2 glib-2.0 >= 2.2 gnome-vfs-2.0 >= 2.2 rest >= 0.6)
+PKG_CHECK_MODULES(DEPS, gtk+-2.0 >= 2.2 glib-2.0 >= 2.2 gnome-vfs-2.0 >= 2.2 rest-0.6 >= 0.6)
 AC_SUBST(DEPS_CFLAGS)
 AC_SUBST(DEPS_LIBS)
 
index 7393726..cd36954 100644 (file)
@@ -17,6 +17,7 @@
  */
 
 #include "maevies_movie.h"
+#include "movie_info_provider.h"
 #include "extra_scenes_provider.h"
 
 MaeviesMovie *maevies_movie_new(const gchar *name) {
@@ -31,7 +32,7 @@ MaeviesMovie *maevies_movie_new(const gchar *name) {
 void movie_get_info(MaeviesMovie *movie, GCallback callback) {
 
        /* Get movie info */
-
+       get_info(movie);
 
        /* Get movie stingers */
        movie->has_stingers = has_stingers(movie->title);
diff --git a/src/movie_info_provider.c b/src/movie_info_provider.c
new file mode 100644 (file)
index 0000000..ac76f41
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * movie_info_provider.c
+ *
+ * This file is part of maevies
+ * Copyright (C) 2009 Simón Pena <spenap@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ */
+
+#include "movie_info_provider.h"
+#include "tmdb_movie.h"
+
+void get_info(MaeviesMovie *movie) {
+
+       TMDBMovie *tmdb_movie = tmdb_get_info(movie->title);
+
+       movie->ranking = tmdb_movie->rating;
+       movie->year = g_date_get_year(tmdb_movie->released);
+}
diff --git a/src/movie_info_provider.h b/src/movie_info_provider.h
new file mode 100644 (file)
index 0000000..4157f8d
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * movie_info_provider.h
+ *
+ * This file is part of maevies
+ * Copyright (C) 2009 Simón Pena <spenap@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ */
+
+#ifndef MOVIE_INFO_PROVIDER_H_
+#define MOVIE_INFO_PROVIDER_H_
+
+#include "maevies_movie.h"
+
+void get_info(MaeviesMovie *movie);
+
+#endif /* MOVIE_INFO_PROVIDER_H_ */
diff --git a/src/tmdb_movie.c b/src/tmdb_movie.c
new file mode 100644 (file)
index 0000000..d581ea8
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * tmdb_movie.c
+ *
+ * This file is part of maevies
+ * Copyright (C) 2009 Simón Pena <spenap@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ */
+
+#include "tmdb_movie.h"
+
+void query_tmdb(const gchar *name);
+
+static void parse_child_element(gpointer key, gpointer element, gpointer data);
+
+RestXmlNode *get_xml(RestProxyCall *call);
+
+TMDBMovie *tmdb_get_info(const gchar *name) {
+
+       TMDBMovie *movie = g_new0(TMDBMovie, 1);
+
+       movie->rating = 10;
+       movie->released = g_date_new_dmy(1, G_DATE_FEBRUARY, 2009);
+
+       query_tmdb(name);
+
+       return movie;
+}
+
+void query_tmdb(const gchar *name) {
+
+       RestProxy *proxy;
+       RestProxyCall *call;
+       gchar *tmdb_function;
+       const gchar *response;
+       RestXmlNode *root;
+       gssize len;
+
+       /* Provider initialization, should be refactored. Maybe it can be reused between calls */
+       proxy = rest_proxy_new(TMDB_SERVICE_URL, FALSE);
+       call = rest_proxy_new_call(proxy);
+
+       /* Generate the function string */
+       tmdb_function = g_strdup_printf("%s/%s/%s/%s/%s", TMDB_SEARCH_METHOD,
+                       TMDB_LANGUAGE, TMDB_FORMAT, TMDB_API_KEY, name);
+
+       rest_proxy_call_set_function(call, tmdb_function);
+
+       /* The actual call */
+       rest_proxy_call_run(call, NULL, NULL);
+
+       get_xml(call);
+
+       /* Object disposal, should be refactored. */
+       g_object_unref(call);
+       g_object_unref(proxy);
+}
+
+RestXmlNode *get_xml(RestProxyCall *call) {
+       RestXmlParser *parser;
+       RestXmlNode *root;
+       GError *error = NULL;
+
+       parser = rest_xml_parser_new();
+
+       root = rest_xml_parser_parse_from_data(parser, rest_proxy_call_get_payload(
+                       call), rest_proxy_call_get_payload_length(call));
+
+       g_hash_table_foreach(root->children, (GHFunc) parse_child_element, NULL);
+
+       g_object_unref(parser);
+
+       return root;
+}
+
+static void parse_child_element(gpointer key, gpointer element, gpointer data) {
+
+       RestXmlNode *node = (RestXmlNode*) element;
+
+       g_print("%s: ", key);
+       if (g_hash_table_size(node->children) == 0) {
+               g_print("%s", node->content);
+       }
+       g_print("\n");
+       g_hash_table_foreach(node->children, (GHFunc) parse_child_element, NULL);
+}
diff --git a/src/tmdb_movie.h b/src/tmdb_movie.h
new file mode 100644 (file)
index 0000000..ff00b22
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * tmdb_movie.h
+ *
+ * This file is part of maevies
+ * Copyright (C) 2009 Simón Pena <spenap@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ */
+
+#ifndef TMDB_MOVIE_H_
+#define TMDB_MOVIE_H_
+
+#include <stdio.h>
+#include <rest-0.6/rest/rest-proxy.h>
+#include <rest-0.6/rest/rest-proxy-call.h>
+#include <rest-0.6/rest/rest-xml-parser.h>
+
+#define TMDB_API_KEY "249e1a42df9bee09fac5e92d3a51396b"
+#define TMDB_SERVICE_URL "http://api.themoviedb.org/2.1"
+#define TMDB_LANGUAGE "en"
+#define TMDB_FORMAT "xml"
+#define TMDB_SEARCH_METHOD "Movie.search"
+
+typedef struct _TMDBMovie TMDBMovie;
+
+struct _TMDBMovie {
+
+       gint popularity;
+       const gchar *name;
+       const gchar *alternative_name;
+       gint id;
+       const gchar *imdb_id;
+       const gchar *url;
+       const gchar *overview;
+       gint rating;
+       GDate *released;
+       gint runtime;
+       // categories;
+       // images
+};
+
+TMDBMovie *tmdb_get_info(const gchar *name);
+
+#endif /* TMDB_MOVIE_H_ */
index 4192b50..0fe9a72 100644 (file)
@@ -20,7 +20,7 @@
 #define WATC_PROVIDER_H_
 
 #include <stdio.h>
-#include <rest/rest/rest-proxy.h>
+#include <rest-0.6/rest/rest-proxy.h>
 
 #define WATC_SERVICE_URL "http://whatsafterthecredits.com/api.php"