Adjusted logs

This commit is contained in:
emeric
2025-09-13 18:14:55 +02:00
parent 90fc3fc04b
commit f786b8b705
3 changed files with 56 additions and 49 deletions
@@ -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();
@@ -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();
});
};
@@ -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();