From f786b8b705b781f546eb94dea4d606710af78b34 Mon Sep 17 00:00:00 2001 From: emeric Date: Sat, 13 Sep 2025 18:14:55 +0200 Subject: [PATCH] Adjusted logs --- .../steps/DownloadEpisodeArtworksStep.cpp | 53 ++++++++++--------- .../impl/steps/DownloadEpisodesStep.cpp | 2 +- .../steps/DownloadPodcastArtworksStep.cpp | 50 +++++++++-------- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/src/libs/services/podcast/impl/steps/DownloadEpisodeArtworksStep.cpp b/src/libs/services/podcast/impl/steps/DownloadEpisodeArtworksStep.cpp index 86f3d526..0d95573e 100644 --- a/src/libs/services/podcast/impl/steps/DownloadEpisodeArtworksStep.cpp +++ b/src/libs/services/podcast/impl/steps/DownloadEpisodeArtworksStep.cpp @@ -112,38 +112,41 @@ namespace lms::podcast const std::string url{ episode->getImageUrl() }; const std::filesystem::path finalFilePath{ getCachePath() / utils::generateRandomFileName() }; + LMS_LOG(PODCAST, DEBUG, "Downloading episode artwork for episode '" << episode->getTitle() << "' from '" << url << "' in file '" << finalFilePath << "'"); + core::http::ClientGETRequestParameters params; params.relativeUrl = episode->getImageUrl(); - params.onFailureFunc = [this, episode] { - LMS_LOG(PODCAST, ERROR, "Failed to download episode image from '" << episode->getImageUrl() << "'"); + params.onFailureFunc = [=, this] { + LMS_LOG(PODCAST, ERROR, "Failed to download episode artwork for episode '" << episode->getTitle() << "' from '" << url << "'"); processNext(); }; params.onSuccessFunc = [=, this](const Wt::Http::Message& msg) { - const std::string body{ msg.body() }; // API enforces a copy here + getExecutor().post([=, this] { + std::ofstream file{ finalFilePath, std::ios::binary | std::ios::trunc }; + if (!file) + { + std::error_code ec{ errno, std::generic_category() }; + LMS_LOG(PODCAST, ERROR, "Failed to open file " << finalFilePath << " for writing: " << ec.message()); + processNext(); + return; + } + + const std::string body{ msg.body() }; // API enforces a copy here + file.write(body.data(), body.size()); + if (!file) + { + std::error_code ec{ errno, std::generic_category() }; + LMS_LOG(PODCAST, ERROR, "Failed to write to file " << finalFilePath << ": " << ec.message()); + processNext(); + return; + } + + LMS_LOG(PODCAST, INFO, "Downloaded episode artwork for episode '" << episode->getTitle() << "'"); + const std::string* contentType{ msg.getHeader("Content-Type") }; + createEpisodeArtwork(getDb().getTLSSession(), episodeId, finalFilePath, contentType ? *contentType : "application/octet-stream"); - std::ofstream file{ finalFilePath, std::ios::binary | std::ios::trunc }; - if (!file) - { - std::error_code ec{ errno, std::generic_category() }; - LMS_LOG(PODCAST, ERROR, "Failed to open file " << finalFilePath << " for writing: " << ec.message()); processNext(); - return; - } - - file.write(body.data(), body.size()); - if (!file) - { - std::error_code ec{ errno, std::generic_category() }; - LMS_LOG(PODCAST, ERROR, "Failed to write to file " << finalFilePath << ": " << ec.message()); - processNext(); - return; - } - - const std::string* contentType{ msg.getHeader("Content-Type") }; - LMS_LOG(PODCAST, INFO, "Downloaded episode artwork for episode '" << episode->getTitle() << "' to " << finalFilePath << " with content type '" << (contentType ? *contentType : "unknown") << "', size = " << body.size() << " bytes"); - createEpisodeArtwork(getDb().getTLSSession(), episodeId, finalFilePath, contentType ? *contentType : "application/octet-stream"); - - processNext(); + }); }; params.onAbortFunc = [this] { onAbort(); diff --git a/src/libs/services/podcast/impl/steps/DownloadEpisodesStep.cpp b/src/libs/services/podcast/impl/steps/DownloadEpisodesStep.cpp index 8051ab32..26cb2cf7 100644 --- a/src/libs/services/podcast/impl/steps/DownloadEpisodesStep.cpp +++ b/src/libs/services/podcast/impl/steps/DownloadEpisodesStep.cpp @@ -182,7 +182,7 @@ namespace lms::podcast // TODO: now the file is complete, should we attempt to read it and get the real information like duration and size? - LMS_LOG(PODCAST, INFO, "Successfully downloaded episode '" << episode->getTitle() << "'"); + LMS_LOG(PODCAST, INFO, "Downloaded episode '" << episode->getTitle() << "'"); processNext(); }); }; diff --git a/src/libs/services/podcast/impl/steps/DownloadPodcastArtworksStep.cpp b/src/libs/services/podcast/impl/steps/DownloadPodcastArtworksStep.cpp index e2f08372..c27e1912 100644 --- a/src/libs/services/podcast/impl/steps/DownloadPodcastArtworksStep.cpp +++ b/src/libs/services/podcast/impl/steps/DownloadPodcastArtworksStep.cpp @@ -111,6 +111,8 @@ namespace lms::podcast const std::string url{ podcast->getImageUrl() }; const std::filesystem::path finalFilePath{ getCachePath() / utils::generateRandomFileName() }; + LMS_LOG(PODCAST, DEBUG, "Downloading podcast artwork '" << podcast->getTitle() << "' from '" << url << "' in file '" << finalFilePath << "'"); + core::http::ClientGETRequestParameters params; params.relativeUrl = podcast->getImageUrl(); params.onFailureFunc = [this, podcast] { @@ -118,31 +120,33 @@ namespace lms::podcast processNext(); }; params.onSuccessFunc = [=, this](const Wt::Http::Message& msg) { - const std::string body{ msg.body() }; // API enforces a copy here + getExecutor().post([=, this] { + const std::string body{ msg.body() }; // API enforces a copy here + + std::ofstream file{ finalFilePath, std::ios::binary | std::ios::app }; + if (!file) + { + std::error_code ec{ errno, std::generic_category() }; + LMS_LOG(PODCAST, ERROR, "Failed to open file " << finalFilePath << " for writing: " << ec.message()); + processNext(); + return; + } + + file.write(body.data(), body.size()); + if (!file) + { + std::error_code ec{ errno, std::generic_category() }; + LMS_LOG(PODCAST, ERROR, "Failed to write to file " << finalFilePath << ": " << ec.message()); + processNext(); + return; + } + + LMS_LOG(PODCAST, INFO, "Downloaded podcast artwork for podcast '" << podcast->getTitle()); + const std::string* contentType{ msg.getHeader("Content-Type") }; + createPodcastArtwork(getDb().getTLSSession(), podcastId, finalFilePath, contentType ? *contentType : "application/octet-stream"); - std::ofstream file{ finalFilePath, std::ios::binary | std::ios::app }; - if (!file) - { - std::error_code ec{ errno, std::generic_category() }; - LMS_LOG(PODCAST, ERROR, "Failed to open file " << finalFilePath << " for writing: " << ec.message()); processNext(); - return; - } - - file.write(body.data(), body.size()); - if (!file) - { - std::error_code ec{ errno, std::generic_category() }; - LMS_LOG(PODCAST, ERROR, "Failed to write to file " << finalFilePath << ": " << ec.message()); - processNext(); - return; - } - - const std::string* contentType{ msg.getHeader("Content-Type") }; - LMS_LOG(PODCAST, INFO, "Downloaded podcast artwork for podcast '" << podcast->getTitle() << "' to " << finalFilePath << " with content type '" << (contentType ? *contentType : "unknown") << "', size = " << body.size()); - createPodcastArtwork(getDb().getTLSSession(), podcastId, finalFilePath, contentType ? *contentType : "application/octet-stream"); - - processNext(); + }); }; params.onAbortFunc = [this] { onAbort();