From 5be9458de0fe21aaebd43cee6fd0c084b4464a68 Mon Sep 17 00:00:00 2001 From: "Rafael G. Martins" Date: Wed, 4 Nov 2015 01:31:20 -0200 Subject: content-parser: implemented youtube directive --- src/directives.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'src/directives.c') diff --git a/src/directives.c b/src/directives.c index 5ff3b4d..829a736 100644 --- a/src/directives.c +++ b/src/directives.c @@ -10,13 +10,50 @@ #include #endif /* HAVE_CONFIG_H */ +#include + #include "utils/utils.h" +#include "directives.h" #include "error.h" + +blogc_directive_t registry[] = { + {"youtube", blogc_directive_youtube}, + {NULL, NULL}, +}; + + char* blogc_directive_loader(const char *name, const char *argument, b_trie_t *params, blogc_error_t **err) { - // TODO: implement me! - return b_strdup("TODO\n"); + for (unsigned int i = 0; registry[i].name != NULL; i++) + if (0 == strcmp(name, registry[i].name)) + return registry[i].callback(argument, params, err); + return NULL; +} + + +char* +blogc_directive_youtube(const char *argument, b_trie_t *params, blogc_error_t **err) +{ + if (err != NULL && *err != NULL) + return NULL; + if (argument == NULL) { + *err = blogc_error_new_printf(BLOGC_WARNING_CONTENT_PARSER, + "youtube: Invalid video ID: %s", argument); + return NULL; + } + + char *width = b_trie_lookup(params, "width"); + char *height = b_trie_lookup(params, "height"); + + // using default 16:9 sizes provided by youtube as of 2015-11-04 + return b_strdup_printf( + "\n", + width == NULL ? "560" : width, + height == NULL ? "315" : height, + argument); } -- cgit v1.2.3-18-g5258