diff options
Diffstat (limited to 'src/fruits')
| -rw-r--r-- | src/fruits/cmc/cmc.c | 49 |
1 files changed, 44 insertions, 5 deletions
diff --git a/src/fruits/cmc/cmc.c b/src/fruits/cmc/cmc.c index ad7c75e..d39d639 100644 --- a/src/fruits/cmc/cmc.c +++ b/src/fruits/cmc/cmc.c @@ -8,8 +8,14 @@ #include "cmc.h" +enum { + CLI_ADD = 0 +}; + struct cmc { struct aki_event_loop loop; + u8 command; + array(str) args; struct camu_client client; struct camu_post_cache cache; array(struct cmc_search *) searches; @@ -29,7 +35,16 @@ static void client_callback(void *userdata, u8 op, void *opaque) struct cmc *c = (struct cmc *)userdata; switch (op) { case CAMU_CLIENT_LOGIN: { - camu_client_create_search(&c->client, al_str_c("youtube"), al_str_c("")); + switch (c->command) { + case CLI_ADD: { + str *arg; + al_array_foreach_ptr(c->args, i, arg) { + camu_client_add_from_path(&c->client, al_str_c("default"), arg); + } + camu_client_disconnect(&c->client); + break; + } + } break; } case CAMU_CLIENT_SEARCH_CREATED: { @@ -62,7 +77,7 @@ static void client_callback(void *userdata, u8 op, void *opaque) al_array_push(page->list, s); } al_array_push(search->pages, page); - camu_client_add(&c->client, al_str_c("default"), &al_array_at(page->list, 0), 0); + camu_client_add_from_post(&c->client, al_str_c("default"), &al_array_at(page->list, 0), 0); break; } } @@ -71,21 +86,45 @@ static void client_callback(void *userdata, u8 op, void *opaque) static struct cmc c = { 0 }; #ifndef _WIN32 +static bool parse_cmd(s32 argc, char *argv[]) +#else +static bool parse_cmd(s32 argc, wchar_t **argv) +#endif +{ + if (argc < 2) return false; + if (al_str_eq(al_str_cr(argv[1]), al_str_c("add"))) { + if (argc < 3) return false; + c.command = CLI_ADD; + char path[PATH_MAX]; + str arg; + for (s32 i = 2; i < argc; i++) { + if (realpath(argv[i], path)) { + al_str_clone(&arg, al_str_cr(path)); + al_array_push(c.args, arg); + } + } + } + return true; +} + + +#ifndef _WIN32 s32 main(s32 argc, char *argv[]) #else s32 wmain(s32 argc, wchar_t **argv) #endif { - (void)argc; - (void)argv; if (!aki_common_init()) return EXIT_FAILURE; aki_event_loop_init(&c.loop); - camu_post_cache_init(&c.cache); + al_array_init(c.args); + camu_post_cache_init(&c.cache); al_array_init(c.searches); + if (!parse_cmd(argc, argv)) return EXIT_FAILURE; + c.client.callback = client_callback; c.client.userdata = &c; if (!camu_client_login(&c.client, &c.loop, CAMU_LOCAL_TYPE, CAMU_LOCAL_ADDR, CAMU_PORT, al_str_c("andrew"))) { |