Merge branch 'develop' for release v3.71.0
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ Language: Cpp
|
|||||||
BasedOnStyle: Microsoft
|
BasedOnStyle: Microsoft
|
||||||
Standard: c++20
|
Standard: c++20
|
||||||
AccessModifierOffset: -4
|
AccessModifierOffset: -4
|
||||||
AlignAfterOpenBracket: DontAlign
|
AlignAfterOpenBracket: Align
|
||||||
AlignConsecutiveAssignments: false
|
AlignConsecutiveAssignments: false
|
||||||
AlignConsecutiveDeclarations: false
|
AlignConsecutiveDeclarations: false
|
||||||
AlignOperands: AlignAfterOperator
|
AlignOperands: AlignAfterOperator
|
||||||
|
|||||||
@@ -9,5 +9,5 @@ jobs:
|
|||||||
- name: Run clang-format style check
|
- name: Run clang-format style check
|
||||||
uses: jidicula/clang-format-action@v4.13.0
|
uses: jidicula/clang-format-action@v4.13.0
|
||||||
with:
|
with:
|
||||||
clang-format-version: '13'
|
clang-format-version: '19'
|
||||||
check-path: 'src'
|
check-path: 'src'
|
||||||
@@ -24,6 +24,7 @@ find_package(Threads REQUIRED)
|
|||||||
find_package(Filesystem REQUIRED)
|
find_package(Filesystem REQUIRED)
|
||||||
find_package(Boost REQUIRED COMPONENTS system program_options iostreams)
|
find_package(Boost REQUIRED COMPONENTS system program_options iostreams)
|
||||||
find_package(Wt REQUIRED COMPONENTS Wt Dbo DboSqlite3 HTTP)
|
find_package(Wt REQUIRED COMPONENTS Wt Dbo DboSqlite3 HTTP)
|
||||||
|
find_package(Pugixml CONFIG REQUIRED)
|
||||||
|
|
||||||
# WT
|
# WT
|
||||||
if (NOT Wt_FOUND)
|
if (NOT Wt_FOUND)
|
||||||
|
|||||||
+4
-4
@@ -17,11 +17,11 @@
|
|||||||
## Docker
|
## Docker
|
||||||
_Docker_ images are available, please see detailed instructions on https://hub.docker.com/r/epoupon/lms.
|
_Docker_ images are available, please see detailed instructions on https://hub.docker.com/r/epoupon/lms.
|
||||||
## Debian packages
|
## Debian packages
|
||||||
_Bookworm_ packages are provided for _amd64_ architectures.
|
_Trixie_ packages are provided for _amd64_ architectures.
|
||||||
As root, trust the following debian package provider and add it in your list of repositories:
|
As root, trust the following debian package provider and add it in your list of repositories:
|
||||||
```sh
|
```sh
|
||||||
wget --backups=1 https://debian.poupon.dev/apt/debian/epoupon.gpg -P /usr/share/keyrings
|
wget --backups=1 https://debian.poupon.dev/apt/debian/epoupon.gpg -P /usr/share/keyrings
|
||||||
echo "deb [signed-by=/usr/share/keyrings/epoupon.gpg] https://debian.poupon.dev/apt/debian bookworm main" > /etc/apt/sources.list.d/epoupon.list
|
echo "deb [signed-by=/usr/share/keyrings/epoupon.gpg] https://debian.poupon.dev/apt/debian trixie main" > /etc/apt/sources.list.d/epoupon.list
|
||||||
```
|
```
|
||||||
To install or upgrade _LMS_:
|
To install or upgrade _LMS_:
|
||||||
```sh
|
```sh
|
||||||
@@ -31,13 +31,13 @@ apt install lms
|
|||||||
The _lms_ service is started just after the package installation, run by a dedicated _lms_ system user.</br>
|
The _lms_ service is started just after the package installation, run by a dedicated _lms_ system user.</br>
|
||||||
Please refer to [Deployment](#deployment) for further configuration options.
|
Please refer to [Deployment](#deployment) for further configuration options.
|
||||||
## From source
|
## From source
|
||||||
__Note__: this installation process and the default values of the configuration files have been written for _Debian Bookworm_ and _Debian Trixie_. Therefore, you may have to adapt commands and/or paths in order to fit to your distribution.
|
__Note__: this installation process and the default values of the configuration files have been written for _Debian Trixie_. Therefore, you may have to adapt commands and/or paths in order to fit to your distribution.
|
||||||
### Build dependencies
|
### Build dependencies
|
||||||
__Notes__:
|
__Notes__:
|
||||||
* a C++20 compiler is needed
|
* a C++20 compiler is needed
|
||||||
* ffmpeg version 4 minimum is required
|
* ffmpeg version 4 minimum is required
|
||||||
```sh
|
```sh
|
||||||
apt-get install g++ cmake libboost-program-options-dev libboost-system-dev libavutil-dev libavformat-dev libstb-dev libconfig++-dev ffmpeg libtag1-dev libpam0g-dev libpugixml-dev libgtest-dev libarchive-dev libxxhash-dev libssl-dev
|
apt-get install build-essential cmake libboost-program-options-dev libboost-system-dev libavutil-dev libavformat-dev libstb-dev libconfig++-dev ffmpeg libtag-dev libpam0g-dev libpugixml-dev libgtest-dev libarchive-dev libxxhash-dev libssl-dev
|
||||||
```
|
```
|
||||||
__Notes__:
|
__Notes__:
|
||||||
* libpam0g-dev is optional (only for using PAM authentication)
|
* libpam0g-dev is optional (only for using PAM authentication)
|
||||||
|
|||||||
@@ -188,6 +188,7 @@
|
|||||||
<message id="Lms.Admin.InitWizard.header">Create administrator account</message>
|
<message id="Lms.Admin.InitWizard.header">Create administrator account</message>
|
||||||
|
|
||||||
<!--Auth-->
|
<!--Auth-->
|
||||||
|
<message id="Lms.Auth.login">Log in</message>
|
||||||
<message id="Lms.Auth.remember-me">Remember me</message>
|
<message id="Lms.Auth.remember-me">Remember me</message>
|
||||||
<message id="Lms.Auth.welcome">Welcome!</message>
|
<message id="Lms.Auth.welcome">Welcome!</message>
|
||||||
|
|
||||||
|
|||||||
@@ -187,6 +187,7 @@
|
|||||||
<message id="Lms.Admin.InitWizard.header">Crear cuenta de administrador</message>
|
<message id="Lms.Admin.InitWizard.header">Crear cuenta de administrador</message>
|
||||||
|
|
||||||
<!--Auth-->
|
<!--Auth-->
|
||||||
|
<message id="Lms.Auth.login">Iniciar Sesión</message>
|
||||||
<message id="Lms.Auth.remember-me">Recordarme</message>
|
<message id="Lms.Auth.remember-me">Recordarme</message>
|
||||||
<message id="Lms.Auth.welcome">¡Bienvenido!</message>
|
<message id="Lms.Auth.welcome">¡Bienvenido!</message>
|
||||||
|
|
||||||
|
|||||||
@@ -187,6 +187,7 @@
|
|||||||
<message id="Lms.Admin.InitWizard.header">Creation du compte administrateur</message>
|
<message id="Lms.Admin.InitWizard.header">Creation du compte administrateur</message>
|
||||||
|
|
||||||
<!--Auth-->
|
<!--Auth-->
|
||||||
|
<message id="Lms.Auth.login">Login</message>
|
||||||
<message id="Lms.Auth.remember-me">Se souvenir de moi</message>
|
<message id="Lms.Auth.remember-me">Se souvenir de moi</message>
|
||||||
<message id="Lms.Auth.welcome">Bienvenue !</message>
|
<message id="Lms.Auth.welcome">Bienvenue !</message>
|
||||||
|
|
||||||
|
|||||||
@@ -187,6 +187,7 @@
|
|||||||
<message id="Lms.Admin.InitWizard.header">Crea un account amministratore</message>
|
<message id="Lms.Admin.InitWizard.header">Crea un account amministratore</message>
|
||||||
|
|
||||||
<!--Auth-->
|
<!--Auth-->
|
||||||
|
<message id="Lms.Auth.login">Login</message>
|
||||||
<message id="Lms.Auth.remember-me">Ricordami</message>
|
<message id="Lms.Auth.remember-me">Ricordami</message>
|
||||||
<message id="Lms.Auth.welcome">Benvenuto!</message>
|
<message id="Lms.Auth.welcome">Benvenuto!</message>
|
||||||
|
|
||||||
|
|||||||
@@ -204,6 +204,7 @@
|
|||||||
<message id="Lms.Admin.InitWizard.header">Utwórz konto administratora</message>
|
<message id="Lms.Admin.InitWizard.header">Utwórz konto administratora</message>
|
||||||
|
|
||||||
<!--Auth-->
|
<!--Auth-->
|
||||||
|
<message id="Lms.Auth.login">Login</message>
|
||||||
<message id="Lms.Auth.remember-me">Zapamiętaj mnie</message>
|
<message id="Lms.Auth.remember-me">Zapamiętaj mnie</message>
|
||||||
<message id="Lms.Auth.welcome">Witam!</message>
|
<message id="Lms.Auth.welcome">Witam!</message>
|
||||||
|
|
||||||
|
|||||||
@@ -184,6 +184,7 @@
|
|||||||
<message id="Lms.Admin.InitWizard.header">新建管理员账号</message>
|
<message id="Lms.Admin.InitWizard.header">新建管理员账号</message>
|
||||||
|
|
||||||
<!--Auth-->
|
<!--Auth-->
|
||||||
|
<message id="Lms.Auth.login">登陆</message>
|
||||||
<message id="Lms.Auth.remember-me">记住我</message>
|
<message id="Lms.Auth.remember-me">记住我</message>
|
||||||
<message id="Lms.Auth.welcome">欢迎!</message>
|
<message id="Lms.Auth.welcome">欢迎!</message>
|
||||||
|
|
||||||
|
|||||||
+5
-1
@@ -101,8 +101,12 @@ cover-jpeg-quality = 75;
|
|||||||
# Preferred file names for covers (order is important, accept wildcards)
|
# Preferred file names for covers (order is important, accept wildcards)
|
||||||
cover-preferred-file-names = ("cover", "front", "folder", "default");
|
cover-preferred-file-names = ("cover", "front", "folder", "default");
|
||||||
|
|
||||||
|
# Image file names searched alongside the artist info file (artist.nfo)
|
||||||
|
# Note: files whose name is the artist's MBID are always searched first. You can place the MBID files anywhere in your libraries.
|
||||||
|
artist-info-image-file-names = ("thumb", "folder", "fanart");
|
||||||
|
|
||||||
# File names for artist images (order is important, accept wildcards)
|
# File names for artist images (order is important, accept wildcards)
|
||||||
# Note: files whose name is the artist's MBID are always searched before the names in this list. You can place the MBID files anywhere in your libraries.
|
# Note: files next to artist info files are searched first.
|
||||||
artist-image-file-names = ("artist");
|
artist-image-file-names = ("artist");
|
||||||
|
|
||||||
# File names for medium images (order is important, accept wildcards)
|
# File names for medium images (order is important, accept wildcards)
|
||||||
|
|||||||
@@ -44,10 +44,20 @@ namespace lms::core::stringUtils
|
|||||||
|
|
||||||
constexpr std::pair<char, std::string_view> jsonEscapeChars[]{
|
constexpr std::pair<char, std::string_view> jsonEscapeChars[]{
|
||||||
{ '\\', "\\\\" },
|
{ '\\', "\\\\" },
|
||||||
|
{ '"', "\\\"" },
|
||||||
|
{ '\b', "\\b" },
|
||||||
|
{ '\f', "\\f" },
|
||||||
{ '\n', "\\n" },
|
{ '\n', "\\n" },
|
||||||
{ '\r', "\\r" },
|
{ '\r', "\\r" },
|
||||||
{ '\t', "\\t" },
|
{ '\t', "\\t" },
|
||||||
{ '"', "\\\"" },
|
};
|
||||||
|
|
||||||
|
constexpr std::pair<char, std::string_view> xmlEscapeChars[]{
|
||||||
|
{ '&', "&" },
|
||||||
|
{ '<', "<" },
|
||||||
|
{ '>', ">" },
|
||||||
|
{ '\'', "'" },
|
||||||
|
{ '"', """ },
|
||||||
};
|
};
|
||||||
|
|
||||||
template<std::size_t N>
|
template<std::size_t N>
|
||||||
@@ -442,6 +452,16 @@ namespace lms::core::stringUtils
|
|||||||
details::writeEscapedString(os, str, details::jsonEscapeChars);
|
details::writeEscapedString(os, str, details::jsonEscapeChars);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string xmlEscape(std::string_view str)
|
||||||
|
{
|
||||||
|
return details::escape(str, details::xmlEscapeChars);
|
||||||
|
}
|
||||||
|
|
||||||
|
void writeXmlEscapedString(std::ostream& os, std::string_view str)
|
||||||
|
{
|
||||||
|
details::writeEscapedString(os, str, details::xmlEscapeChars);
|
||||||
|
}
|
||||||
|
|
||||||
std::string escapeString(std::string_view str, std::string_view charsToEscape, char escapeChar)
|
std::string escapeString(std::string_view str, std::string_view charsToEscape, char escapeChar)
|
||||||
{
|
{
|
||||||
std::string res;
|
std::string res;
|
||||||
|
|||||||
@@ -313,7 +313,7 @@ namespace lms::core::http
|
|||||||
LOG(DEBUG, "Throttling for " << duration.count() << " seconds");
|
LOG(DEBUG, "Throttling for " << duration.count() << " seconds");
|
||||||
|
|
||||||
_throttleTimer.expires_after(duration);
|
_throttleTimer.expires_after(duration);
|
||||||
_throttleTimer.async_wait([this](const boost::system::error_code& ec) {
|
_throttleTimer.async_wait(boost::asio::bind_executor(_strand, [this](const boost::system::error_code& ec) {
|
||||||
if (ec == boost::asio::error::operation_aborted)
|
if (ec == boost::asio::error::operation_aborted)
|
||||||
LOG(DEBUG, "Throttle aborted");
|
LOG(DEBUG, "Throttle aborted");
|
||||||
else if (ec)
|
else if (ec)
|
||||||
@@ -322,7 +322,7 @@ namespace lms::core::http
|
|||||||
setState(State::Idle);
|
setState(State::Idle);
|
||||||
if (!ec)
|
if (!ec)
|
||||||
sendNextQueuedRequest();
|
sendNextQueuedRequest();
|
||||||
});
|
}));
|
||||||
|
|
||||||
setState(State::Throttled);
|
setState(State::Throttled);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,9 @@ namespace lms::core::stringUtils
|
|||||||
void writeJSEscapedString(std::ostream& os, std::string_view str);
|
void writeJSEscapedString(std::ostream& os, std::string_view str);
|
||||||
void writeJsonEscapedString(std::ostream& os, std::string_view str);
|
void writeJsonEscapedString(std::ostream& os, std::string_view str);
|
||||||
|
|
||||||
|
[[nodiscard]] std::string xmlEscape(std::string_view str);
|
||||||
|
void writeXmlEscapedString(std::ostream& os, std::string_view str);
|
||||||
|
|
||||||
[[nodiscard]] std::string escapeString(std::string_view str, std::string_view charsToEscape, char escapeChar);
|
[[nodiscard]] std::string escapeString(std::string_view str, std::string_view charsToEscape, char escapeChar);
|
||||||
[[nodiscard]] std::string unescapeString(std::string_view str, char escapeChar);
|
[[nodiscard]] std::string unescapeString(std::string_view str, char escapeChar);
|
||||||
|
|
||||||
|
|||||||
@@ -221,6 +221,27 @@ namespace lms::core::stringUtils::tests
|
|||||||
EXPECT_EQ(jsonEscape(R"(Test'.mp3)"), R"(Test'.mp3)");
|
EXPECT_EQ(jsonEscape(R"(Test'.mp3)"), R"(Test'.mp3)");
|
||||||
EXPECT_EQ(jsonEscape(R"(Test"".mp3)"), R"(Test\"\".mp3)");
|
EXPECT_EQ(jsonEscape(R"(Test"".mp3)"), R"(Test\"\".mp3)");
|
||||||
EXPECT_EQ(jsonEscape(R"(\Test\.mp3)"), R"(\\Test\\.mp3)");
|
EXPECT_EQ(jsonEscape(R"(\Test\.mp3)"), R"(\\Test\\.mp3)");
|
||||||
|
EXPECT_EQ(jsonEscape("Line1\nLine2"), R"(Line1\nLine2)");
|
||||||
|
EXPECT_EQ(jsonEscape("Line1\rLine2"), R"(Line1\rLine2)");
|
||||||
|
EXPECT_EQ(jsonEscape("Col1\tCol2"), R"(Col1\tCol2)");
|
||||||
|
EXPECT_EQ(jsonEscape("Hello\bWorld"), R"(Hello\bWorld)");
|
||||||
|
EXPECT_EQ(jsonEscape("Hello\fWorld"), R"(Hello\fWorld)");
|
||||||
|
EXPECT_EQ(jsonEscape("Hello\nWorld"), R"(Hello\nWorld)");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(StringUtils, escapeXmlString)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(xmlEscape(""), "");
|
||||||
|
EXPECT_EQ(xmlEscape("Test.mp3"), "Test.mp3");
|
||||||
|
EXPECT_EQ(xmlEscape("A & B"), "A & B");
|
||||||
|
EXPECT_EQ(xmlEscape("<tag>"), "<tag>");
|
||||||
|
EXPECT_EQ(xmlEscape(R"(He said "Hello")"), "He said "Hello"");
|
||||||
|
EXPECT_EQ(xmlEscape("It's fine"), "It's fine");
|
||||||
|
EXPECT_EQ(xmlEscape(R"(<tag attr="val & val2">O'Hara</tag>)"), "<tag attr="val & val2">O'Hara</tag>");
|
||||||
|
EXPECT_EQ(xmlEscape(R"(\Test\.mp3)"), R"(\Test\.mp3)");
|
||||||
|
EXPECT_EQ(xmlEscape("Café & Tea"), "Café & Tea");
|
||||||
|
EXPECT_EQ(xmlEscape(R"(&<>'")"), "&<>'"");
|
||||||
|
EXPECT_EQ(xmlEscape("Line1\nLine2"), "Line1\nLine2");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(StringUtils, escapeString)
|
TEST(StringUtils, escapeString)
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ target_include_directories(lmsmetadata PRIVATE
|
|||||||
target_link_libraries(lmsmetadata PRIVATE
|
target_link_libraries(lmsmetadata PRIVATE
|
||||||
lmsav
|
lmsav
|
||||||
PkgConfig::Taglib
|
PkgConfig::Taglib
|
||||||
|
pugixml::pugixml
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(lmsmetadata PUBLIC
|
target_link_libraries(lmsmetadata PUBLIC
|
||||||
|
|||||||
@@ -19,14 +19,27 @@
|
|||||||
|
|
||||||
#include "metadata/ArtistInfo.hpp"
|
#include "metadata/ArtistInfo.hpp"
|
||||||
|
|
||||||
#include <boost/property_tree/ptree.hpp>
|
#include <pugixml.hpp>
|
||||||
#include <boost/property_tree/xml_parser.hpp>
|
|
||||||
|
|
||||||
#include "core/ILogger.hpp"
|
#include "core/ILogger.hpp"
|
||||||
|
#include "core/LiteralString.hpp"
|
||||||
#include "core/String.hpp"
|
#include "core/String.hpp"
|
||||||
|
|
||||||
namespace lms::metadata
|
namespace lms::metadata
|
||||||
{
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
std::optional<std::string_view> getText(const pugi::xml_node& node, const core::LiteralString& tag)
|
||||||
|
{
|
||||||
|
std::optional<std::string_view> res;
|
||||||
|
|
||||||
|
if (const pugi::xml_node child{ node.child(tag.c_str()) })
|
||||||
|
res = std::string_view{ child.child_value() };
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
std::span<const std::filesystem::path> getSupportedArtistInfoFiles()
|
std::span<const std::filesystem::path> getSupportedArtistInfoFiles()
|
||||||
{
|
{
|
||||||
static const std::array<std::filesystem::path, 1> files{ "artist.nfo" };
|
static const std::array<std::filesystem::path, 1> files{ "artist.nfo" };
|
||||||
@@ -34,30 +47,34 @@ namespace lms::metadata
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArtistInfo parseArtistInfo(std::istream& is)
|
ArtistInfo parseArtistInfo(std::istream& is)
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
ArtistInfo artistInfo;
|
ArtistInfo artistInfo;
|
||||||
|
pugi::xml_document doc;
|
||||||
|
pugi::xml_parse_result result{ doc.load(is) };
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
LMS_LOG(METADATA, ERROR, "Cannot read artist info xml: " << result.description());
|
||||||
|
throw ArtistInfoParseException{ result.description() };
|
||||||
|
}
|
||||||
|
|
||||||
boost::property_tree::ptree root;
|
const pugi::xml_node artistNode{ doc.child("artist") };
|
||||||
boost::property_tree::read_xml(is, root);
|
if (!artistNode)
|
||||||
|
throw ArtistInfoParseException{ "No <artist> element found in artist info xml" };
|
||||||
|
|
||||||
const auto& artistNode{ root.get_child("artist") };
|
{
|
||||||
|
auto mbid{ getText(artistNode, "musicBrainzArtistID") };
|
||||||
|
if (!mbid.has_value())
|
||||||
|
mbid = getText(artistNode, "musicbrainzartistid"); // lidarr seems to put this in lowercase
|
||||||
|
artistInfo.mbid = core::UUID::fromString(core::stringUtils::stringTrim(mbid.has_value() ? *mbid : ""));
|
||||||
|
}
|
||||||
|
|
||||||
artistInfo.mbid = core::UUID::fromString(core::stringUtils::stringTrim(artistNode.get_optional<std::string>("musicBrainzArtistID").value_or("")));
|
artistInfo.name = core::stringUtils::stringTrim(getText(artistNode, "name").value_or(""));
|
||||||
artistInfo.name = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("name").value_or(""));
|
artistInfo.sortName = core::stringUtils::stringTrim(getText(artistNode, "sortname").value_or(""));
|
||||||
artistInfo.sortName = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("sortname").value_or(""));
|
artistInfo.type = core::stringUtils::stringTrim(getText(artistNode, "type").value_or(""));
|
||||||
artistInfo.type = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("type").value_or(""));
|
artistInfo.gender = core::stringUtils::stringTrim(getText(artistNode, "gender").value_or(""));
|
||||||
artistInfo.gender = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("gender").value_or(""));
|
artistInfo.disambiguation = core::stringUtils::stringTrim(getText(artistNode, "disambiguation").value_or(""));
|
||||||
artistInfo.disambiguation = core::stringUtils::stringTrim(artistNode.get_optional<std::string>("disambiguation").value_or(""));
|
artistInfo.biography = getText(artistNode, "biography").value_or("");
|
||||||
artistInfo.biography = artistNode.get_optional<std::string>("biography").value_or("");
|
|
||||||
|
|
||||||
return artistInfo;
|
return artistInfo;
|
||||||
}
|
}
|
||||||
catch (boost::property_tree::ptree_error& error)
|
|
||||||
{
|
|
||||||
LMS_LOG(METADATA, ERROR, "Cannot read artist xml info: " << error.what());
|
|
||||||
throw ArtistInfoParseException{ error.what() };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // namespace lms::metadata
|
} // namespace lms::metadata
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
#include <taglib/taglib.h>
|
#include <taglib/taglib.h>
|
||||||
|
|
||||||
#if (TAGLIB_MAJOR_VERSION > 2)
|
#if (TAGLIB_MAJOR_VERSION >= 2)
|
||||||
#define TAGLIB_HAS_DSF 1
|
#define TAGLIB_HAS_DSF 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@
|
|||||||
#include <taglib/wavfile.h>
|
#include <taglib/wavfile.h>
|
||||||
#include <taglib/wavpackfile.h>
|
#include <taglib/wavpackfile.h>
|
||||||
#if TAGLIB_HAS_DSF
|
#if TAGLIB_HAS_DSF
|
||||||
|
#include <taglib/dsdifffile.h>
|
||||||
#include <taglib/dsffile.h>
|
#include <taglib/dsffile.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -452,6 +453,8 @@ namespace lms::metadata::taglib
|
|||||||
#if TAGLIB_HAS_DSF
|
#if TAGLIB_HAS_DSF
|
||||||
else if (const auto* dsfProperties{ dynamic_cast<const TagLib::DSF::Properties*>(properties) })
|
else if (const auto* dsfProperties{ dynamic_cast<const TagLib::DSF::Properties*>(properties) })
|
||||||
_audioProperties.bitsPerSample = dsfProperties->bitsPerSample();
|
_audioProperties.bitsPerSample = dsfProperties->bitsPerSample();
|
||||||
|
else if (const auto* dsfProperties{ dynamic_cast<const TagLib::DSDIFF::Properties*>(properties) })
|
||||||
|
_audioProperties.bitsPerSample = dsfProperties->bitsPerSample();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@
|
|||||||
#include <taglib/wavfile.h>
|
#include <taglib/wavfile.h>
|
||||||
#include <taglib/wavpackfile.h>
|
#include <taglib/wavpackfile.h>
|
||||||
#if TAGLIB_HAS_DSF
|
#if TAGLIB_HAS_DSF
|
||||||
|
#include <taglib/dsdifffile.h>
|
||||||
#include <taglib/dsffile.h>
|
#include <taglib/dsffile.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -50,8 +51,7 @@ namespace lms::metadata::taglib::utils
|
|||||||
{
|
{
|
||||||
std::span<const std::filesystem::path> getSupportedExtensions()
|
std::span<const std::filesystem::path> getSupportedExtensions()
|
||||||
{
|
{
|
||||||
static const std::vector<std::filesystem::path> supportedExtensions
|
static const std::vector<std::filesystem::path> supportedExtensions{
|
||||||
{
|
|
||||||
".mp3", ".mp2", ".aac", ".ogg", ".oga", ".flac", ".spx", ".opus",
|
".mp3", ".mp2", ".aac", ".ogg", ".oga", ".flac", ".spx", ".opus",
|
||||||
".mpc", ".wv", ".ape", ".tta", ".m4a", ".m4r", ".m4b", ".m4p",
|
".mpc", ".wv", ".ape", ".tta", ".m4a", ".m4r", ".m4b", ".m4p",
|
||||||
".3g2", ".m4v", ".wma", ".asf", ".aif", ".aiff", ".afc", ".aifc",
|
".3g2", ".m4v", ".wma", ".asf", ".aif", ".aiff", ".afc", ".aifc",
|
||||||
@@ -201,9 +201,9 @@ namespace lms::metadata::taglib::utils
|
|||||||
else if (TagLib::RIFF::WAV::File::isSupported(stream))
|
else if (TagLib::RIFF::WAV::File::isSupported(stream))
|
||||||
file = std::make_unique<TagLib::RIFF::WAV::File>(stream, readAudioProperties, audioPropertiesStyle);
|
file = std::make_unique<TagLib::RIFF::WAV::File>(stream, readAudioProperties, audioPropertiesStyle);
|
||||||
#if TAGLIB_HAS_DSF
|
#if TAGLIB_HAS_DSF
|
||||||
else if (DSF::File::isSupported(stream))
|
else if (TagLib::DSF::File::isSupported(stream))
|
||||||
file = std::make_unique<TagLib::DSF::File>(stream, readAudioProperties, audioPropertiesStyle);
|
file = std::make_unique<TagLib::DSF::File>(stream, readAudioProperties, audioPropertiesStyle);
|
||||||
else if (DSDIFF::File::isSupported(stream))
|
else if (TagLib::DSDIFF::File::isSupported(stream))
|
||||||
file = std::make_unique<TagLib::DSDIFF::File>(stream, readAudioProperties, audioPropertiesStyle);
|
file = std::make_unique<TagLib::DSDIFF::File>(stream, readAudioProperties, audioPropertiesStyle);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -77,6 +77,24 @@ He moved from the UK to Montreal in 1984 to become resident DJ at a number of cl
|
|||||||
ASSERT_EQ(artistInfo.biography, "DJ and producer based in London, UK. Founder of Missile Records and Planet Of Drums.\r\n\r\nHe moved from the UK to Montreal in 1984 to become resident DJ at a number of clubs. In 1987, he began working as an A&R for JSE Agency & Management in New York, managing the likes of Tommy Musto, Frankie Bones, and The KLF. He also arranged and was tour manager for artists such as Womack & Womack, Jungle Brothers, Ice-T, and Guru Josh.");
|
ASSERT_EQ(artistInfo.biography, "DJ and producer based in London, UK. Founder of Missile Records and Planet Of Drums.\r\n\r\nHe moved from the UK to Montreal in 1984 to become resident DJ at a number of clubs. In 1987, he began working as an A&R for JSE Agency & Management in New York, managing the likes of Tommy Musto, Frankie Bones, and The KLF. He also arranged and was tour manager for artists such as Womack & Womack, Jungle Brothers, Ice-T, and Guru Josh.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ArtistInfo, basic_musicbrainzartistid)
|
||||||
|
{
|
||||||
|
std::istringstream is{ R"(<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
|
||||||
|
<artist>
|
||||||
|
<name>Tim Taylor</name>
|
||||||
|
<musicbrainzartistid>38811c52-85e3-4e2e-3319-ab7d9f2cfa5b</musicbrainzartistid>
|
||||||
|
<sortname>Taylor, Tim</sortname>
|
||||||
|
<disambiguation>Timothy Taylor</disambiguation>
|
||||||
|
</artist>)" };
|
||||||
|
|
||||||
|
const ArtistInfo artistInfo{ parseArtistInfo(is) };
|
||||||
|
|
||||||
|
EXPECT_EQ(artistInfo.mbid, core::UUID::fromString("38811c52-85e3-4e2e-3319-ab7d9f2cfa5b"));
|
||||||
|
EXPECT_EQ(artistInfo.name, "Tim Taylor");
|
||||||
|
ASSERT_EQ(artistInfo.sortName, "Taylor, Tim");
|
||||||
|
ASSERT_EQ(artistInfo.disambiguation, "Timothy Taylor");
|
||||||
|
}
|
||||||
|
|
||||||
TEST(ArtistInfo, trim)
|
TEST(ArtistInfo, trim)
|
||||||
{
|
{
|
||||||
std::istringstream is{ R"(<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
|
std::istringstream is{ R"(<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
pkg_check_modules(PUGIXML REQUIRED IMPORTED_TARGET pugixml)
|
|
||||||
|
|
||||||
add_library(lmspodcast STATIC
|
add_library(lmspodcast STATIC
|
||||||
impl/steps/CheckForMissingFilesStep.cpp
|
impl/steps/CheckForMissingFilesStep.cpp
|
||||||
impl/steps/ClearTmpDirectoryStep.cpp
|
impl/steps/ClearTmpDirectoryStep.cpp
|
||||||
@@ -22,13 +20,12 @@ target_include_directories(lmspodcast INTERFACE
|
|||||||
target_include_directories(lmspodcast PRIVATE
|
target_include_directories(lmspodcast PRIVATE
|
||||||
include
|
include
|
||||||
impl
|
impl
|
||||||
${PUGIXML_INCLUDE_DIRS}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(lmspodcast PRIVATE
|
target_link_libraries(lmspodcast PRIVATE
|
||||||
lmscore
|
lmscore
|
||||||
lmsimage
|
lmsimage
|
||||||
PkgConfig::PUGIXML
|
pugixml::pugixml
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(lmspodcast PUBLIC
|
target_link_libraries(lmspodcast PUBLIC
|
||||||
|
|||||||
@@ -274,8 +274,8 @@ namespace lms::podcast
|
|||||||
// order is important, each step is done only when the previous one is done
|
// order is important, each step is done only when the previous one is done
|
||||||
_refreshSteps.emplace_back(std::make_unique<ClearTmpDirectoryStep>(_refreshContext, onDoneCallback));
|
_refreshSteps.emplace_back(std::make_unique<ClearTmpDirectoryStep>(_refreshContext, onDoneCallback));
|
||||||
_refreshSteps.emplace_back(std::make_unique<CheckForMissingFilesStep>(_refreshContext, onDoneCallback));
|
_refreshSteps.emplace_back(std::make_unique<CheckForMissingFilesStep>(_refreshContext, onDoneCallback));
|
||||||
_refreshSteps.emplace_back(std::make_unique<RefreshPodcastsStep>(_refreshContext, onDoneCallback));
|
|
||||||
_refreshSteps.emplace_back(std::make_unique<RemovePodcastsStep>(_refreshContext, onDoneCallback));
|
_refreshSteps.emplace_back(std::make_unique<RemovePodcastsStep>(_refreshContext, onDoneCallback));
|
||||||
|
_refreshSteps.emplace_back(std::make_unique<RefreshPodcastsStep>(_refreshContext, onDoneCallback));
|
||||||
_refreshSteps.emplace_back(std::make_unique<RemoveEpisodesStep>(_refreshContext, onDoneCallback));
|
_refreshSteps.emplace_back(std::make_unique<RemoveEpisodesStep>(_refreshContext, onDoneCallback));
|
||||||
_refreshSteps.emplace_back(std::make_unique<DownloadPodcastArtworksStep>(_refreshContext, onDoneCallback));
|
_refreshSteps.emplace_back(std::make_unique<DownloadPodcastArtworksStep>(_refreshContext, onDoneCallback));
|
||||||
_refreshSteps.emplace_back(std::make_unique<DownloadEpisodeArtworksStep>(_refreshContext, onDoneCallback));
|
_refreshSteps.emplace_back(std::make_unique<DownloadEpisodeArtworksStep>(_refreshContext, onDoneCallback));
|
||||||
|
|||||||
@@ -79,9 +79,9 @@ namespace lms::podcast
|
|||||||
dbPodcast.modify()->setSubtitle(podcast.subtitle);
|
dbPodcast.modify()->setSubtitle(podcast.subtitle);
|
||||||
dbPodcast.modify()->setSummary(podcast.summary);
|
dbPodcast.modify()->setSummary(podcast.summary);
|
||||||
dbPodcast.modify()->setTitle(podcast.title);
|
dbPodcast.modify()->setTitle(podcast.title);
|
||||||
if (dbPodcast->getImageUrl() != podcast.imageUrl)
|
if (std::string previousUrl{ dbPodcast->getImageUrl() }; !previousUrl.empty() && previousUrl != podcast.imageUrl)
|
||||||
{
|
{
|
||||||
LMS_LOG(PODCAST, INFO, "Podcast '" << podcast.title << "' : image url changed from '" << dbPodcast->getImageUrl() << "' to '" << podcast.imageUrl << "'");
|
LMS_LOG(PODCAST, INFO, "Podcast '" << podcast.title << "' : image url changed from '" << previousUrl << "' to '" << podcast.imageUrl << "'");
|
||||||
if (db::Artwork::pointer currentArtwork{ dbPodcast->getArtwork() })
|
if (db::Artwork::pointer currentArtwork{ dbPodcast->getArtwork() })
|
||||||
removeArtwork(session, currentArtwork);
|
removeArtwork(session, currentArtwork);
|
||||||
|
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ namespace lms::scanner
|
|||||||
struct SearchArtistArtworkParams
|
struct SearchArtistArtworkParams
|
||||||
{
|
{
|
||||||
std::span<const std::string> artistFileNames;
|
std::span<const std::string> artistFileNames;
|
||||||
|
std::span<const std::string> artistInfoFileNames;
|
||||||
const ScannerSettings& settings;
|
const ScannerSettings& settings;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -101,7 +102,7 @@ namespace lms::scanner
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
db::Image::pointer searchImageInArtistInfoDirectory(db::Session& session, db::ArtistId artistId)
|
db::Image::pointer searchImageInArtistInfoDirectory(db::Session& session, const SearchArtistArtworkParams& searchParams, db::ArtistId artistId)
|
||||||
{
|
{
|
||||||
db::Image::pointer image;
|
db::Image::pointer image;
|
||||||
|
|
||||||
@@ -110,7 +111,7 @@ namespace lms::scanner
|
|||||||
fileInfoPaths.push_back(artistInfo->getAbsoluteFilePath());
|
fileInfoPaths.push_back(artistInfo->getAbsoluteFilePath());
|
||||||
|
|
||||||
if (!image)
|
if (!image)
|
||||||
image = findImageInDirectory(session, artistInfo->getDirectory()->getAbsolutePath(), std::array<std::string, 2>{ "thumb", "folder" });
|
image = findImageInDirectory(session, artistInfo->getDirectory()->getAbsolutePath(), searchParams.artistInfoFileNames);
|
||||||
});
|
});
|
||||||
|
|
||||||
if (fileInfoPaths.size() > 1)
|
if (fileInfoPaths.size() > 1)
|
||||||
@@ -198,7 +199,7 @@ namespace lms::scanner
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const db::Image::pointer image{ searchImageInArtistInfoDirectory(session, artist->getId()) };
|
const db::Image::pointer image{ searchImageInArtistInfoDirectory(session, searchParams, artist->getId()) };
|
||||||
if (image)
|
if (image)
|
||||||
return db::Artwork::find(session, image->getId());
|
return db::Artwork::find(session, image->getId());
|
||||||
}
|
}
|
||||||
@@ -253,6 +254,19 @@ namespace lms::scanner
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> constructArtistInfoFileNames()
|
||||||
|
{
|
||||||
|
std::vector<std::string> res;
|
||||||
|
|
||||||
|
core::Service<core::IConfig>::get()->visitStrings("artist-info-image-file-names",
|
||||||
|
[&res](std::string_view fileName) {
|
||||||
|
res.emplace_back(fileName);
|
||||||
|
},
|
||||||
|
{ "thumb", "folder", "fanart" });
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
bool fetchNextArtistIdRange(db::Session& session, db::ArtistId& lastRetrievedId, db::IdRange<db::ArtistId>& idRange)
|
bool fetchNextArtistIdRange(db::Session& session, db::ArtistId& lastRetrievedId, db::IdRange<db::ArtistId>& idRange)
|
||||||
{
|
{
|
||||||
constexpr std::size_t readBatchSize{ 100 };
|
constexpr std::size_t readBatchSize{ 100 };
|
||||||
@@ -274,6 +288,9 @@ namespace lms::scanner
|
|||||||
, _artistIdRange{ artistIdRange }
|
, _artistIdRange{ artistIdRange }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
~ComputeArtistArtworkAssociationsJob() override = default;
|
||||||
|
ComputeArtistArtworkAssociationsJob(const ComputeArtistArtworkAssociationsJob&) = delete;
|
||||||
|
ComputeArtistArtworkAssociationsJob& operator=(const ComputeArtistArtworkAssociationsJob&) = delete;
|
||||||
|
|
||||||
std::span<const ArtistArtworkAssociation> getAssociations() const { return _associations; }
|
std::span<const ArtistArtworkAssociation> getAssociations() const { return _associations; }
|
||||||
std::size_t getProcessedArtistCount() const { return _processedArtistCount; }
|
std::size_t getProcessedArtistCount() const { return _processedArtistCount; }
|
||||||
@@ -314,6 +331,7 @@ namespace lms::scanner
|
|||||||
ScanStepAssociateArtistImages::ScanStepAssociateArtistImages(InitParams& initParams)
|
ScanStepAssociateArtistImages::ScanStepAssociateArtistImages(InitParams& initParams)
|
||||||
: ScanStepBase{ initParams }
|
: ScanStepBase{ initParams }
|
||||||
, _artistFileNames{ constructArtistFileNames() }
|
, _artistFileNames{ constructArtistFileNames() }
|
||||||
|
, _artistInfoFileNames{ constructArtistInfoFileNames() }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,6 +357,7 @@ namespace lms::scanner
|
|||||||
|
|
||||||
const SearchArtistArtworkParams searchParams{
|
const SearchArtistArtworkParams searchParams{
|
||||||
.artistFileNames = _artistFileNames,
|
.artistFileNames = _artistFileNames,
|
||||||
|
.artistInfoFileNames = _artistInfoFileNames,
|
||||||
.settings = _settings,
|
.settings = _settings,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -41,5 +41,6 @@ namespace lms::scanner
|
|||||||
void process(ScanContext& context) override;
|
void process(ScanContext& context) override;
|
||||||
|
|
||||||
const std::vector<std::string> _artistFileNames;
|
const std::vector<std::string> _artistFileNames;
|
||||||
|
const std::vector<std::string> _artistInfoFileNames;
|
||||||
};
|
};
|
||||||
} // namespace lms::scanner
|
} // namespace lms::scanner
|
||||||
|
|||||||
@@ -64,6 +64,10 @@ target_link_libraries(lmssubsonic PUBLIC
|
|||||||
Wt::Wt
|
Wt::Wt
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
add_subdirectory(test)
|
||||||
|
endif()
|
||||||
|
|
||||||
if (BUILD_BENCHMARKS)
|
if (BUILD_BENCHMARKS)
|
||||||
add_subdirectory(bench)
|
add_subdirectory(bench)
|
||||||
endif()
|
endif()
|
||||||
@@ -23,9 +23,8 @@
|
|||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
#include <boost/property_tree/xml_parser.hpp>
|
|
||||||
|
|
||||||
#include "core/String.hpp"
|
#include "core/String.hpp"
|
||||||
|
#include "core/Utils.hpp"
|
||||||
#include "core/Version.hpp"
|
#include "core/Version.hpp"
|
||||||
|
|
||||||
#include "ProtocolVersion.hpp"
|
#include "ProtocolVersion.hpp"
|
||||||
@@ -113,133 +112,90 @@ namespace lms::api::subsonic
|
|||||||
setAttribute("version", std::to_string(protocolVersion.major) + "." + std::to_string(protocolVersion.minor) + "." + std::to_string(protocolVersion.patch));
|
setAttribute("version", std::to_string(protocolVersion.major) + "." + std::to_string(protocolVersion.minor) + "." + std::to_string(protocolVersion.patch));
|
||||||
}
|
}
|
||||||
|
|
||||||
Response Response::createOkResponse(ProtocolVersion protocolVersion)
|
void Response::XmlSerializer::serializeNode(std::ostream& os, const Node& node, std::string_view tagName)
|
||||||
{
|
{
|
||||||
return createResponseCommon(protocolVersion);
|
// Opening tag
|
||||||
|
os << '<' << tagName;
|
||||||
|
|
||||||
|
// Attributes
|
||||||
|
for (const auto& [key, value] : node._attributes)
|
||||||
|
{
|
||||||
|
os << ' ' << key.str() << '=';
|
||||||
|
os << '"';
|
||||||
|
serializeValue(os, value);
|
||||||
|
os << '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
Response Response::createFailedResponse(ProtocolVersion protocolVersion, const Error& error)
|
// Hack
|
||||||
|
if (tagName == "subsonic-response")
|
||||||
|
os << " xmlns=\"http://subsonic.org/restapi\"";
|
||||||
|
|
||||||
|
bool hasChildren = !node._children.empty() || !node._childrenArrays.empty() || !node._childrenValues.empty();
|
||||||
|
bool hasValue = node._value.has_value();
|
||||||
|
|
||||||
|
if (!hasChildren && !hasValue)
|
||||||
{
|
{
|
||||||
return createResponseCommon(protocolVersion, &error);
|
os << "/>"; // Self-closing tag
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Response Response::createResponseCommon(ProtocolVersion protocolVersion, const Error* error)
|
os << '>'; // End opening tag
|
||||||
{
|
|
||||||
Response response;
|
|
||||||
Node& responseNode{ response._root.createChild("subsonic-response") };
|
|
||||||
|
|
||||||
responseNode.setAttribute("status", error ? "failed" : "ok");
|
// Node value (text content)
|
||||||
responseNode.setVersionAttribute(protocolVersion);
|
if (hasValue)
|
||||||
|
serializeValue(os, *node._value);
|
||||||
|
|
||||||
if (error)
|
// Child nodes
|
||||||
|
for (const auto& [key, childNode] : node._children)
|
||||||
|
serializeNode(os, childNode, key.str());
|
||||||
|
|
||||||
|
// Child arrays
|
||||||
|
for (const auto& [key, childArrayNodes] : node._childrenArrays)
|
||||||
|
for (const Node& childNode : childArrayNodes)
|
||||||
|
serializeNode(os, childNode, key.str());
|
||||||
|
|
||||||
|
// Array values
|
||||||
|
for (const auto& [key, childValues] : node._childrenValues)
|
||||||
{
|
{
|
||||||
Node& errorNode{ responseNode.createChild("error") };
|
for (const Node::ValueType& value : childValues)
|
||||||
errorNode.setAttribute("code", static_cast<int>(error->getCode()));
|
{
|
||||||
errorNode.setAttribute("message", error->getMessage());
|
os << '<' << key.str() << '>';
|
||||||
|
serializeValue(os, value);
|
||||||
|
os << "</" << key.str() << '>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenSubsonic mandatory fields
|
// Closing tag
|
||||||
// No big deal to send them even for legacy clients
|
os << "</" << tagName << '>';
|
||||||
responseNode.setAttribute("type", "lms");
|
|
||||||
responseNode.setAttribute("serverVersion", core::getVersion());
|
|
||||||
responseNode.setAttribute("openSubsonic", true);
|
|
||||||
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Response::addNode(Node::Key key, Node&& node)
|
void Response::XmlSerializer::serializeValue(std::ostream& os, const Node::ValueType& value)
|
||||||
{
|
{
|
||||||
return _root._children["subsonic-response"].addChild(key, std::move(node));
|
std::visit(core::utils::overloads{
|
||||||
|
[&](const Node::string& str) { core::stringUtils::writeXmlEscapedString(os, str); },
|
||||||
|
[&](bool value) { os << (value ? "true" : "false"); },
|
||||||
|
[&](float value) { os << value; },
|
||||||
|
[&](long long value) { os << value; } },
|
||||||
|
value);
|
||||||
}
|
}
|
||||||
|
|
||||||
Response::Node& Response::createNode(Node::Key key)
|
void Response::XmlSerializer::serializeEscapedString(std::ostream& os, std::string_view str)
|
||||||
{
|
{
|
||||||
return _root._children["subsonic-response"].createChild(key);
|
core::stringUtils::writeXmlEscapedString(os, str);
|
||||||
}
|
|
||||||
|
|
||||||
Response::Node& Response::createArrayNode(Node::Key key)
|
|
||||||
{
|
|
||||||
return _root._children["subsonic-response"].createArrayChild(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Response::write(std::ostream& os, ResponseFormat format) const
|
|
||||||
{
|
|
||||||
switch (format)
|
|
||||||
{
|
|
||||||
case ResponseFormat::xml:
|
|
||||||
writeXML(os);
|
|
||||||
break;
|
|
||||||
case ResponseFormat::json:
|
|
||||||
writeJSON(os);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Response::writeXML(std::ostream& os) const
|
void Response::writeXML(std::ostream& os) const
|
||||||
{
|
{
|
||||||
std::function<boost::property_tree::ptree(const Node&)> nodeToPropertyTree = [&](const Node& node) {
|
os << R"(<?xml version="1.0" encoding="utf-8"?>)" << '\n';
|
||||||
boost::property_tree::ptree res;
|
|
||||||
|
|
||||||
auto valueToPropertyTree = [](const Node::ValueType& value) {
|
XmlSerializer serializer;
|
||||||
boost::property_tree::ptree res;
|
|
||||||
std::visit([&](const auto& rawValue) {
|
|
||||||
using RawValueType = std::decay_t<decltype(rawValue)>;
|
|
||||||
if constexpr (std::is_same_v<RawValueType, Node::string>)
|
|
||||||
res.put_value(core::stringUtils::replaceInString(rawValue, "\n", "\\n"));
|
|
||||||
else
|
|
||||||
res.put_value(rawValue);
|
|
||||||
},
|
|
||||||
value);
|
|
||||||
|
|
||||||
return res;
|
assert(_root._children.size() == 1);
|
||||||
};
|
if (_root._children.size() == 1)
|
||||||
|
|
||||||
if (node._value)
|
|
||||||
{
|
{
|
||||||
res = valueToPropertyTree(*node._value);
|
const auto& [tagName, node] = *_root._children.begin();
|
||||||
|
serializer.serializeNode(os, node, tagName.str());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
for (const auto& [key, childNode] : node._children)
|
|
||||||
{
|
|
||||||
boost::property_tree::ptree& tree{ res.add_child(std::string{ key.str() }, nodeToPropertyTree(childNode)) };
|
|
||||||
// Hardcoded attribute to simplify createOkResponse calls
|
|
||||||
if (key == "subsonic-response")
|
|
||||||
tree.put("<xmlattr>.xmlns", "http://subsonic.org/restapi");
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& [key, childArrayNodes] : node._childrenArrays)
|
|
||||||
{
|
|
||||||
for (const Node& childNode : childArrayNodes)
|
|
||||||
res.add_child(std::string{ key.str() }, nodeToPropertyTree(childNode));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& [key, childArrayValues] : node._childrenValues)
|
|
||||||
{
|
|
||||||
for (const Response::Node::ValueType& value : childArrayValues)
|
|
||||||
res.add_child(std::string{ key.str() }, valueToPropertyTree(value));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const auto& [key, value] : node._attributes)
|
|
||||||
{
|
|
||||||
if (std::holds_alternative<Node::string>(value))
|
|
||||||
res.put("<xmlattr>." + std::string{ key.str() }, std::get<Node::string>(value));
|
|
||||||
else if (std::holds_alternative<bool>(value))
|
|
||||||
res.put("<xmlattr>." + std::string{ key.str() }, std::get<bool>(value));
|
|
||||||
else if (std::holds_alternative<float>(value))
|
|
||||||
res.put("<xmlattr>." + std::string{ key.str() }, std::get<float>(value));
|
|
||||||
else if (std::holds_alternative<long long>(value))
|
|
||||||
res.put("<xmlattr>." + std::string{ key.str() }, std::get<long long>(value));
|
|
||||||
else
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
};
|
|
||||||
|
|
||||||
const boost::property_tree::ptree root{ nodeToPropertyTree(_root) };
|
|
||||||
boost::property_tree::write_xml(os, root);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Response::JsonSerializer::serializeNode(std::ostream& os, const Response::Node& node)
|
void Response::JsonSerializer::serializeNode(std::ostream& os, const Response::Node& node)
|
||||||
@@ -325,30 +281,18 @@ namespace lms::api::subsonic
|
|||||||
|
|
||||||
void Response::JsonSerializer::serializeValue(std::ostream& os, const Node::ValueType& value)
|
void Response::JsonSerializer::serializeValue(std::ostream& os, const Node::ValueType& value)
|
||||||
{
|
{
|
||||||
if (std::holds_alternative<Node::string>(value))
|
std::visit(
|
||||||
{
|
core::utils::overloads{
|
||||||
serializeEscapedString(os, std::get<Node::string>(value));
|
[&](const Node::string& str) { serializeEscapedString(os, str); },
|
||||||
}
|
[&](bool value) { os << (value ? "true" : "false"); },
|
||||||
else if (std::holds_alternative<bool>(value))
|
[&](float value) {
|
||||||
{
|
if (std::isnan(value) || std::fabs(value) == std::numeric_limits<float>::infinity())
|
||||||
os << (std::get<bool>(value) ? "true" : "false");
|
|
||||||
}
|
|
||||||
else if (std::holds_alternative<float>(value))
|
|
||||||
{
|
|
||||||
const float d{ std::get<float>(value) };
|
|
||||||
if (std::isnan(d) || std::fabs(d) == std::numeric_limits<float>::infinity())
|
|
||||||
os << "null";
|
os << "null";
|
||||||
else
|
else
|
||||||
os << d;
|
os << value;
|
||||||
}
|
},
|
||||||
else if (std::holds_alternative<long long>(value))
|
[&](long long value) { os << value; } },
|
||||||
{
|
value);
|
||||||
os << std::get<long long>(value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Response::JsonSerializer::serializeEscapedString(std::ostream& os, std::string_view str)
|
void Response::JsonSerializer::serializeEscapedString(std::ostream& os, std::string_view str)
|
||||||
@@ -358,6 +302,68 @@ namespace lms::api::subsonic
|
|||||||
os << '\"';
|
os << '\"';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Response Response::createOkResponse(ProtocolVersion protocolVersion)
|
||||||
|
{
|
||||||
|
return createResponseCommon(protocolVersion);
|
||||||
|
}
|
||||||
|
|
||||||
|
Response Response::createFailedResponse(ProtocolVersion protocolVersion, const Error& error)
|
||||||
|
{
|
||||||
|
return createResponseCommon(protocolVersion, &error);
|
||||||
|
}
|
||||||
|
|
||||||
|
Response Response::createResponseCommon(ProtocolVersion protocolVersion, const Error* error)
|
||||||
|
{
|
||||||
|
Response response;
|
||||||
|
Node& responseNode{ response._root.createChild("subsonic-response") };
|
||||||
|
|
||||||
|
responseNode.setAttribute("status", error ? "failed" : "ok");
|
||||||
|
responseNode.setVersionAttribute(protocolVersion);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
Node& errorNode{ responseNode.createChild("error") };
|
||||||
|
errorNode.setAttribute("code", static_cast<int>(error->getCode()));
|
||||||
|
errorNode.setAttribute("message", error->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
// OpenSubsonic mandatory fields
|
||||||
|
// No big deal to send them even for legacy clients
|
||||||
|
responseNode.setAttribute("type", "lms");
|
||||||
|
responseNode.setAttribute("serverVersion", core::getVersion());
|
||||||
|
responseNode.setAttribute("openSubsonic", true);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Response::addNode(Node::Key key, Node&& node)
|
||||||
|
{
|
||||||
|
return _root._children["subsonic-response"].addChild(key, std::move(node));
|
||||||
|
}
|
||||||
|
|
||||||
|
Response::Node& Response::createNode(Node::Key key)
|
||||||
|
{
|
||||||
|
return _root._children["subsonic-response"].createChild(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
Response::Node& Response::createArrayNode(Node::Key key)
|
||||||
|
{
|
||||||
|
return _root._children["subsonic-response"].createArrayChild(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Response::write(std::ostream& os, ResponseFormat format) const
|
||||||
|
{
|
||||||
|
switch (format)
|
||||||
|
{
|
||||||
|
case ResponseFormat::xml:
|
||||||
|
writeXML(os);
|
||||||
|
break;
|
||||||
|
case ResponseFormat::json:
|
||||||
|
writeJSON(os);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Response::writeJSON(std::ostream& os) const
|
void Response::writeJSON(std::ostream& os) const
|
||||||
{
|
{
|
||||||
JsonSerializer serializer;
|
JsonSerializer serializer;
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ namespace lms::api::subsonic
|
|||||||
Error(Code code)
|
Error(Code code)
|
||||||
: _code{ code } {}
|
: _code{ code } {}
|
||||||
|
|
||||||
|
virtual ~Error() = default;
|
||||||
|
|
||||||
|
Error(const Error&) = delete;
|
||||||
|
Error& operator=(const Error&) = delete;
|
||||||
|
|
||||||
virtual std::string getMessage() const = 0;
|
virtual std::string getMessage() const = 0;
|
||||||
|
|
||||||
Code getCode() const { return _code; }
|
Code getCode() const { return _code; }
|
||||||
@@ -318,8 +323,16 @@ namespace lms::api::subsonic
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void serializeNode(std::ostream& os, const Node& node);
|
void serializeNode(std::ostream& os, const Node& node);
|
||||||
void serializeValue(std::ostream& os, const Node::ValueType& value);
|
static void serializeValue(std::ostream& os, const Node::ValueType& value);
|
||||||
void serializeEscapedString(std::ostream&, std::string_view str);
|
static void serializeEscapedString(std::ostream&, std::string_view str);
|
||||||
|
};
|
||||||
|
|
||||||
|
class XmlSerializer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void serializeNode(std::ostream& os, const Node& node, std::string_view tagName);
|
||||||
|
static void serializeValue(std::ostream& os, const Node::ValueType& value);
|
||||||
|
static void serializeEscapedString(std::ostream&, std::string_view str);
|
||||||
};
|
};
|
||||||
|
|
||||||
void writeJSON(std::ostream& os) const;
|
void writeJSON(std::ostream& os) const;
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
include(GoogleTest)
|
||||||
|
|
||||||
|
add_executable(test-subsonic
|
||||||
|
SubsonicResponseTest.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(test-subsonic PRIVATE
|
||||||
|
../impl
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(test-subsonic PRIVATE
|
||||||
|
lmscore
|
||||||
|
lmssubsonic
|
||||||
|
GTest::GTest
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT CMAKE_CROSSCOMPILING)
|
||||||
|
gtest_discover_tests(test-subsonic)
|
||||||
|
endif()
|
||||||
|
|
||||||
@@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* 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 <sstream>
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "ProtocolVersion.hpp"
|
||||||
|
#include "SubsonicResponse.hpp"
|
||||||
|
|
||||||
|
namespace lms::api::subsonic::tests
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
Response generateFakeResponse()
|
||||||
|
{
|
||||||
|
Response response{ Response::createOkResponse(defaultServerProtocolVersion) };
|
||||||
|
|
||||||
|
Response::Node& node{ response.createNode("MyNode") };
|
||||||
|
node.setAttribute("Attr1", "value1");
|
||||||
|
node.setAttribute("Attr2", "value2");
|
||||||
|
node.setAttribute("attr3", "<value3=\"foo\">");
|
||||||
|
node.setAttribute("attr4", true);
|
||||||
|
node.setAttribute("attr5", false);
|
||||||
|
node.setAttribute("attr6", 3.14159265359);
|
||||||
|
node.setAttribute("attr7", 333666);
|
||||||
|
|
||||||
|
for (std::size_t i{}; i < 2; ++i)
|
||||||
|
{
|
||||||
|
Response::Node& childNode{ node.createArrayChild("MyArrayChild") };
|
||||||
|
childNode.setAttribute("Attr42", i);
|
||||||
|
|
||||||
|
node.addArrayValue("MyArray1", "value1");
|
||||||
|
node.addArrayValue("MyArray1", "value2");
|
||||||
|
for (std::size_t j{}; j < i; ++j)
|
||||||
|
node.addArrayValue("MyArray2", j);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
TEST(SubsonicResponse, emptyJson)
|
||||||
|
{
|
||||||
|
Response response{ Response::createOkResponse(ProtocolVersion{ 1, 16, 0 }) };
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
response.write(oss, ResponseFormat::json);
|
||||||
|
|
||||||
|
EXPECT_EQ(oss.str(), R"({"subsonic-response":{"openSubsonic":true,"serverVersion":"v3.70.0","status":"ok","type":"lms","version":"1.16.0"}})");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SubsonicResponse, json)
|
||||||
|
{
|
||||||
|
Response response{ generateFakeResponse() };
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
response.write(oss, ResponseFormat::json);
|
||||||
|
|
||||||
|
EXPECT_EQ(oss.str(), R"({"subsonic-response":{"openSubsonic":true,"serverVersion":"v3.70.0","status":"ok","type":"lms","version":"1.16.0","MyNode":{"Attr1":"value1","Attr2":"value2","attr3":"<value3=\"foo\">","attr4":true,"attr5":false,"attr6":3.14159,"attr7":333666,"MyArrayChild":[{"Attr42":0},{"Attr42":1}],"MyArray1":["value1","value2","value1","value2"],"MyArray2":[0]}}})");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SubsonicResponse, emptyXml)
|
||||||
|
{
|
||||||
|
Response response{ Response::createOkResponse(ProtocolVersion{ 1, 16, 0 }) };
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
response.write(oss, ResponseFormat::xml);
|
||||||
|
|
||||||
|
EXPECT_EQ(oss.str(), R"(<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<subsonic-response openSubsonic="true" serverVersion="v3.70.0" status="ok" type="lms" version="1.16.0" xmlns="http://subsonic.org/restapi"/>)");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SubsonicResponse, xml)
|
||||||
|
{
|
||||||
|
Response response{ generateFakeResponse() };
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
response.write(oss, ResponseFormat::xml);
|
||||||
|
|
||||||
|
EXPECT_EQ(oss.str(), R"(<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<subsonic-response openSubsonic="true" serverVersion="v3.70.0" status="ok" type="lms" version="1.16.0" xmlns="http://subsonic.org/restapi"><MyNode Attr1="value1" Attr2="value2" attr3="<value3="foo">" attr4="true" attr5="false" attr6="3.14159" attr7="333666"><MyArrayChild Attr42="0"/><MyArrayChild Attr42="1"/><MyArray1>value1</MyArray1><MyArray1>value2</MyArray1><MyArray1>value1</MyArray1><MyArray1>value2</MyArray1><MyArray2>0</MyArray2></MyNode></subsonic-response>)");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace lms::api::subsonic::tests
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
::testing::InitGoogleTest(&argc, argv);
|
||||||
|
return RUN_ALL_TESTS();
|
||||||
|
}
|
||||||
+1
-1
@@ -219,7 +219,7 @@ namespace lms::ui
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Wt::WPushButton* loginBtn{ bindNew<Wt::WPushButton>("login-btn", Wt::WString::tr("Lms.login")) };
|
Wt::WPushButton* loginBtn{ bindNew<Wt::WPushButton>("login-btn", Wt::WString::tr("Lms.Auth.login")) };
|
||||||
loginBtn->clicked().connect(this, processAuth);
|
loginBtn->clicked().connect(this, processAuth);
|
||||||
|
|
||||||
updateView(model.get());
|
updateView(model.get());
|
||||||
|
|||||||
Reference in New Issue
Block a user