aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-04-05 23:10:28 +0200
committerdec05eba <dec05eba@protonmail.com>2022-04-05 23:12:13 +0200
commit0e12dd4e395cb4716e81bac41b220a7575397b28 (patch)
treeddd2276489300aaa24d78ab7281204259bad638d /src/main.c
parentc83325a3699748e08395180529deff658ca27a58 (diff)
Execute $HOME/.config/automedia/download_finished.sh on download finished
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index c6e46a0..45936a5 100644
--- a/src/main.c
+++ b/src/main.c
@@ -479,6 +479,7 @@ static void sync_tracked_html(char *html_config_dir, char *program_dir, const ch
typedef struct {
char *items;
int size;
+ const char *download_dir;
} UnfinishedTorrents;
static void torrent_list_check_new_downloads_callback(int id, const char *name, double percentage_done, void *userdata) {
@@ -491,12 +492,25 @@ static void torrent_list_check_new_downloads_callback(int id, const char *name,
id--;
UnfinishedTorrents *unfinished_torrents = userdata;
+ const char *home_dir = get_home_dir();
+
+ char download_finished_script[PATH_MAX];
+ strcpy(download_finished_script, home_dir);
+ strcat(download_finished_script, "/.config/automedia/download_finished.sh");
+
int is_finished = (percentage_done >= 0.9999);
if(is_finished) {
if(id < unfinished_torrents->size && unfinished_torrents->items[id] == 1) {
unfinished_torrents->items[id] = 0;
const char *notify_args[] = { "notify-send", "-u", "normal", "-a", "automedia", "-t", "10000", "--", "Download finished", name, NULL };
program_exec(notify_args, NULL, NULL);
+
+ char item_path[PATH_MAX];
+ const char *components[] = { unfinished_torrents->download_dir, name };
+ path_join(item_path, components, 2);
+
+ const char *download_finished_args[] = { download_finished_script, "rss", item_path, NULL };
+ program_exec(download_finished_args, NULL, NULL);
}
} else {
if(id >= unfinished_torrents->size) {
@@ -529,6 +543,7 @@ static void sync_rss_html(char *rss_config_dir, char *html_config_dir, char *pro
UnfinishedTorrents unfinished_torrents;
unfinished_torrents.size = 1024;
unfinished_torrents.items = alloc_or_crash(unfinished_torrents.size);
+ unfinished_torrents.download_dir = download_dir;
memset(unfinished_torrents.items, 0, unfinished_torrents.size);
automedia_running = 1;