diff options
Diffstat (limited to 'src/fruits/cmc')
| -rw-r--r-- | src/fruits/cmc/cli.h | 4 | ||||
| -rw-r--r-- | src/fruits/cmc/cmc.c | 98 | ||||
| -rw-r--r-- | src/fruits/cmc/cmc.h | 15 | ||||
| -rw-r--r-- | src/fruits/cmc/cmc.py | 17 | ||||
| -rw-r--r-- | src/fruits/cmc/meson.build | 19 |
5 files changed, 136 insertions, 17 deletions
diff --git a/src/fruits/cmc/cli.h b/src/fruits/cmc/cli.h new file mode 100644 index 0000000..4373054 --- /dev/null +++ b/src/fruits/cmc/cli.h @@ -0,0 +1,4 @@ +#pragma once + +struct cmc_cli { +}; diff --git a/src/fruits/cmc/cmc.c b/src/fruits/cmc/cmc.c new file mode 100644 index 0000000..ad7c75e --- /dev/null +++ b/src/fruits/cmc/cmc.c @@ -0,0 +1,98 @@ +#include <aki/common.h> +#include <aki/event_loop.h> + +#include "../../libclient/client.h" +#include "../../server/common.c" +#include "../../portal/src/packet_ext.h" +#include "../../portal/src/post_cache.h" + +#include "cmc.h" + +struct cmc { + struct aki_event_loop loop; + struct camu_client client; + struct camu_post_cache cache; + array(struct cmc_search *) searches; +}; + +static struct cmc_search *get_search_by_id(struct cmc *c, s32 id) +{ + struct cmc_search *search; + al_array_foreach(c->searches, i, search) { + if (search->id == id) return search; + } + return NULL; +} + +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("")); + break; + } + case CAMU_CLIENT_SEARCH_CREATED: { + struct cmc_search *search = al_alloc_object(struct cmc_search); + search->id = *(s32 *)opaque; + al_array_init(search->pages); + al_array_push(c->searches, search); + camu_client_get_page(&c->client, search->id, 0); + break; + } + case CAMU_CLIENT_PAGE_RESULTS: { + struct aki_packet *packet = (struct aki_packet *)opaque; + s32 id = aki_packet_read_s32(packet); + struct cmc_search *search = get_search_by_id(c, id); + if (!search) return; + struct cmc_search_page *page = al_alloc_object(struct cmc_search_page); + page->num = aki_packet_read_u32(packet); + u32 posts = aki_packet_read_u32(packet); + for (u32 i = 0; i < posts; i++) { + struct camu_post post; + aki_packet_read_post(packet, &post); + camu_post_cache_push(&c->cache, &post); + } + u32 ids = aki_packet_read_u32(packet); + for (u32 i = 0; i < ids; i++) { + str unique_id; + aki_packet_read_str(packet, &unique_id); + str s; + al_str_clone(&s, &unique_id); + 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); + break; + } + } +} + +static struct cmc c = { 0 }; + +#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.searches); + + 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"))) { + return EXIT_FAILURE; + } + + aki_event_loop_run(&c.loop); + + return EXIT_SUCCESS; +} diff --git a/src/fruits/cmc/cmc.h b/src/fruits/cmc/cmc.h new file mode 100644 index 0000000..a9c8544 --- /dev/null +++ b/src/fruits/cmc/cmc.h @@ -0,0 +1,15 @@ +#pragma once + +#include <al/types.h> +#include <al/array.h> +#include <al/str.h> + +struct cmc_search_page { + u32 num; + array(str) list; +}; + +struct cmc_search { + s32 id; + array(struct cmc_search_page *) pages; +}; diff --git a/src/fruits/cmc/cmc.py b/src/fruits/cmc/cmc.py deleted file mode 100644 index 5c0a5b6..0000000 --- a/src/fruits/cmc/cmc.py +++ /dev/null @@ -1,17 +0,0 @@ -import cffi -import locale -from notcurses import notcurses - -ffi = cffi.FFI() - -print(ffi.string(notcurses.lib.notcurses_version())) - -class CMC: - def __init__(self): - pass - -c = CMC() - -locale.setlocale(locale.LC_ALL, "") -nc = notcurses.Notcurses() -nc.render() diff --git a/src/fruits/cmc/meson.build b/src/fruits/cmc/meson.build new file mode 100644 index 0000000..4cbe553 --- /dev/null +++ b/src/fruits/cmc/meson.build @@ -0,0 +1,19 @@ +cmc_src = ['cmc.c'] +cmc_deps = [libclient] +cmc_args = [] + +if get_option('portal').enabled() + cmc_deps += [portal] +endif + +use_tui = true +if use_tui + #cmc_src += ['ui.c'] + cmc_deps += [dependency('notcurses')] +endif + +if is_windows and meson.is_cross_build() + cmc_args += ['-static', '-static-libgcc', '-static-libstdc++', '-municode', '-mwindows'] +endif + +executable('cmc', cmc_src, dependencies: cmc_deps, link_args: cmc_args) |