summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDennis van der Schagt <dennisschagt@gmail.com>2024-10-04 14:43:03 +0200
committerDennis van der Schagt <dennisschagt@gmail.com>2024-10-04 14:49:05 +0200
commit03ed0b389eb140f9dc30faeb0252b7be48a3fd36 (patch)
tree1aa7ec1b21e0be95ad412e192582dbec8ad29c3b
parentdf2cb06e0173a78efbcb905a7a43f83e5839b7a0 (diff)
QueueManager: Pass RssFeed by reference instead of shared_ptr
-rw-r--r--include/queuemanager.h8
-rw-r--r--src/controller.cpp4
-rw-r--r--src/queuemanager.cpp17
-rw-r--r--test/queuemanager.cpp71
4 files changed, 48 insertions, 52 deletions
diff --git a/include/queuemanager.h b/include/queuemanager.h
index 759834bd..dfaa10e8 100644
--- a/include/queuemanager.h
+++ b/include/queuemanager.h
@@ -32,15 +32,13 @@ public:
QueueManager(ConfigContainer* cfg, std::string queue_file);
/// Adds the podcast URL to Podboat's queue file
- EnqueueResult enqueue_url(std::shared_ptr<RssItem> item,
- std::shared_ptr<RssFeed> feed);
+ EnqueueResult enqueue_url(std::shared_ptr<RssItem> item, RssFeed& feed);
/// Add all HTTP and HTTPS enclosures to the queue file
- EnqueueResult autoenqueue(std::shared_ptr<RssFeed> feed);
+ EnqueueResult autoenqueue(RssFeed& feed);
private:
- std::string generate_enqueue_filename(std::shared_ptr<RssItem> item,
- std::shared_ptr<RssFeed> feed);
+ std::string generate_enqueue_filename(std::shared_ptr<RssItem> item, RssFeed& feed);
};
}
diff --git a/src/controller.cpp b/src/controller.cpp
index e84cd2a1..57d6d328 100644
--- a/src/controller.cpp
+++ b/src/controller.cpp
@@ -725,7 +725,7 @@ void Controller::replace_feed(std::shared_ptr<RssFeed> oldfeed,
feedcontainer.replace_feed(pos, feed);
if (cfg.get_configvalue_as_bool("podcast-auto-enqueue")) {
- const auto result = queueManager.autoenqueue(feed);
+ const auto result = queueManager.autoenqueue(*feed);
switch (result.status) {
case EnqueueStatus::QUEUED_SUCCESSFULLY:
case EnqueueStatus::URL_QUEUED_ALREADY:
@@ -825,7 +825,7 @@ std::vector<std::shared_ptr<RssItem>> Controller::search_for_items(
EnqueueResult Controller::enqueue_url(std::shared_ptr<RssItem> item,
std::shared_ptr<RssFeed> feed)
{
- return queueManager.enqueue_url(item, feed);
+ return queueManager.enqueue_url(item, *feed);
}
void Controller::reload_urls_file()
diff --git a/src/queuemanager.cpp b/src/queuemanager.cpp
index 899dd4dc..846276e2 100644
--- a/src/queuemanager.cpp
+++ b/src/queuemanager.cpp
@@ -15,8 +15,7 @@ QueueManager::QueueManager(ConfigContainer* cfg_, std::string queue_file)
, queue_file(std::move(queue_file))
{}
-EnqueueResult QueueManager::enqueue_url(std::shared_ptr<RssItem> item,
- std::shared_ptr<RssFeed> feed)
+EnqueueResult QueueManager::enqueue_url(std::shared_ptr<RssItem> item, RssFeed& feed)
{
const std::string& url = item->enclosure_url();
const std::string filename = generate_enqueue_filename(item, feed);
@@ -65,7 +64,7 @@ std::string get_hostname_from_url(const std::string& url)
std::string QueueManager::generate_enqueue_filename(
std::shared_ptr<RssItem> item,
- std::shared_ptr<RssFeed> feed)
+ RssFeed& feed)
{
const std::string& url = item->enclosure_url();
const std::string& title = utils::utf8_to_locale(item->title());
@@ -87,7 +86,7 @@ std::string QueueManager::generate_enqueue_filename(
}
FmtStrFormatter fmt;
- fmt.register_fmt('n', utils::replace_all(feed->title(), "/", "_"));
+ fmt.register_fmt('n', utils::replace_all(feed.title(), "/", "_"));
fmt.register_fmt('h', get_hostname_from_url(url));
fmt.register_fmt('u', base);
fmt.register_fmt('F', utils::mt_strf_localtime("%F", pubDate));
@@ -102,23 +101,23 @@ std::string QueueManager::generate_enqueue_filename(
fmt.register_fmt('t', utils::replace_all(title, "/", "_"));
fmt.register_fmt('e', utils::replace_all(extension, "/", "_"));
- if (feed->rssurl() != item->feedurl() &&
+ if (feed.rssurl() != item->feedurl() &&
item->get_feedptr() != nullptr) {
std::string feedtitle = item->get_feedptr()->title();
utils::remove_soft_hyphens(feedtitle);
fmt.register_fmt('N', utils::replace_all(feedtitle, "/", "_"));
} else {
- fmt.register_fmt('N', utils::replace_all(feed->title(), "/", "_"));
+ fmt.register_fmt('N', utils::replace_all(feed.title(), "/", "_"));
}
const std::string dlpath = fmt.do_format(dlformat);
return dlpath;
}
-EnqueueResult QueueManager::autoenqueue(std::shared_ptr<RssFeed> feed)
+EnqueueResult QueueManager::autoenqueue(RssFeed& feed)
{
- std::lock_guard<std::mutex> lock(feed->item_mutex);
- for (const auto& item : feed->items()) {
+ std::lock_guard<std::mutex> lock(feed.item_mutex);
+ for (const auto& item : feed.items()) {
if (item->enqueued() || item->enclosure_url().empty()) {
continue;
}
diff --git a/test/queuemanager.cpp b/test/queuemanager.cpp
index 20006ba2..587fefff 100644
--- a/test/queuemanager.cpp
+++ b/test/queuemanager.cpp
@@ -25,7 +25,7 @@ SCENARIO("Smoke test for QueueManager", "[QueueManager]")
item->set_enclosure_url(enclosure_url);
item->set_enclosure_type("audio/mpeg");
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/news.atom");
+ RssFeed feed(&cache, "https://example.com/news.atom");
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());
@@ -144,7 +144,7 @@ SCENARIO("enqueue_url() errors if the filename is already used", "[QueueManager]
item2->set_enclosure_url(enclosure_url2);
item2->set_enclosure_type("audio/mpeg");
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/news.atom");
+ RssFeed feed(&cache, "https://example.com/news.atom");
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());
@@ -214,7 +214,7 @@ SCENARIO("enqueue_url() errors if the queue file can't be opened for writing",
item->set_enclosure_url("https://example.com/podcast.mp3");
item->set_enclosure_type("audio/mpeg");
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/news.atom");
+ RssFeed feed(&cache, "https://example.com/news.atom");
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());
@@ -261,7 +261,7 @@ TEST_CASE("QueueManager puts files into a location configured by `download-path`
item2->set_enclosure_url(enclosure_url2);
item2->set_enclosure_type("audio/vorbis");
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/podcasts.atom");
+ RssFeed feed(&cache, "https://example.com/podcasts.atom");
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());
@@ -312,7 +312,7 @@ TEST_CASE("QueueManager names files according to the `download-filename-format`
cfg.set_configvalue("download-filename-format", "%n");
feed->set_title("Feed title/theme");
- manager.enqueue_url(item, feed);
+ manager.enqueue_url(item, *feed);
const auto lines = test_helpers::file_contents(queue_file.get_path());
REQUIRE(lines.size() == 2);
@@ -324,7 +324,7 @@ TEST_CASE("QueueManager names files according to the `download-filename-format`
SECTION("%h for the enclosure URL's hostname") {
cfg.set_configvalue("download-filename-format", "%h");
- manager.enqueue_url(item, feed);
+ manager.enqueue_url(item, *feed);
const auto lines = test_helpers::file_contents(queue_file.get_path());
REQUIRE(lines.size() == 2);
@@ -335,7 +335,7 @@ TEST_CASE("QueueManager names files according to the `download-filename-format`
SECTION("%u for the enclosure URL's basename") {
cfg.set_configvalue("download-filename-format", "%u");
- manager.enqueue_url(item, feed);
+ manager.enqueue_url(item, *feed);
const auto lines = test_helpers::file_contents(queue_file.get_path());
REQUIRE(lines.size() == 2);
@@ -352,7 +352,7 @@ TEST_CASE("QueueManager names files according to the `download-filename-format`
// Tue, 06 Apr 2021 15:38:19 +0000
item->set_pubDate(1617723499);
- manager.enqueue_url(item, feed);
+ manager.enqueue_url(item, *feed);
const auto lines = test_helpers::file_contents(queue_file.get_path());
REQUIRE(lines.size() == 2);
@@ -365,7 +365,7 @@ TEST_CASE("QueueManager names files according to the `download-filename-format`
cfg.set_configvalue("download-filename-format", "%t");
item->set_title("Rain/snow/sun in a single day");
- manager.enqueue_url(item, feed);
+ manager.enqueue_url(item, *feed);
const auto lines = test_helpers::file_contents(queue_file.get_path());
REQUIRE(lines.size() == 2);
@@ -377,7 +377,7 @@ TEST_CASE("QueueManager names files according to the `download-filename-format`
SECTION("%e for enclosure's filename extension") {
cfg.set_configvalue("download-filename-format", "%e");
- manager.enqueue_url(item, feed);
+ manager.enqueue_url(item, *feed);
const auto lines = test_helpers::file_contents(queue_file.get_path());
REQUIRE(lines.size() == 2);
@@ -394,9 +394,8 @@ TEST_CASE("QueueManager names files according to the `download-filename-format`
item->set_feedptr(feed);
- auto irrelevant_feed = std::make_shared<RssFeed>(&cache,
- "https://example.com/podcasts.atom");
- irrelevant_feed->set_title("Irrelevant");
+ RssFeed irrelevant_feed(&cache, "https://example.com/podcasts.atom");
+ irrelevant_feed.set_title("Irrelevant");
manager.enqueue_url(item, irrelevant_feed);
@@ -411,7 +410,7 @@ TEST_CASE("QueueManager names files according to the `download-filename-format`
feed->set_title("Relevant feed");
item->set_feedptr(feed);
- manager.enqueue_url(item, feed);
+ manager.enqueue_url(item, *feed);
const auto lines = test_helpers::file_contents(queue_file.get_path());
REQUIRE(lines.size() == 2);
@@ -429,22 +428,22 @@ TEST_CASE("autoenqueue() adds all enclosures of all items to the queue", "[Queue
Cache cache(":memory:", &cfg);
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/podcasts.atom");
+ RssFeed feed(&cache, "https://example.com/podcasts.atom");
auto item1 = std::make_shared<RssItem>(&cache);
item1->set_enclosure_url("https://example.com/~adam/podcast.mp3");
item1->set_enclosure_type("audio/mpeg");
- feed->add_item(item1);
+ feed.add_item(item1);
auto item2 = std::make_shared<RssItem>(&cache);
item2->set_enclosure_url("https://example.com/episode.ogg");
item2->set_enclosure_type("audio/vorbis");
- feed->add_item(item2);
+ feed.add_item(item2);
auto item3 = std::make_shared<RssItem>(&cache);
item3->set_enclosure_url("https://example.com/~fae/painting.jpg");
item3->set_enclosure_type("");
- feed->add_item(item3);
+ feed.add_item(item3);
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());
@@ -484,19 +483,19 @@ SCENARIO("autoenqueue() errors if the filename is already used", "[QueueManager]
Cache cache(":memory:", &cfg);
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/news.atom");
+ RssFeed feed(&cache, "https://example.com/news.atom");
auto item1 = std::make_shared<RssItem>(&cache);
const std::string enclosure_url1("https://example.com/podcast.mp3");
item1->set_enclosure_url(enclosure_url1);
item1->set_enclosure_type("audio/mpeg");
- feed->add_item(item1);
+ feed.add_item(item1);
auto item2 = std::make_shared<RssItem>(&cache);
const std::string enclosure_url2("https://example.com/~joe/podcast.mp3");
item2->set_enclosure_url(enclosure_url2);
item2->set_enclosure_type("audio/mpeg");
- feed->add_item(item2);
+ feed.add_item(item2);
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());
@@ -538,12 +537,12 @@ SCENARIO("autoenqueue() errors if the queue file can't be opened for writing",
Cache cache(":memory:", &cfg);
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/news.atom");
+ RssFeed feed(&cache, "https://example.com/news.atom");
auto item = std::make_shared<RssItem>(&cache);
item->set_enclosure_url("https://example.com/podcast.mp3");
item->set_enclosure_type("audio/mpeg");
- feed->add_item(item);
+ feed.add_item(item);
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());
@@ -576,23 +575,23 @@ TEST_CASE("autoenqueue() skips already-enqueued items", "[QueueManager]")
Cache cache(":memory:", &cfg);
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/news.atom");
+ RssFeed feed(&cache, "https://example.com/news.atom");
auto item1 = std::make_shared<RssItem>(&cache);
item1->set_enclosure_url("https://example.com/podcast.mp3");
item1->set_enclosure_type("audio/mpeg");
- feed->add_item(item1);
+ feed.add_item(item1);
auto item2 = std::make_shared<RssItem>(&cache);
item2->set_enclosure_url("https://example.com/podcast2.mp3");
item2->set_enclosure_type("audio/mpeg");
item2->set_enqueued(true);
- feed->add_item(item2);
+ feed.add_item(item2);
auto item3 = std::make_shared<RssItem>(&cache);
item3->set_enclosure_url("https://example.com/podcast3.mp3");
item3->set_enclosure_type("audio/mpeg");
- feed->add_item(item3);
+ feed.add_item(item3);
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());
@@ -619,22 +618,22 @@ TEST_CASE("autoenqueue() only enqueues HTTP and HTTPS URLs", "[QueueManager]")
Cache cache(":memory:", &cfg);
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/news.atom");
+ RssFeed feed(&cache, "https://example.com/news.atom");
auto item1 = std::make_shared<RssItem>(&cache);
item1->set_enclosure_url("https://example.com/podcast.mp3");
item1->set_enclosure_type("audio/mpeg");
- feed->add_item(item1);
+ feed.add_item(item1);
auto item2 = std::make_shared<RssItem>(&cache);
item2->set_enclosure_url("http://example.com/podcast2.mp3");
item2->set_enclosure_type("audio/mpeg");
- feed->add_item(item2);
+ feed.add_item(item2);
auto item3 = std::make_shared<RssItem>(&cache);
item3->set_enclosure_url("ftp://user@example.com/podcast3.mp3");
item3->set_enclosure_type("audio/mpeg");
- feed->add_item(item3);
+ feed.add_item(item3);
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());
@@ -659,27 +658,27 @@ TEST_CASE("autoenqueue() does not enqueue items with an invalid podcast type",
ConfigContainer cfg;
Cache cache(":memory:", &cfg);
- auto feed = std::make_shared<RssFeed>(&cache, "https://example.com/news.atom");
+ RssFeed feed(&cache, "https://example.com/news.atom");
auto item1 = std::make_shared<RssItem>(&cache);
item1->set_enclosure_url("https://example.com/podcast1.mp3");
item1->set_enclosure_type("audio/mpeg");
- feed->add_item(item1);
+ feed.add_item(item1);
auto item2 = std::make_shared<RssItem>(&cache);
item2->set_enclosure_url("http://example.com/not-a-podcast.jpg");
item2->set_enclosure_type("image/jpeg");
- feed->add_item(item2);
+ feed.add_item(item2);
auto item3 = std::make_shared<RssItem>(&cache);
item3->set_enclosure_url("https://example.com/podcast2.mp3");
item3->set_enclosure_type("audio/mpeg");
- feed->add_item(item3);
+ feed.add_item(item3);
auto item4 = std::make_shared<RssItem>(&cache);
item4->set_enclosure_url("https://example.com/podcast3.mp3");
item4->set_enclosure_type("");
- feed->add_item(item4);
+ feed.add_item(item4);
test_helpers::TempFile queue_file;
QueueManager manager(&cfg, queue_file.get_path());