From dfad8a8016426d7fe198dc32973b01a1e075142e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 12 Jul 2020 21:32:44 +0200 Subject: Starting on conversion to c. Program exec, buffers.. --- main.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 main.c (limited to 'main.c') diff --git a/main.c b/main.c new file mode 100644 index 0000000..04c8f29 --- /dev/null +++ b/main.c @@ -0,0 +1,60 @@ +#include +#include +#include "program.h" +#include "buffer.h" + +static int program_buffer_write_callback(char *data, int size, void *userdata) { + Buffer *buffer = userdata; + buffer_append(buffer, data, size); + return 0; +} + +static void usage() { + fprintf(stderr, "usage: automedia COMMAND\n"); + fprintf(stderr, "\n"); + fprintf(stderr, "COMMANDS\n"); + fprintf(stderr, " add Add media to track\n"); + fprintf(stderr, " sync Start syncing tracked media\n"); + fprintf(stderr, " downloaded List downloaded media\n"); + exit(1); +} + +static void usage_add() { + fprintf(stderr, "usage: automedia add [--name name] [--start-after start_after]\n"); + fprintf(stderr, "OPTIONS\n"); + fprintf(stderr, " type The type should be either rss or html\n"); + fprintf(stderr, " url The url to the rss or html\n"); + fprintf(stderr, " filename The filename of an episode of an existing serie to start track. Currently only works with rss on https://nyaa.si\n"); + fprintf(stderr, " --name The display name to be used for the media. Optional for rss, in which case the name will be retries from rss TITLE, required for html\n"); + fprintf(stderr, " --start-after The sync should start downloading media after this item. This --start-after value should be the title of the episode/chapter (Optional, default is to start from the first item)\n"); + fprintf(stderr, "EXAMPLES\n"); + fprintf(stderr, " automedia.py add rss 'https://nyaa.si/?page=rss&q=Tejina-senpai+1080p&c=0_0&f=0&u=HorribleSubs'\n"); + fprintf(stderr, " automedia.py add html 'https://manganelo.com/manga/read_naruto_manga_online_free3' --name Naruto\n"); + fprintf(stderr, " automedia.py add rss '[Erai-raws] Saiki Kusuo no Psi Nan - Kanketsu-hen - 01 [1080p][Multiple Subtitle].mkv'\n"); + exit(1); +} + +static void usage_sync() { + fprintf(stderr, "usage: automedia sync \n"); + fprintf(stderr, "OPTIONS\n"); + fprintf(stderr, " download_dir The path where media should be downloaded to\n"); + fprintf(stderr, "EXAMPLES\n"); + fprintf(stderr, " automedia.py sync /home/adam/Downloads/automedia\n"); + exit(1); +} + +int main(int argc, char **argv) { + if(argc < 3) + usage(); + + Buffer buffer; + buffer_init(&buffer); + + const char *args[] = { "curl", "-s", "-L", "-f", "https://google.com", NULL }; + program_exec(args, program_buffer_write_callback, &buffer); + printf("program output: %.*s\n", (int)buffer.size, (char*)buffer.data); + + buffer_deinit(&buffer); + + return 0; +} -- cgit v1.2.3