diff --git a/include/echoion/core/YouTubeClient.hpp b/include/echoion/core/YouTubeClient.hpp index b104911..a7b75cd 100644 --- a/include/echoion/core/YouTubeClient.hpp +++ b/include/echoion/core/YouTubeClient.hpp @@ -135,15 +135,6 @@ namespace Echoion::Core void fetchVideoDurations(std::vector& tracks, const std::vector& 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> fetchPlaylistItems(std::string_view playlistId); diff --git a/include/echoion/core/state/StateSerializer.hpp b/include/echoion/core/state/StateSerializer.hpp index c0cc4f2..96d3507 100644 --- a/include/echoion/core/state/StateSerializer.hpp +++ b/include/echoion/core/state/StateSerializer.hpp @@ -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; }; diff --git a/src/YouTubeClient.cpp b/src/YouTubeClient.cpp index 3b22897..bc54e12 100644 --- a/src/YouTubeClient.cpp +++ b/src/YouTubeClient.cpp @@ -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_(std::move(networkClient)), ytDlpManager_(std::make_unique(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 YouTubeClient::searchWithYtDlp( std::string_view query, const std::optional& 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( diff --git a/src/state/StateMigration.cpp b/src/state/StateMigration.cpp index a8c1e91..50b2842 100644 --- a/src/state/StateMigration.cpp +++ b/src/state/StateMigration.cpp @@ -2,6 +2,7 @@ #include "echoion/core/state/StateSerializer.hpp" #include #include +#include #include 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; } diff --git a/src/state/StateSerializer.cpp b/src/state/StateSerializer.cpp index 12bb51f..b0dabf2 100644 --- a/src/state/StateSerializer.cpp +++ b/src/state/StateSerializer.cpp @@ -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 @@ -130,9 +130,4 @@ namespace Echoion::Core return 0; } - std::string StateSerializer::getCurrentTimestampISO8601() - { - return Void::Time::utc_now_iso8601(); - } - } // namespace Echoion::Core