aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-01-11 23:21:13 +0100
committerdec05eba <dec05eba@protonmail.com>2022-01-11 23:21:13 +0100
commit4906898393698525b7662d974cbd80dc71c40957 (patch)
tree1ac5d6b1f4fa2bfb942361d35b5148d361849379
parent44ebc4333645547af146dbfd57b3891b92112d86 (diff)
Add --include-tracked option to downloaded command to include all tracked episodes
-rwxr-xr-xautomediabin120760 -> 120760 bytes
-rw-r--r--src/main.c33
2 files changed, 25 insertions, 8 deletions
diff --git a/automedia b/automedia
index 5ec4454..d090d81 100755
--- a/automedia
+++ b/automedia
Binary files differ
diff --git a/src/main.c b/src/main.c
index fa4ca20..d38ea2d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -65,6 +65,16 @@ static void usage_sync(void) {
exit(1);
}
+static void usage_downloaded(void) {
+ fprintf(stderr, "usage: automedia downloaded [--include-tracked]\n");
+ fprintf(stderr, "OPTIONS\n");
+ fprintf(stderr, " --include-tracked Include tracked only episodes that have already been marked as watched and will not be downloaded (Optional, default is to not include these)\n");
+ fprintf(stderr, "EXAMPLES\n");
+ fprintf(stderr, " automedia downloaded\n");
+ fprintf(stderr, " automedia downloaded --include-tracked\n");
+ exit(1);
+}
+
static void usage_cleanup(void) {
fprintf(stderr, "usage: automedia cleanup <days>\n");
fprintf(stderr, "OPTIONS\n");
@@ -76,7 +86,7 @@ static void usage_cleanup(void) {
typedef void (*DownloadedListCallback)(const char *title, double timestamp, void *userdata);
-static void data_file_get_downloaded(const char *dir_name, const char *data_filepath, int is_html, DownloadedListCallback callback, void *userdata) {
+static void data_file_get_downloaded(const char *dir_name, const char *data_filepath, int is_html, int include_tracked, DownloadedListCallback callback, void *userdata) {
char *file_data;
long file_size;
if(file_get_content(data_filepath, &file_data, &file_size) != 0) {
@@ -114,7 +124,7 @@ static void data_file_get_downloaded(const char *dir_name, const char *data_file
continue;
const cJSON *filler_json = cJSON_GetObjectItemCaseSensitive(downloaded_item_json, "filler");
- if(cJSON_IsTrue(filler_json))
+ if(!include_tracked && cJSON_IsTrue(filler_json))
continue;
const cJSON *time_json = cJSON_GetObjectItemCaseSensitive(downloaded_item_json, "time");
@@ -160,7 +170,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, int is_html, void *userdata) {
+static void get_downloaded_items(const char *tracked_dir, int is_html, void *userdata, int include_tracked) {
struct dirent *dir;
DIR *d = opendir(tracked_dir);
if(!d) {
@@ -180,7 +190,7 @@ static void get_downloaded_items(const char *tracked_dir, int is_html, void *use
strcpy(data_filepath + data_filepath_length, dir->d_name);
strcpy(data_filepath + data_filepath_length + filename_len, "/data");
- data_file_get_downloaded(dir->d_name, data_filepath, is_html, downloaded_list_callback, userdata);
+ data_file_get_downloaded(dir->d_name, data_filepath, is_html, include_tracked, downloaded_list_callback, userdata);
}
closedir(d);
@@ -655,7 +665,14 @@ static void command_sync(int argc, char **argv, char *rss_config_dir, char *html
remove(automedia_pid_path);
}
-static void command_downloaded(const char *rss_config_dir, const char *html_config_dir) {
+static void command_downloaded(int argc, char **argv, const char *rss_config_dir, const char *html_config_dir) {
+ int include_tracked = 0;
+ if(argc >= 1) {
+ include_tracked = strcmp(argv[0], "--include-tracked") == 0;
+ if(!include_tracked)
+ usage_downloaded();
+ }
+
char rss_tracked_dir[PATH_MAX];
strcpy(rss_tracked_dir, rss_config_dir);
strcat(rss_tracked_dir, "/tracked");
@@ -667,8 +684,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, 0, &downloaded_items);
- get_downloaded_items(html_tracked_dir, 1, &downloaded_items);
+ get_downloaded_items(rss_tracked_dir, 0, &downloaded_items, include_tracked);
+ get_downloaded_items(html_tracked_dir, 1, &downloaded_items, include_tracked);
qsort(downloaded_items.data, buffer_get_size(&downloaded_items, sizeof(DownloadedListData)), sizeof(DownloadedListData), compare_downloaded_item);
DownloadedListData *list_it = buffer_begin(&downloaded_items);
@@ -887,7 +904,7 @@ int main(int argc, char **argv) {
} else if(strcmp(command, "sync") == 0) {
command_sync(argc - 2, argv + 2, rss_config_dir, html_config_dir, dirname(argv[0]));
} else if(strcmp(command, "downloaded") == 0) {
- command_downloaded(rss_config_dir, html_config_dir);
+ command_downloaded(argc - 2, argv + 2, rss_config_dir, html_config_dir);
} else if(strcmp(command, "cleanup") == 0) {
command_cleanup(argc - 2, argv + 2, rss_config_dir, html_config_dir);
} else {