Regarding to TheMovieDB.org, I finished the parsing of 1 result (ignoring data if...
authorspenap <bulfaiter@gmail.com>
Sun, 15 Nov 2009 20:56:45 +0000 (20:56 +0000)
committerspenap <bulfaiter@gmail.com>
Sun, 15 Nov 2009 20:56:45 +0000 (20:56 +0000)
I modified maevies_movieschedule to get it compiling in my system. Will have to take a decission on rest/rest-0.6, and the prefix in the includes.
With <rest-0.6/rest/file.h>, eclipse allows autocompletion. But <rest/file.h> should be used to ignore the librest version.

Regarding to the examples, I modified the Makefile to allow tmdb querying.

git-svn-id: file:///svnroot/maevies/trunk@14 a96798e0-47ce-444a-94a4-1d14e63744fc

13 files changed:
examples/Makefile
examples/gmovies.c
examples/gtranslate.c
examples/test_tmdb.c [new file with mode: 0644]
src/maevies_movie.h
src/maevies_movieschedule.c
src/maevies_movieschedule.h
src/maevies_window.c
src/movie_info_provider.c
src/tmdb_movie.c
src/tmdb_movie.h
src/watc_provider.c
src/watc_provider.h

index ec9d541..4aabbff 100644 (file)
@@ -1,14 +1,18 @@
 CC = gcc
 
-LIBS_GTRANSLATE = `pkg-config rest --libs`
+LIBS_TMDB = `pkg-config rest-0.6 --libs`
 
-FLAGS_GTRANSLATE = `pkg-config rest --cflags`
+FLAGS_TMDB = `pkg-config rest-0.6 --cflags` -I../src/
 
-LIBS_GMOVIES = `pkg-config libxml-2.0 rest --libs`
+LIBS_GTRANSLATE = `pkg-config rest-0.6 --libs`
 
-FLAGS_GMOVIES = `pkg-config libxml-2.0 rest --cflags`
+FLAGS_GTRANSLATE = `pkg-config rest-0.6 --cflags`
 
-all: gtranslate gmovies
+LIBS_GMOVIES = `pkg-config libxml-2.0 rest-0.6 --libs`
+
+FLAGS_GMOVIES = `pkg-config libxml-2.0 rest-0.6 --cflags`
+
+all: gtranslate gmovies tmdb
        
 gtranslate: gtranslate.o
        $(CC) -o gtranslate gtranslate.o $(LIBS_GTRANSLATE)
@@ -21,6 +25,15 @@ gmovies: gmovies.o
 
 gmovies.o: gmovies.c
        $(CC) -g -c gmovies.c $(FLAGS_GMOVIES)
+       
+tmdb: test_tmdb.o tmdb_movie.o
+       $(CC) -ggdb -o tmdb test_tmdb.o tmdb_movie.o $(LIBS_TMDB)
+
+tmdb_movie.o: ../src/tmdb_movie.c
+       $(CC) -ggdb -c ../src/tmdb_movie.c $(FLAGS_TMDB)
+       
+test_tmdb.o: test_tmdb.c
+       $(CC) -ggdb -c test_tmdb.c $(FLAGS_TMDB)
 
 clean:
-       rm -rf gtranslate gtranslate.o gmovies gmovies.o *~
+       rm -rf gtranslate gtranslate.o gmovies gmovies.o tmdb tmdb_movie.o test_tmdb.o *~
index 5771391..1f93daa 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <libxml/HTMLparser.h>
 #include <libxml/tree.h>
-#include <rest/rest/rest-proxy.h>
+#include <rest/rest-proxy.h>
 #include <glib.h>
 #include <stdio.h>
 #include <unistd.h>
index 1974cf0..b6c3140 100644 (file)
@@ -1,5 +1,5 @@
 #include <stdio.h>
-#include <rest/rest/rest-proxy.h>
+#include <rest/rest-proxy.h>
 #include <glib.h>
 #include <unistd.h>
 
diff --git a/examples/test_tmdb.c b/examples/test_tmdb.c
new file mode 100644 (file)
index 0000000..57b83d5
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * test_tmdb.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 <glib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "tmdb_movie.h"
+
+gint main(gint argc, gchar **argv) {
+
+       TMDBMovie *movie = NULL;
+       const gchar *title = NULL;
+
+       if (argc != 2) {
+               title = "Zombieland";
+       } else {
+               title = argv[1];
+       }
+
+       g_thread_init(NULL);
+       g_type_init();
+
+       movie = tmdb_get_info(title);
+
+       tmdb_movie_print(movie);
+
+       tmdb_movie_unref(movie);
+       return 1;
+}
index ba25c7f..4b47cf5 100644 (file)
@@ -32,8 +32,10 @@ struct _MaeviesMovie {
        const gchar *title;
        gchar *director;
        GSList *cast;
-       gint ranking;
-       gint year;
+       gfloat ranking;
+       GDate *released;
+       const gchar *overview;
+       const gchar *url;
        GSList* movieScheduleList;
 
 };
index baf2c9a..0dae86a 100644 (file)
@@ -18,7 +18,6 @@
 
 #include "maevies_movieschedule.h"
 
-
 MaeviesMovieSchedule *maevies_movieschedule_new(MaeviesMovieSchedule* theater) {
 
        MaeviesMovieSchedule *ms = g_new0(MaeviesTheater,1);
@@ -28,8 +27,8 @@ MaeviesMovieSchedule *maevies_movieschedule_new(MaeviesMovieSchedule* theater) {
        return ms;
 }
 
-
-MaeviesMovieSchedule *maevies_movieschedule_new(MaeviesMovieSchedule* theater, GSList* timeList) {
+MaeviesMovieSchedule *maevies_movieschedule_new_with_list(
+               MaeviesMovieSchedule* theater, GSList* timeList) {
 
        MaeviesMovieSchedule *ms = maevies_movieschedule_new(theater);
 
index dfb0eb8..be578b1 100644 (file)
 
 G_BEGIN_DECLS
 
-struct _MaeviesMovieSchedule
-{
+struct _MaeviesMovieSchedule {
        MaeviesTheater* theater;
        GSList* timeList;
 };
 typedef struct _MaeviesMovieSchedule MaeviesMovieSchedule;
 
-
 MaeviesMovieSchedule* maevies_movieschedule_new(MaeviesTheater* theater);
 
-MaeviesMovieSchedule* maevies_movieschedule_new(MaeviesTheater* theater, GSList* tiemList);
+MaeviesMovieSchedule* maevies_movieschedule_new_with_list(
+               MaeviesTheater* theater, GSList* itemList);
 
 G_END_DECLS
 
index 7d5efa2..549b77d 100644 (file)
@@ -72,11 +72,12 @@ MaeviesWindow* maevies_window_new(osso_context_t *osso) {
 static void hello_item_clicked(GtkButton* button, gpointer data) {
 
        MaeviesWindow *self = MAEVIES_WINDOW(data);
+       gchar *has_stingers = NULL;
+
        g_assert(self);
 
        movie_get_info(self->movie, NULL);
 
-       gchar *has_stingers = NULL;
 
        if (self->movie->has_stingers)
                has_stingers = "Con escenas";
index ac76f41..8ec8b83 100644 (file)
@@ -24,5 +24,7 @@ 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);
+       movie->released = tmdb_movie->released;
+       movie->overview = tmdb_movie->overview;
+       movie->url = tmdb_movie->url;
 }
index d581ea8..150b1fd 100644 (file)
 
 #include "tmdb_movie.h"
 
-void query_tmdb(const gchar *name);
+static void do_get_info(TMDBMovie *movie);
 
-static void parse_child_element(gpointer key, gpointer element, gpointer data);
-
-RestXmlNode *get_xml(RestProxyCall *call);
+static void parse_xml_response(RestProxyCall *call, TMDBMovie *movie);
 
 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);
+       movie->name = g_strdup(name);
+
+       do_get_info(movie);
 
-       query_tmdb(name);
+       /*
+        * movie->rating = 10;
+        * movie->released = g_date_new_dmy(1, G_DATE_FEBRUARY, 2009);
+        */
 
        return movie;
 }
 
-void query_tmdb(const gchar *name) {
+static void do_get_info(TMDBMovie *movie) {
 
        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 */
+       /* Generate the function string.
+        * It's METHOD/LANGUAGE/FORMAT/APIKEY/MOVIENAME,
+        * so the actual query puts that after the URL */
        tmdb_function = g_strdup_printf("%s/%s/%s/%s/%s", TMDB_SEARCH_METHOD,
-                       TMDB_LANGUAGE, TMDB_FORMAT, TMDB_API_KEY, name);
+                       TMDB_LANGUAGE, TMDB_FORMAT, TMDB_API_KEY, movie->name);
 
        rest_proxy_call_set_function(call, tmdb_function);
 
        /* The actual call */
        rest_proxy_call_run(call, NULL, NULL);
 
-       get_xml(call);
+       parse_xml_response(call, movie);
 
        /* Object disposal, should be refactored. */
        g_object_unref(call);
+       g_free(tmdb_function);
        g_object_unref(proxy);
 }
 
-RestXmlNode *get_xml(RestProxyCall *call) {
+static void parse_xml_response(RestProxyCall *call, TMDBMovie *movie) {
        RestXmlParser *parser;
        RestXmlNode *root;
-       GError *error = NULL;
+       RestXmlNode *tmp;
+       RestXmlNode *field;
+       gint total_results;
 
        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);
+       tmp = g_hash_table_lookup(root->children, g_intern_string(
+                       "opensearch:totalResults"));
 
-       g_object_unref(parser);
+       total_results = atof(tmp->content);
+
+       tmp = g_hash_table_lookup(root->children, g_intern_string("movies"));
+
+       tmp = g_hash_table_lookup(tmp->children, g_intern_string("movie"));
+
+       while (tmp != NULL) {
+
+               field = g_hash_table_lookup(tmp->children,
+                               g_intern_string("popularity"));
+               movie->popularity = atoi(field->content);
+
+               field = g_hash_table_lookup(tmp->children, g_intern_string("name"));
+               movie->name = g_strdup(field->content);
+
+               field = g_hash_table_lookup(tmp->children, g_intern_string(
+                               "alternative_name"));
+               movie->alternative_name = g_strdup(field->content);
+
+               field = g_hash_table_lookup(tmp->children, g_intern_string("id"));
+               movie->id = atoi(field->content);
 
-       return root;
+               field = g_hash_table_lookup(tmp->children, g_intern_string("imdb_id"));
+               movie->imdb_id = g_strdup(field->content);
+
+               field = g_hash_table_lookup(tmp->children, g_intern_string("url"));
+               movie->url = g_strdup(field->content);
+
+               field = g_hash_table_lookup(tmp->children, g_intern_string("rating"));
+               movie->rating = atof(field->content);
+
+               field = g_hash_table_lookup(tmp->children, g_intern_string("released"));
+               movie->released = g_date_new();
+               g_date_set_parse(movie->released, field->content);
+
+               field = g_hash_table_lookup(tmp->children, g_intern_string("overview"));
+               movie->overview = g_strdup(field->content);
+
+               /* tmp = tmp->next; */
+               tmp = NULL;
+       }
+
+       g_object_unref(parser);
+       rest_xml_node_unref(root);
 }
 
-static void parse_child_element(gpointer key, gpointer element, gpointer data) {
+void tmdb_movie_unref(TMDBMovie *movie) {
+
+       g_free(movie->alternative_name);
+       g_free(movie->imdb_id);
+       g_free(movie->name);
+       g_free(movie->overview);
+       g_free(movie->url);
 
-       RestXmlNode *node = (RestXmlNode*) element;
+       if (movie->released != NULL)
+               g_date_free(movie->released);
+
+       g_free(movie);
+}
 
-       g_print("%s: ", key);
-       if (g_hash_table_size(node->children) == 0) {
-               g_print("%s", node->content);
+void tmdb_movie_print(const TMDBMovie *movie) {
+
+       g_print("themoviedb.org - The Movie Database.\n");
+       g_print("Movie name: %s\n", GET_MESSAGE(movie->name));
+       g_print("Alternate name: %s\n", GET_MESSAGE(movie->alternative_name));
+       g_print("Rating: %f\n", movie->rating);
+       g_print("Overview:\n %s\n", GET_MESSAGE(movie->overview));
+       g_print("ID: %d\n", movie->id);
+       g_print("IMDB ID: %s\n", GET_MESSAGE(movie->imdb_id));
+       g_print("Popularity: %d\n", movie->popularity);
+       g_print("URL: %s\n", GET_MESSAGE(movie->url));
+       g_print("Runtime: %d\n", movie->runtime);
+       if (g_date_valid(movie->released)) {
+               g_print("Released: %d-%d-%d\n", g_date_get_year(movie->released),
+                               g_date_get_month(movie->released), g_date_get_day(
+                                               movie->released));
        }
-       g_print("\n");
-       g_hash_table_foreach(node->children, (GHFunc) parse_child_element, NULL);
 }
index ff00b22..894b89f 100644 (file)
 #define TMDB_MOVIE_H_
 
 #include <stdio.h>
+#include <stdlib.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 GET_MESSAGE(x) ( (x) ? x : " - " )
 #define TMDB_API_KEY "249e1a42df9bee09fac5e92d3a51396b"
 #define TMDB_SERVICE_URL "http://api.themoviedb.org/2.1"
 #define TMDB_LANGUAGE "en"
@@ -35,19 +37,23 @@ typedef struct _TMDBMovie TMDBMovie;
 struct _TMDBMovie {
 
        gint popularity;
-       const gchar *name;
-       const gchar *alternative_name;
+       gchar *name;
+       gchar *alternative_name;
        gint id;
-       const gchar *imdb_id;
-       const gchar *url;
-       const gchar *overview;
-       gint rating;
+       gchar *imdb_id;
+       gchar *url;
+       gchar *overview;
+       gfloat rating;
        GDate *released;
        gint runtime;
-       // categories;
-       // images
+/* categories */
+/* images */
 };
 
 TMDBMovie *tmdb_get_info(const gchar *name);
 
+void tmdb_movie_unref(TMDBMovie *movie);
+
+void tmdb_movie_print(const TMDBMovie *movie);
+
 #endif /* TMDB_MOVIE_H_ */
index 9f5ae0e..8999d5c 100644 (file)
@@ -19,6 +19,8 @@
 #include "watc_provider.h"
 #include "string.h"
 
+static gboolean parse_response(const gchar *response);
+
 gboolean watc_has_stingers(const gchar *name) {
 
        RestProxy *proxy;
index 0fe9a72..769da66 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stdio.h>
 #include <rest-0.6/rest/rest-proxy.h>
+#include <unistd.h>
 
 #define WATC_SERVICE_URL "http://whatsafterthecredits.com/api.php"