diff options
author | dec05eba <dec05eba@protonmail.com> | 2021-08-19 03:37:41 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2021-08-19 03:37:41 +0200 |
commit | 03d49c498fb6e781dcb80e4e01ef81dab37b8cf6 (patch) | |
tree | 73e49705ef32c8db6cad034cced9f459858fbef1 | |
parent | 7f3a741d2af875674f071aba5313ac47d8353eaa (diff) |
Add option to cleanup all items, fix cleanup of items that have never synced, sort cleanup items
-rw-r--r-- | README.md | 6 | ||||
-rwxr-xr-x | automedia | bin | 120760 -> 120760 bytes | |||
-rwxr-xr-x | open_media.py | 2 | ||||
-rw-r--r-- | src/main.c | 38 |
4 files changed, 23 insertions, 23 deletions
@@ -7,7 +7,9 @@ Run `sudo ./install.sh` to install AutoMedia, or first run `./release.sh` to bui AutoMedia checks and downloads updates every 15 minutes. ## Usage -Run automedia with `sync` option and keep it running to track media. You can then use `add` option to add new media to track. +Run automedia with `sync` option and keep it running to track media. You can then use `add` option to add new media to track.\ +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. # Requirements ## System @@ -16,7 +18,7 @@ curl, transmission-cli, notify-send (optional) lxml, requests, pure_protobuf (optional, used with mangaplus.shueisha.co.jp) # Requirements when using open_media.py ## System -dmenu, sxiv +dmenu, sxiv (for manga), mpv (for anime) # Important Do not move files inside the download directory. If you want to move them, move the whole download directory when automedia is not running and then set the download directory to the new location when using sync command. Binary files differdiff --git a/open_media.py b/open_media.py index d9d5ba3..f7a47cd 100755 --- a/open_media.py +++ b/open_media.py @@ -62,7 +62,7 @@ def main(): download_dir = sys.argv[1] if not os.path.isdir(download_dir): - print("No such directory: " % (download_dir)) + print("No such directory: " % str(download_dir)) exit(2) files_in_media_path = get_files_in_download_dir(download_dir) @@ -221,18 +221,6 @@ static void get_tracked_items(const char *tracked_dir, time_t age_sec, Buffer /* strcpy(data_filepath + data_filepath_length, dir->d_name); - strcpy(data_filepath + data_filepath_length + filename_len, "/synced"); - if(file_get_content(data_filepath, &file_data, &file_size) != 0) { - fprintf(stderr, "Failed to read the content of file %s\n", data_filepath); - continue; - } - - time_t synced_time = 0; - sscanf(file_data, "%ld", &synced_time); - free(file_data); - if(time_now - synced_time > age_sec) - continue; - strcpy(data_filepath + data_filepath_length + filename_len, "/updated"); if(file_get_content(data_filepath, &file_data, &file_size) != 0) { fprintf(stderr, "Failed to read the content of file %s\n", data_filepath); @@ -697,14 +685,21 @@ const char* path_get_filename(const char *filepath) { return filepath; } -static void command_cleanup(int argc, char **argv, const char *rss_config_dir, const char *html_config_dir) { - if(argc < 1) - usage_cleanup(); +static int compare_tracked_item(const void *a, const void *b) { + const TrackedItemData *list_data_a = a; + const TrackedItemData *list_data_b = b; + return list_data_a->updated_time - list_data_b->updated_time; +} - time_t days = strtol(argv[0], NULL, 0); - if(errno || days < 0) { - fprintf(stderr, "Invalid value for days argument %s, expected a positive number\n", argv[0]); - return; +static void command_cleanup(int argc, char **argv, const char *rss_config_dir, const char *html_config_dir) { + time_t days = 0; + if(argc >= 1) { + errno = 0; + days = strtol(argv[0], NULL, 0); + if(errno || days < 0) { + fprintf(stderr, "Invalid value for days argument %s, expected a positive number\n", argv[0]); + usage_cleanup(); + } } char rss_tracked_dir[PATH_MAX]; @@ -719,12 +714,15 @@ static void command_cleanup(int argc, char **argv, const char *rss_config_dir, c buffer_init(&tracked_items); int num_rss_items = 0; - time_t age_sec = 60 * 60 * 24 * days; + const time_t age_sec = 60 * 60 * 24 * days; get_tracked_items(rss_tracked_dir, age_sec, &tracked_items); num_rss_items = buffer_get_size(&tracked_items, sizeof(TrackedItemData)); get_tracked_items(html_tracked_dir, age_sec, &tracked_items); int num_tracked_items = buffer_get_size(&tracked_items, sizeof(TrackedItemData)); + qsort(tracked_items.data, num_rss_items, sizeof(TrackedItemData), compare_tracked_item); + qsort((TrackedItemData*)tracked_items.data + num_rss_items, num_tracked_items - num_rss_items, sizeof(TrackedItemData), compare_tracked_item); + TrackedItemData *list_begin = buffer_begin(&tracked_items); TrackedItemData *list_it = list_begin; TrackedItemData *list_end = buffer_end(&tracked_items); |