-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Subsonic API: added timestamps into coverart ids, Made use of image i…
…ds to save a lookup, ref #558
- Loading branch information
Showing
18 changed files
with
248 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (C) 2024 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 "CoverArtId.hpp" | ||
|
||
#include "SubsonicId.hpp" | ||
#include "core/String.hpp" | ||
|
||
namespace lms::api::subsonic | ||
{ | ||
namespace | ||
{ | ||
constexpr char timestampSeparatorChar{ ':' }; | ||
} | ||
|
||
std::string idToString(db::ImageId id) | ||
{ | ||
return "im-" + id.toString(); | ||
} | ||
|
||
std::string idToString(CoverArtId coverId) | ||
{ | ||
// produce "id:timestamp" | ||
std::string res{ std::visit([](auto&& id) { | ||
return idToString(id); | ||
}, | ||
coverId.id) }; | ||
|
||
res += timestampSeparatorChar; | ||
res += std::to_string(coverId.timestamp); | ||
|
||
return res; | ||
} | ||
} // namespace lms::api::subsonic | ||
|
||
// Used to parse parameters | ||
namespace lms::core::stringUtils | ||
{ | ||
template<> | ||
std::optional<db::ImageId> readAs(std::string_view str) | ||
{ | ||
std::vector<std::string_view> values{ core::stringUtils::splitString(str, '-') }; | ||
if (values.size() != 2) | ||
return std::nullopt; | ||
|
||
if (values[0] != "im") | ||
return std::nullopt; | ||
|
||
if (const auto value{ core::stringUtils::readAs<db::ReleaseId::ValueType>(values[1]) }) | ||
return db::ImageId{ *value }; | ||
|
||
return std::nullopt; | ||
} | ||
|
||
template<> | ||
std::optional<api::subsonic::CoverArtId> readAs(std::string_view str) | ||
{ | ||
// expect "id:timestamp" | ||
auto timeStampSeparator{ str.find_last_of(api::subsonic::timestampSeparatorChar) }; | ||
if (timeStampSeparator == std::string_view::npos) | ||
return std::nullopt; | ||
|
||
std::string_view strId{ str.substr(0, timeStampSeparator) }; | ||
std::string_view strTimestamp{ str.substr(timeStampSeparator + 1) }; | ||
|
||
api::subsonic::CoverArtId cover; | ||
if (const auto imagetId{ readAs<db::ImageId>(strId) }) | ||
cover.id = *imagetId; | ||
else if (const auto trackId{ readAs<db::TrackId>(strId) }) | ||
cover.id = *trackId; | ||
else | ||
return std::nullopt; | ||
|
||
if (const auto timestamp{ readAs<std::time_t>(strTimestamp) }) | ||
cover.timestamp = *timestamp; | ||
else | ||
return std::nullopt; | ||
|
||
return cover; | ||
} | ||
} // namespace lms::core::stringUtils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (C) 2024 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 <ctime> | ||
#include <variant> | ||
|
||
#include "core/String.hpp" | ||
#include "database/ImageId.hpp" | ||
#include "database/TrackId.hpp" | ||
|
||
namespace lms::api::subsonic | ||
{ | ||
struct CoverArtId | ||
{ | ||
std::variant<db::ImageId, db::TrackId> id; | ||
std::time_t timestamp; | ||
}; | ||
|
||
std::string idToString(CoverArtId coverId); | ||
std::string idToString(db::ImageId imageId); | ||
} // namespace lms::api::subsonic | ||
|
||
// Used to parse parameters | ||
namespace lms::core::stringUtils | ||
{ | ||
template<> | ||
std::optional<db::ImageId> readAs(std::string_view str); | ||
|
||
template<> | ||
std::optional<api::subsonic::CoverArtId> readAs(std::string_view str); | ||
} // namespace lms::core::stringUtils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.