aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-12 21:32:44 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-12 21:32:44 +0200
commitdfad8a8016426d7fe198dc32973b01a1e075142e (patch)
tree1ba7312e0a3d5dbb1942088165e338ffd25af034 /main.c
parent4f9c16f821af54110889c01eed0cb6bbf9eb9ce2 (diff)
Starting on conversion to c. Program exec, buffers..
Diffstat (limited to 'main.c')
-rw-r--r--main.c60
1 files changed, 60 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+#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 <type> <url|filename> [--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 <download_dir>\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;
+}