aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-02-11 17:43:58 +0100
committerdec05eba <dec05eba@protonmail.com>2022-02-11 17:43:58 +0100
commit515477b5d597b807b27d2f95950b937ab8684c00 (patch)
tree48b258a58087f842be9a20d4601e095140ac2b82 /src/plugins
parent6f2648422107c8760b3e7717fc9b6693e37fcd92 (diff)
Add read local manga to automedia seen
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/LocalManga.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/plugins/LocalManga.cpp b/src/plugins/LocalManga.cpp
index 4deb229..3ad4ffa 100644
--- a/src/plugins/LocalManga.cpp
+++ b/src/plugins/LocalManga.cpp
@@ -4,6 +4,7 @@
#include "../../include/Theme.hpp"
#include "../../include/StringUtils.hpp"
#include "../../include/Storage.hpp"
+#include <unordered_set>
namespace QuickMedia {
// Pages are sorted from 1.png to n.png
@@ -155,6 +156,47 @@ namespace QuickMedia {
return PluginResult::OK;
}
+ static std::unordered_set<std::string> get_lines_in_file(const Path &filepath) {
+ std::unordered_set<std::string> lines;
+
+ std::string file_content;
+ if(file_get_content(filepath, file_content) != 0)
+ return lines;
+
+ string_split(file_content, '\n', [&lines](const char *str_part, size_t size) {
+ lines.insert(std::string(str_part, size));
+ return true;
+ });
+
+ return lines;
+ }
+
+ static bool append_seen_manga_to_automedia_seen(const std::string &manga_chapter_name) {
+ Path automedia_config_dir = get_home_dir().join(".config").join("automedia");
+ if(create_directory_recursive(automedia_config_dir) != 0) {
+ fprintf(stderr, "Warning: failed to create directory: %s\n", automedia_config_dir.data.c_str());
+ return false;
+ }
+
+ Path automedia_seen_filepath = automedia_config_dir;
+ automedia_seen_filepath.join("seen");
+
+ std::unordered_set<std::string> lines = get_lines_in_file(automedia_seen_filepath);
+ if(lines.find(manga_chapter_name) != lines.end())
+ return true; // Already seen
+
+ FILE *file = fopen(automedia_seen_filepath.data.c_str(), "ab");
+ if(!file) {
+ fprintf(stderr, "Warning: failed to open automedia seen file %s\n", automedia_seen_filepath.data.c_str());
+ return false;
+ }
+
+ std::string new_line_data = manga_chapter_name + "\n";
+ fwrite(new_line_data.data(), 1, new_line_data.size(), file);
+ fclose(file);
+ return true;
+ }
+
PluginResult LocalMangaChaptersPage::submit(const SubmitArgs &args, std::vector<Tab> &result_tabs) {
if(get_config().local_manga_directory.empty()) {
show_notification("QuickMedia", "local_manga_directory config is not set", Urgency::CRITICAL);
@@ -169,6 +211,10 @@ namespace QuickMedia {
Path chapter_url = Path(get_config().local_manga_directory).join(content_url).join(args.url);
std::vector<LocalMangaPage> pages = get_images_in_manga(chapter_url);
result_tabs.push_back(Tab{nullptr, std::make_unique<LocalMangaImagesPage>(program, content_title, args.title, args.url, thumbnail_url, std::move(pages)), nullptr});
+
+ if(is_program_executable_by_name("automedia"))
+ append_seen_manga_to_automedia_seen(content_url + "/" + args.url);
+
return PluginResult::OK;
}