Inline 4 trivial Void delegation shims
Remove YouTubeClient::urlEncode/decodeHtmlEntities/parseIso8601Duration and StateSerializer::getCurrentTimestampISO8601 — each just forwarded to one Void call — and have the ~12 call sites call Void directly (Void::Encoding::Url::encode, Void::Text::html_unescape, Void::Time::parse_iso8601_interval(...).value_or(0), Void::Time::utc_now_iso8601). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
17f31ea3e0
commit
f8757d6040
5 files changed
+13
-51
No files matched your search
@@ -135,15 +135,6 @@ namespace Echoion::Core
|
||||
void fetchVideoDurations(std::vector<Api::TrackInfo>& tracks,
|
||||
const std::vector<std::string>& videoIds);
|
||||
|
||||
// Parse ISO 8601 duration string
|
||||
[[nodiscard]] static std::chrono::seconds
|
||||
parseIso8601Duration(const std::string& duration);
|
||||
|
||||
// URL encode/decode helpers
|
||||
[[nodiscard]] static std::string urlEncode(std::string_view value);
|
||||
[[nodiscard]] static std::string
|
||||
decodeHtmlEntities(std::string_view value);
|
||||
|
||||
// Internal methods for playlist resolution
|
||||
[[nodiscard]] Api::Result<std::vector<Api::YouTubePlaylistItem>>
|
||||
fetchPlaylistItems(std::string_view playlistId);
|
||||
|
||||
@@ -33,9 +33,6 @@ namespace Echoion::Core
|
||||
// Extract version from JSON blob
|
||||
static uint32_t extractVersion(const std::string& jsonStr);
|
||||
|
||||
// Helper to get current timestamp
|
||||
static std::string getCurrentTimestampISO8601();
|
||||
|
||||
// Make it accessible to StateMigration
|
||||
friend class StateMigration;
|
||||
};
|
||||
|
||||
+10
-32
@@ -58,18 +58,6 @@ namespace
|
||||
namespace Echoion::Core
|
||||
{
|
||||
|
||||
// URL encode helper function
|
||||
std::string YouTubeClient::urlEncode(std::string_view value)
|
||||
{
|
||||
return Void::Encoding::Url::encode(value);
|
||||
}
|
||||
|
||||
// HTML entity decode helper function
|
||||
std::string YouTubeClient::decodeHtmlEntities(std::string_view value)
|
||||
{
|
||||
return Void::Text::html_unescape(value);
|
||||
}
|
||||
|
||||
YouTubeClient::YouTubeClient(std::shared_ptr<NetworkClient> networkClient)
|
||||
: networkClient_(std::move(networkClient)),
|
||||
ytDlpManager_(std::make_unique<YtDlpManager>(networkClient_)),
|
||||
@@ -346,7 +334,7 @@ namespace Echoion::Core
|
||||
Api::TrackInfo info;
|
||||
info.id = jStr(json, "id");
|
||||
if (jHas(json, "title")) {
|
||||
info.title = decodeHtmlEntities(jStr(json, "title"));
|
||||
info.title = Void::Text::html_unescape(jStr(json, "title"));
|
||||
}
|
||||
info.artist = jStr(json, "uploader");
|
||||
if (jHas(json, "duration")) {
|
||||
@@ -456,7 +444,7 @@ namespace Echoion::Core
|
||||
std::string url = std::format(
|
||||
"https://www.googleapis.com/youtube/v3/"
|
||||
"search?part=snippet&type=video&maxResults=10&q={}&key={}",
|
||||
urlEncode(query), apiKey);
|
||||
Void::Encoding::Url::encode(query), apiKey);
|
||||
|
||||
if (pageToken.has_value()) {
|
||||
url += std::format("&pageToken={}", *pageToken);
|
||||
@@ -573,10 +561,10 @@ namespace Echoion::Core
|
||||
if (const JValue* snippet = jObj(item, "snippet")) {
|
||||
if (jHas(*snippet, "title")) {
|
||||
track.title =
|
||||
decodeHtmlEntities(jStr(*snippet, "title"));
|
||||
Void::Text::html_unescape(jStr(*snippet, "title"));
|
||||
}
|
||||
if (jHas(*snippet, "channelTitle")) {
|
||||
track.artist = decodeHtmlEntities(
|
||||
track.artist = Void::Text::html_unescape(
|
||||
jStr(*snippet, "channelTitle"));
|
||||
}
|
||||
if (const JValue* thumbnails =
|
||||
@@ -718,7 +706,7 @@ namespace Echoion::Core
|
||||
if (jHas(*contentDetails, "duration")) {
|
||||
std::string durationStr =
|
||||
jStr(*contentDetails, "duration");
|
||||
auto duration = parseIso8601Duration(durationStr);
|
||||
auto duration = Void::Time::parse_iso8601_interval(durationStr).value_or(std::chrono::seconds{0});
|
||||
if (duration.count() > 0) {
|
||||
ECHOION_LOG_DEBUG(
|
||||
std::format("Got duration: {}, parse as: {}",
|
||||
@@ -745,16 +733,6 @@ namespace Echoion::Core
|
||||
}
|
||||
}
|
||||
|
||||
std::chrono::seconds
|
||||
YouTubeClient::parseIso8601Duration(const std::string& duration)
|
||||
{
|
||||
// Delegate to Void; an unparseable value yields zero (prior behaviour).
|
||||
if (auto d = Void::Time::parse_iso8601_interval(duration)) {
|
||||
return *d;
|
||||
}
|
||||
return std::chrono::seconds{0};
|
||||
}
|
||||
|
||||
Api::Result<Api::SearchResult> YouTubeClient::searchWithYtDlp(
|
||||
std::string_view query, const std::optional<std::string>& pageToken)
|
||||
{
|
||||
@@ -818,11 +796,11 @@ namespace Echoion::Core
|
||||
track.id = jStr(entry, "id");
|
||||
if (jHas(entry, "title")) {
|
||||
track.title =
|
||||
decodeHtmlEntities(jStr(entry, "title"));
|
||||
Void::Text::html_unescape(jStr(entry, "title"));
|
||||
}
|
||||
if (jHas(entry, "uploader")) {
|
||||
track.artist =
|
||||
decodeHtmlEntities(jStr(entry, "uploader"));
|
||||
Void::Text::html_unescape(jStr(entry, "uploader"));
|
||||
}
|
||||
if (jHas(entry, "duration")) {
|
||||
track.duration =
|
||||
@@ -1171,7 +1149,7 @@ namespace Echoion::Core
|
||||
Api::YouTubePlaylistItem item;
|
||||
item.videoId = jStr(entry, "id");
|
||||
if (jHas(entry, "title")) {
|
||||
item.title = decodeHtmlEntities(jStr(entry, "title"));
|
||||
item.title = Void::Text::html_unescape(jStr(entry, "title"));
|
||||
}
|
||||
if (const JValue* thumbs = jArr(entry, "thumbnails")) {
|
||||
const auto& arr = thumbs->as_array();
|
||||
@@ -1247,10 +1225,10 @@ namespace Echoion::Core
|
||||
Api::TrackInfo track;
|
||||
track.id = jStr(json, "id");
|
||||
if (jHas(json, "title")) {
|
||||
track.title = decodeHtmlEntities(jStr(json, "title"));
|
||||
track.title = Void::Text::html_unescape(jStr(json, "title"));
|
||||
}
|
||||
if (jHas(json, "uploader")) {
|
||||
track.artist = decodeHtmlEntities(jStr(json, "uploader"));
|
||||
track.artist = Void::Text::html_unescape(jStr(json, "uploader"));
|
||||
}
|
||||
if (jHas(json, "duration")) {
|
||||
track.duration = std::chrono::seconds(
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "echoion/core/state/StateSerializer.hpp"
|
||||
#include <Void/Data/Json.hpp>
|
||||
#include <Void/Data/Reflect.hpp>
|
||||
#include <Void/Time/Format.hpp>
|
||||
#include <format>
|
||||
|
||||
namespace Echoion::Core
|
||||
@@ -59,7 +60,7 @@ namespace Echoion::Core
|
||||
}
|
||||
|
||||
v1.version = 1;
|
||||
v1.savedAt = StateSerializer::getCurrentTimestampISO8601();
|
||||
v1.savedAt = Void::Time::utc_now_iso8601();
|
||||
|
||||
return v1;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Echoion::Core
|
||||
|
||||
return Api::StateBlob{.data = std::move(data),
|
||||
.version = CURRENT_VERSION,
|
||||
.timestamp = getCurrentTimestampISO8601()};
|
||||
.timestamp = Void::Time::utc_now_iso8601()};
|
||||
}
|
||||
|
||||
Api::Result<StateV1>
|
||||
@@ -130,9 +130,4 @@ namespace Echoion::Core
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string StateSerializer::getCurrentTimestampISO8601()
|
||||
{
|
||||
return Void::Time::utc_now_iso8601();
|
||||
}
|
||||
|
||||
} // namespace Echoion::Core
|
||||
Reference in new issue
Block a user