Added last.fm support to scrobble data, fixes #138
This commit is contained in:
@@ -34,6 +34,7 @@ add_library(lmscore STATIC
|
||||
impl/String.cpp
|
||||
impl/TraceLogger.cpp
|
||||
impl/UUID.cpp
|
||||
impl/Md5.cpp
|
||||
impl/XxHash3.cpp
|
||||
${CMAKE_CURRENT_BINARY_DIR}/impl/Version.cpp
|
||||
)
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "core/Md5.hpp"
|
||||
|
||||
#include <Wt/Utils.h>
|
||||
|
||||
namespace lms::core
|
||||
{
|
||||
std::array<std::byte, 16> md5(std::string_view data)
|
||||
{
|
||||
const std::string raw{ Wt::Utils::md5(std::string{ data }) };
|
||||
|
||||
std::array<std::byte, 16> result;
|
||||
for (std::size_t i{}; i < 16; ++i)
|
||||
result[i] = static_cast<std::byte>(static_cast<unsigned char>(raw[i]));
|
||||
return result;
|
||||
}
|
||||
} // namespace lms::core
|
||||
@@ -462,6 +462,22 @@ namespace lms::core::stringUtils
|
||||
detail::writeEscapedString(os, str, detail::xmlEscapeChars);
|
||||
}
|
||||
|
||||
std::string urlEncode(std::string_view str)
|
||||
{
|
||||
std::ostringstream encoded;
|
||||
encoded << std::hex << std::uppercase;
|
||||
|
||||
for (const unsigned char c : str)
|
||||
{
|
||||
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~')
|
||||
encoded << c;
|
||||
else
|
||||
encoded << '%' << std::setw(2) << std::setfill('0') << static_cast<int>(c);
|
||||
}
|
||||
|
||||
return encoded.str();
|
||||
}
|
||||
|
||||
std::string escapeString(std::string_view str, std::string_view charsToEscape, char escapeChar)
|
||||
{
|
||||
std::string res;
|
||||
|
||||
@@ -284,8 +284,12 @@ namespace lms::core::http
|
||||
LOG(DEBUG, "Remaining messages = " << (remainingCount ? *remainingCount : 0));
|
||||
if (mustThrottle || (remainingCount && *remainingCount == 0))
|
||||
{
|
||||
const auto waitDuration{ headerReadAs<std::chrono::seconds>(msg, "X-RateLimit-Reset-In") };
|
||||
throttle(waitDuration.value_or(_defaultRetryWaitDuration));
|
||||
const std::chrono::seconds waitDuration{
|
||||
headerReadAs<std::chrono::seconds>(msg, "X-RateLimit-Reset-In")
|
||||
.value_or(headerReadAs<std::chrono::seconds>(msg, "Retry-After")
|
||||
.value_or(_defaultRetryWaitDuration))
|
||||
};
|
||||
throttle(waitDuration);
|
||||
}
|
||||
|
||||
if (!mustThrottle)
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2025 Emeric Poupon
|
||||
*
|
||||
* This file is part of LMS.
|
||||
*
|
||||
* LMS is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* LMS is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <string_view>
|
||||
|
||||
namespace lms::core
|
||||
{
|
||||
std::array<std::byte, 16> md5(std::string_view data);
|
||||
} // namespace lms::core
|
||||
@@ -108,6 +108,8 @@ namespace lms::core::stringUtils
|
||||
[[nodiscard]] std::string xmlEscape(std::string_view str);
|
||||
void writeXmlEscapedString(std::ostream& os, std::string_view str);
|
||||
|
||||
[[nodiscard]] std::string urlEncode(std::string_view str);
|
||||
|
||||
[[nodiscard]] std::string escapeString(std::string_view str, std::string_view charsToEscape, char escapeChar);
|
||||
[[nodiscard]] std::string unescapeString(std::string_view str, char escapeChar);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user