From a3b58e59da1ee4dbdb6515680173497643a379e3 Mon Sep 17 00:00:00 2001 From: Sepro Date: Sun, 19 Apr 2020 20:37:55 +0200 Subject: [PATCH] WebAPI: Expand RSS related API Added markAsRead API method with optional parameter for specifying single article. Added the rss_smart_episode_filters and rss_download_repack_proper_episodes keys to preference api. Added matchingArticles API method for retrieving articles that match specified rule. --- src/webui/api/appcontroller.cpp | 6 ++++ src/webui/api/rsscontroller.cpp | 50 +++++++++++++++++++++++++++++++++ src/webui/api/rsscontroller.h | 2 ++ 3 files changed, 58 insertions(+) diff --git a/src/webui/api/appcontroller.cpp b/src/webui/api/appcontroller.cpp index c7136efea..90096d903 100644 --- a/src/webui/api/appcontroller.cpp +++ b/src/webui/api/appcontroller.cpp @@ -255,6 +255,8 @@ void AppController::preferencesAction() data["rss_max_articles_per_feed"] = RSS::Session::instance()->maxArticlesPerFeed(); data["rss_processing_enabled"] = RSS::Session::instance()->isProcessingEnabled(); data["rss_auto_downloading_enabled"] = RSS::AutoDownloader::instance()->isProcessingEnabled(); + data["rss_download_repack_proper_episodes"] = RSS::AutoDownloader::instance()->downloadRepacks(); + data["rss_smart_episode_filters"] = RSS::AutoDownloader::instance()->smartEpisodeFilters().join('\n'); // Advanced settings // qBitorrent preferences @@ -643,6 +645,10 @@ void AppController::setPreferencesAction() RSS::Session::instance()->setProcessingEnabled(it.value().toBool()); if (hasKey("rss_auto_downloading_enabled")) RSS::AutoDownloader::instance()->setProcessingEnabled(it.value().toBool()); + if (hasKey("rss_download_repack_proper_episodes")) + RSS::AutoDownloader::instance()->setDownloadRepacks(it.value().toBool()); + if (hasKey("rss_smart_episode_filters")) + RSS::AutoDownloader::instance()->setSmartEpisodeFilters(it.value().toString().split('\n')); // Advanced settings // qBittorrent preferences diff --git a/src/webui/api/rsscontroller.cpp b/src/webui/api/rsscontroller.cpp index c2f951622..862a19414 100644 --- a/src/webui/api/rsscontroller.cpp +++ b/src/webui/api/rsscontroller.cpp @@ -28,12 +28,15 @@ #include "rsscontroller.h" +#include #include #include #include +#include "base/rss/rss_article.h" #include "base/rss/rss_autodownloader.h" #include "base/rss/rss_autodownloadrule.h" +#include "base/rss/rss_feed.h" #include "base/rss/rss_folder.h" #include "base/rss/rss_session.h" #include "base/utils/string.h" @@ -91,6 +94,29 @@ void RSSController::itemsAction() setResult(jsonVal.toObject()); } +void RSSController::markAsReadAction() +{ + requireParams({"itemPath"}); + + const QString itemPath {params()["itemPath"]}; + const QString articleId {params()["articleId"]}; + + RSS::Item *item = RSS::Session::instance()->itemByPath(itemPath); + if (!item) return; + + if (!articleId.isNull()) { + RSS::Feed *feed = qobject_cast(item); + if (feed) { + RSS::Article *article = feed->articleByGUID(articleId); + if (article) + article->markAsRead(); + } + } + else { + item->markAsRead(); + } +} + void RSSController::refreshItemAction() { requireParams({"itemPath"}); @@ -139,3 +165,27 @@ void RSSController::rulesAction() setResult(jsonObj); } + +void RSSController::matchingArticlesAction() +{ + requireParams({"ruleName"}); + + const QString ruleName {params()["ruleName"]}; + const RSS::AutoDownloadRule rule = RSS::AutoDownloader::instance()->ruleByName(ruleName); + + QJsonObject jsonObj; + for (const QString &feedURL : rule.feedURLs()) { + const RSS::Feed *feed = RSS::Session::instance()->feedByURL(feedURL); + if (!feed) continue; // feed doesn't exist + + QJsonArray matchingArticles; + for (const RSS::Article *article : feed->articles()) { + if (rule.matches(article->data())) + matchingArticles << article->title(); + } + if (!matchingArticles.isEmpty()) + jsonObj.insert(feed->name(), matchingArticles); + } + + setResult(jsonObj); +} diff --git a/src/webui/api/rsscontroller.h b/src/webui/api/rsscontroller.h index a4d22e051..ff99a685d 100644 --- a/src/webui/api/rsscontroller.h +++ b/src/webui/api/rsscontroller.h @@ -44,9 +44,11 @@ private slots: void removeItemAction(); void moveItemAction(); void itemsAction(); + void markAsReadAction(); void refreshItemAction(); void setRuleAction(); void renameRuleAction(); void removeRuleAction(); void rulesAction(); + void matchingArticlesAction(); };