Adjusted logs
This commit is contained in:
@@ -112,38 +112,41 @@ namespace lms::podcast
|
|||||||
const std::string url{ episode->getImageUrl() };
|
const std::string url{ episode->getImageUrl() };
|
||||||
const std::filesystem::path finalFilePath{ getCachePath() / utils::generateRandomFileName() };
|
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;
|
core::http::ClientGETRequestParameters params;
|
||||||
params.relativeUrl = episode->getImageUrl();
|
params.relativeUrl = episode->getImageUrl();
|
||||||
params.onFailureFunc = [this, episode] {
|
params.onFailureFunc = [=, this] {
|
||||||
LMS_LOG(PODCAST, ERROR, "Failed to download episode image from '" << episode->getImageUrl() << "'");
|
LMS_LOG(PODCAST, ERROR, "Failed to download episode artwork for episode '" << episode->getTitle() << "' from '" << url << "'");
|
||||||
processNext();
|
processNext();
|
||||||
};
|
};
|
||||||
params.onSuccessFunc = [=, this](const Wt::Http::Message& msg) {
|
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();
|
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] {
|
params.onAbortFunc = [this] {
|
||||||
onAbort();
|
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?
|
// 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();
|
processNext();
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -111,6 +111,8 @@ namespace lms::podcast
|
|||||||
const std::string url{ podcast->getImageUrl() };
|
const std::string url{ podcast->getImageUrl() };
|
||||||
const std::filesystem::path finalFilePath{ getCachePath() / utils::generateRandomFileName() };
|
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;
|
core::http::ClientGETRequestParameters params;
|
||||||
params.relativeUrl = podcast->getImageUrl();
|
params.relativeUrl = podcast->getImageUrl();
|
||||||
params.onFailureFunc = [this, podcast] {
|
params.onFailureFunc = [this, podcast] {
|
||||||
@@ -118,31 +120,33 @@ namespace lms::podcast
|
|||||||
processNext();
|
processNext();
|
||||||
};
|
};
|
||||||
params.onSuccessFunc = [=, this](const Wt::Http::Message& msg) {
|
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();
|
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] {
|
params.onAbortFunc = [this] {
|
||||||
onAbort();
|
onAbort();
|
||||||
|
|||||||
Reference in New Issue
Block a user