summaryrefslogtreecommitdiff
path: root/cite.c
diff options
context:
space:
mode:
Diffstat (limited to 'cite.c')
-rw-r--r--cite.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/cite.c b/cite.c
index 8feb067..12545c5 100644
--- a/cite.c
+++ b/cite.c
@@ -1,3 +1,4 @@
+#include <curl/curl.h>
#include <libxml/parser.h>
#include <string.h>
@@ -18,6 +19,7 @@ typedef struct {
} Movie;
Movie movies[64] = {0};
+CURL *curl = NULL;
static void print_style(void)
{
@@ -58,6 +60,27 @@ static void print_movie(Movie *movie, int hide_fr)
printf("\n");
}
+static void download_poster(Movie *movie)
+{
+ char out_path[512];
+ char *last_slash = movie->poster;
+ while (strchr(last_slash, '/') != NULL)
+ last_slash = strchr(last_slash, '/') + 1;
+ strcpy(out_path, "cite/");
+ strcat(out_path, last_slash);
+ FILE *const fp = fopen(out_path, "wb");
+ if (fp == NULL)
+ return;
+ curl_easy_setopt(curl, CURLOPT_URL, movie->poster);
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
+ fprintf(stderr, "getting %s", out_path);
+ fprintf(stderr, "\rgot %s \n", out_path);
+ const CURLcode res = curl_easy_perform(curl);
+ if (res == CURLE_OK)
+ strcpy(movie->poster, last_slash);
+}
+
static void xfree(const void *ptr)
{
if (ptr != NULL)
@@ -170,6 +193,12 @@ int main(int argc, char **argv)
xmlFreeDoc(document);
return 1;
}
+ curl = curl_easy_init();
+ if (curl == NULL) {
+ xmlCleanupParser();
+ xmlFreeDoc(document);
+ return 1;
+ }
for (const xmlNode *week = root->children; week != NULL; week = week->next) {
for (const xmlNode *mov = get_movie_node(week); mov != NULL; mov = mov->next) {
const int id = get_id(mov);
@@ -185,8 +214,11 @@ int main(int argc, char **argv)
}
print_style();
printf("<h1><a href=\"http://www.citebd.org/spip.php?film2912\">cinéma de la cité</a></h1>\n");
- for (Movie *movie = movies; movie->id != 0; movie++)
+ for (Movie *movie = movies; movie->id != 0; movie++) {
+ download_poster(movie);
print_movie(movie, atoi(argv[2]));
+ }
+ curl_easy_cleanup(curl);
xmlFreeDoc(document);
xmlCleanupParser();
return 0;