From 754f5f7bfd72974e814cd05a6c9009076e8bb95d Mon Sep 17 00:00:00 2001 From: spenap Date: Sat, 31 Oct 2009 18:27:48 +0000 Subject: [PATCH] Added the what's after the credits provider, with a simple (too simple!!) implementation. Added a file extra_scenes_provider, acting like a wrapper, which will select the right provider to use. It will be the place to add support for dynamic loading. Right now it's just calling the watc provider Modified the Makefile.am to get them compiled. Modified the examples Makefile, to get it doing "all" if invoked without arguments. Added a clean-auto.sh script to delete the files added by the autoconf tools. git-svn-id: file:///svnroot/maevies/trunk@7 a96798e0-47ce-444a-94a4-1d14e63744fc --- Makefile.am | 4 ++- clean-auto.sh | 34 +++++++++++++++++++++ examples/Makefile | 4 +-- src/extra_scenes_provider.c | 32 ++++++++++++++++++++ src/extra_scenes_provider.h | 24 +++++++++++++++ src/main.c | 6 ++++ src/watc_provider.c | 69 +++++++++++++++++++++++++++++++++++++++++++ src/watc_provider.h | 29 ++++++++++++++++++ 8 files changed, 199 insertions(+), 3 deletions(-) create mode 100755 clean-auto.sh create mode 100644 src/extra_scenes_provider.c create mode 100644 src/extra_scenes_provider.h create mode 100644 src/watc_provider.c create mode 100644 src/watc_provider.h diff --git a/Makefile.am b/Makefile.am index dbb2231..8ea279f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -22,7 +22,9 @@ bin_PROGRAMS = \ # Sources maevies_SOURCES = \ - src/main.c + src/main.c \ + src/extra_scenes_provider.c \ + src/watc_provider.c # /Sources # LDADD diff --git a/clean-auto.sh b/clean-auto.sh new file mode 100755 index 0000000..6d89f40 --- /dev/null +++ b/clean-auto.sh @@ -0,0 +1,34 @@ +#!/bin/sh +FILES="Makefile.in \ + aclocal.m4 \ + autom4te.cache \ + config.guess \ + config.h.in \ + config.sub \ + configure \ + depcomp \ + install-sh \ + intltool-extract.in \ + intltool-merge.in \ + intltool-update.in \ + ltmain.sh \ + missing \ + mkinstalldirs \ + src/Makefile.in \ + src/Makefile \ + po/Makefile.in.in" + +for file in $FILES; +do + if [[ -a $file ]]; + then + if [[ -d $file ]]; + then + rm -r $file; + else + rm $file; + fi + fi +done + +rm -rf *~ diff --git a/examples/Makefile b/examples/Makefile index 272ff68..8328a19 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -8,6 +8,8 @@ LIBS_GMOVIES = `pkg-config libxml-2.0 --libs` FLAGS_GMOVIES = `pkg-config libxml-2.0 --cflags` +all: gtranslate gmovies + gtranslate: gtranslate.o $(CC) -o gtranslate gtranslate.o $(LIBS_GTRANSLATE) @@ -20,7 +22,5 @@ gmovies: gmovies.o gmovies.o: gmovies.c $(CC) -c gmovies.c $(FLAGS_GMOVIES) -all: gtranslate gmovies - clean: rm -rf gtranslate gtranslate.o gmovies gmovies.o *~ diff --git a/src/extra_scenes_provider.c b/src/extra_scenes_provider.c new file mode 100644 index 0000000..9267df9 --- /dev/null +++ b/src/extra_scenes_provider.c @@ -0,0 +1,32 @@ +/* + * extra_scenes_provider.c + * + * This file is part of maevies + * Copyright (C) 2009 Simón Pena + * + * 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 "extra_scenes_provider.h" +#include "watc_provider.h" + +int has_stingers(const char *movie) { + + /* Here there should be a mechanism + * allowing us to dynamically load new libraries + * dlopen - http://stackoverflow.com/questions/384121/creating-a-module-system-dynamic-loading-in-c + * Until we get it, we'll use just one of the provided providers ;) + */ + return watc_has_stingers(movie); + + +} diff --git a/src/extra_scenes_provider.h b/src/extra_scenes_provider.h new file mode 100644 index 0000000..5685991 --- /dev/null +++ b/src/extra_scenes_provider.h @@ -0,0 +1,24 @@ +/* + * extra_scenes_provider.h + * + * This file is part of maevies + * Copyright (C) 2009 Simón Pena + * + * 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 EXTRA_SCENES_PROVIDER_H_ +#define EXTRA_SCENES_PROVIDER_H_ + +int has_stingers(const char *movie); + +#endif /* EXTRA_SCENES_PROVIDER_H_ */ diff --git a/src/main.c b/src/main.c index 728f85c..790dd5f 100644 --- a/src/main.c +++ b/src/main.c @@ -23,6 +23,8 @@ #include #include "localisation.h" +#include "extra_scenes_provider.h" + /* Defines to add the application to dbus and keep it running * Please do not modify "APP_NAME" (or other defines) to different name */ @@ -34,6 +36,10 @@ static void button_clicked (GtkButton* button, gpointer data) { + if(has_stingers("Zombieland")) + printf("Movie has stingers\n"); + else + printf("Movie doesn't have stingers\n"); gtk_main_quit(); } diff --git a/src/watc_provider.c b/src/watc_provider.c new file mode 100644 index 0000000..b70b66f --- /dev/null +++ b/src/watc_provider.c @@ -0,0 +1,69 @@ +/* + * watc_provider.c + * + * This file is part of maevies + * Copyright (C) 2009 Simón Pena + * + * 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 "watc_provider.h" +#include "string.h" + +int watc_has_stingers(const char *name) { + + RestProxy *proxy; + RestProxyCall *call; + const gchar *response; + gssize len; + + /* Initialization: most probably done in the invoker */ + g_thread_init(NULL); + g_type_init(); + + /* Provider initialization, should be refactored. Maybe it can be reused between calls */ + proxy = rest_proxy_new(WATC_SERVICE_URL, FALSE); + call = rest_proxy_new_call(proxy); + + /* Adding params to the call: check http://en.wikipedia.org/w/api.php + * + * There's only one variable param: the movie name + * */ + rest_proxy_call_add_params(call, "action", "opensearch", "search", name, + NULL); + + /* The actual call */ + rest_proxy_call_run(call, NULL, NULL); + + /* Retrieving the results: should be done in/should receive a callback function */ + response = rest_proxy_call_get_payload(call); + len = rest_proxy_call_get_payload_length(call); + + /* Process the output: must be checked whether the response has a * in the expected result + * or not */ + write(1, response, len); + printf("\n"); + + /* Object disposal, should be refactored. */ + g_object_unref(call); + g_object_unref(proxy); + + return parse_response(response); +} + +/* Ad-hoc implementation. Will give a wrong result if the query had more than one result, + * if the title has a * in its text, or if the conventions used in what's after the credits vary. + */ +int parse_response(const gchar *response) { + + return (strpbrk(response, "*") != NULL); +} diff --git a/src/watc_provider.h b/src/watc_provider.h new file mode 100644 index 0000000..91e1392 --- /dev/null +++ b/src/watc_provider.h @@ -0,0 +1,29 @@ +/* + * watc_provider.h + * + * This file is part of maevies + * Copyright (C) 2009 Simón Pena + * + * 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 WATC_PROVIDER_H_ +#define WATC_PROVIDER_H_ + +#include +#include + +#define WATC_SERVICE_URL "http://whatsafterthecredits.com/api.php" + +int watc_has_stingers(const char *name); + +#endif /* WATC_PROVIDER_H_ */ -- 1.7.9.5