# 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 \
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)
*/
#include "maevies_movie.h"
+#include "movie_info_provider.h"
#include "extra_scenes_provider.h"
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);
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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_ */
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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_ */
#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"