From 63ff3eaf2bd2467255c08bf427a162f5c446b146 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 13 Jul 2020 01:41:52 +0200 Subject: Add transmission methods --- main.c | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 33bc2fd..36c2b5f 100644 --- a/main.c +++ b/main.c @@ -1,23 +1,15 @@ -#include "program.h" #include "buffer.h" #include "fileutils.h" +#include "transmission.h" #include "json.h" #include #include #include #include -#include #include -/* -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(void) { fprintf(stderr, "usage: automedia COMMAND\n"); fprintf(stderr, "\n"); @@ -64,7 +56,7 @@ static struct json_value_s* json_object_get_field_by_name(struct json_object_s * typedef void (*DownloadedListCallback)(const char *title, double timestamp, void *userdata); -static void data_file_get_downloaded(const char *dir_name, const char *data_filepath, bool is_html, DownloadedListCallback callback, void *userdata) { +static void data_file_get_downloaded(const char *dir_name, const char *data_filepath, int is_html, DownloadedListCallback callback, void *userdata) { char *file_data; long file_size; if(file_get_content(data_filepath, &file_data, &file_size) != 0) { @@ -158,7 +150,7 @@ static void downloaded_list_callback(const char *title, double timestamp, void * buffer_append(buffer, &list_data, sizeof(list_data)); } -static void get_downloaded_items(const char *tracked_dir, bool is_html, void *userdata) { +static void get_downloaded_items(const char *tracked_dir, int is_html, void *userdata) { struct dirent *dir; DIR *d = opendir(tracked_dir); if(!d) @@ -200,8 +192,8 @@ static void command_downloaded(const char *rss_config_dir, const char *html_conf Buffer downloaded_items; buffer_init(&downloaded_items); - get_downloaded_items(rss_tracked_dir, false, &downloaded_items); - get_downloaded_items(html_tracked_dir, true, &downloaded_items); + get_downloaded_items(rss_tracked_dir, 0, &downloaded_items); + get_downloaded_items(html_tracked_dir, 1, &downloaded_items); qsort(downloaded_items.data, buffer_get_size(&downloaded_items, sizeof(DownloadedListData)), sizeof(DownloadedListData), compare_downloaded_item); DownloadedListData *list_it = buffer_begin(&downloaded_items); @@ -214,6 +206,11 @@ static void command_downloaded(const char *rss_config_dir, const char *html_conf buffer_deinit(&downloaded_items); } +static void torrent_list_callback(int id, float percentage_finished, const char *name, void *userdata) { + (void)userdata; + fprintf(stderr, "id: |%d|, done: |%g|, name: |%s|\n", id, percentage_finished, name); +} + int main(int argc, char **argv) { if(argc < 2) usage(); @@ -240,15 +237,8 @@ int main(int argc, char **argv) { 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); + transmission_get_all_torrents(torrent_list_callback, NULL); + printf("is transmission daemon running? %s\n", transmission_is_daemon_running() == 0 ? "yes" : "no"); - buffer_deinit(&buffer); -*/ return 0; } -- cgit v1.2.3