aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rwxr-xr-xautomediabin124920 -> 124936 bytes
-rw-r--r--src/fileutils.h2
-rw-r--r--src/html.c8
-rw-r--r--src/main.c15
5 files changed, 26 insertions, 1 deletions
diff --git a/README.md b/README.md
index 1ef4f62..68c9958 100644
--- a/README.md
+++ b/README.md
@@ -12,6 +12,8 @@ Run automedia with `sync` option and keep it running to track media. You can the
Removing media from being synced can be done by removing the tracked directory in `~/.config/automedia/rss/tracked` or `~/.config/automedia/html/tracked` or by using `automedia cleanup`.\
It is recommended to create a new directory specifically for automedia sync, otherwise tools like `open_media.py` might not work correctly.\
Run automedia without any options to see all options.
+
+If `$HOME/.config/automedia/download_finished.sh` exists then it's called when a download finishes. The first argument is either `html` or `rss` and the second argument is the full path to the rss file (anime episode video) or html directory (manga chapter).
# Requirements
## System
curl, transmission-cli, notify-send (optional)
diff --git a/automedia b/automedia
index 3cda69a..cd345fc 100755
--- a/automedia
+++ b/automedia
Binary files differ
diff --git a/src/fileutils.h b/src/fileutils.h
index e243a89..1c4f828 100644
--- a/src/fileutils.h
+++ b/src/fileutils.h
@@ -4,7 +4,7 @@
#include <stddef.h>
#include <time.h>
-const char* get_home_dir();
+const char* get_home_dir(void);
/* Returns 0 on success */
int file_get_content(const char *filepath, char **data, long *size);
/* Returns 0 on success */
diff --git a/src/html.c b/src/html.c
index c241848..1bdd3de 100644
--- a/src/html.c
+++ b/src/html.c
@@ -379,6 +379,12 @@ int add_html(const char *name, const char *url, char *html_config_dir, char *pro
}
static int download_html_items_in_reverse(const char *plugin_filepath, Buffer *download_items_buffer, TrackedHtml *tracked_html, char *html_tracked_dir, const char *download_dir) {
+ 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 result = 0;
DownloadItemsData *added_download_items[MAX_UPDATE_ITEMS];
long timestamps[MAX_UPDATE_ITEMS];
@@ -421,6 +427,8 @@ static int download_html_items_in_reverse(const char *plugin_filepath, Buffer *d
if(result != 0)
break;
+ const char *download_finished_args[] = { download_finished_script, "html", item_dir, NULL };
+ program_exec(download_finished_args, NULL, NULL);
fprintf(stderr, "Download finished for html item: %s (title: %s)\n", download_items_it->link, notify_msg);
added_download_items[download_item_index] = download_items_it;
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;