1 parent
9f06af6c80
commit
7975f2b38e
19 files changed
+2020
-747
No files matched your search
+43
-30
@@ -105,9 +105,7 @@ namespace Echoion::Core
|
||||
youtubeConfig.ytDlpMaxConcurrent);
|
||||
}
|
||||
|
||||
// Configure URL shortening
|
||||
youTubeClient_->setUrlShorteningEnabled(
|
||||
youtubeConfig.enableUrlShortening);
|
||||
// URL shortening is configured by Core after extension services load.
|
||||
|
||||
auto ytResult = youTubeClient_->initialize();
|
||||
if (!ytResult) {
|
||||
@@ -267,8 +265,6 @@ namespace Echoion::Core
|
||||
youTubeClient_->setMaxConcurrentResolutions(
|
||||
youtube.ytDlpMaxConcurrent);
|
||||
}
|
||||
youTubeClient_->setUrlShorteningEnabled(youtube.enableUrlShortening);
|
||||
|
||||
const bool hasKey = youtube.youtubeApiKey.has_value() &&
|
||||
!youtube.youtubeApiKey->empty();
|
||||
Void::Log::info("MusicManager", "{}",
|
||||
@@ -463,7 +459,9 @@ namespace Echoion::Core
|
||||
|
||||
void MusicManager::addTrackSource(std::shared_ptr<ITrackSource> source)
|
||||
{
|
||||
if (router_) router_->addSource(std::move(source));
|
||||
if (router_) {
|
||||
router_->addSource(std::move(source));
|
||||
}
|
||||
}
|
||||
|
||||
void MusicManager::shutdown()
|
||||
@@ -809,8 +807,8 @@ namespace Echoion::Core
|
||||
// Daily counters / top-requesters stats. clientId 0 is radio/system
|
||||
// (autoplay refill) — automatic adds don't count as user requests.
|
||||
if (database_ && clientId != 0) {
|
||||
(void)database_->logQueueAddition(
|
||||
clientUid(clientId).value_or(""), nicknameFor(clientId));
|
||||
(void)database_->logQueueAddition(clientUid(clientId).value_or(""),
|
||||
nicknameFor(clientId));
|
||||
}
|
||||
|
||||
// Auto-start when idle with an online audience.
|
||||
@@ -953,6 +951,9 @@ namespace Echoion::Core
|
||||
importRunning_ = false;
|
||||
return;
|
||||
}
|
||||
if (youTubeClient_) {
|
||||
youTubeClient_->populateShortenedUrls(*tracks);
|
||||
}
|
||||
size_t queued = 0;
|
||||
for (const auto& track : *tracks) {
|
||||
if (queueTrack(track, clientId)) {
|
||||
@@ -1057,26 +1058,33 @@ namespace Echoion::Core
|
||||
// YouTube search goes through the router (Invidious/Piped/ytdlp);
|
||||
// Yandex is called directly (its canHandle rejects text, so the
|
||||
// router never routes bare queries to it).
|
||||
const auto applyShortening =
|
||||
[this](Api::Result<Api::SearchResult> result) {
|
||||
if (result && youTubeClient_) {
|
||||
youTubeClient_->populateShortenedUrls(result->tracks);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
const auto youtube = [&]() -> Api::Result<Api::SearchResult> {
|
||||
if (router_) {
|
||||
return router_->search(query);
|
||||
return applyShortening(router_->search(query));
|
||||
}
|
||||
if (youTubeClient_) {
|
||||
return youTubeClient_->search(query);
|
||||
return applyShortening(youTubeClient_->search(query));
|
||||
}
|
||||
return Api::fail(Api::ErrorCode::ServiceUnavailable,
|
||||
"YouTube search unavailable");
|
||||
};
|
||||
const auto yandex = [&]() -> Api::Result<Api::SearchResult> {
|
||||
if (yandexSource_ && yandexSource_->isAvailable()) {
|
||||
return yandexSource_->search(query);
|
||||
return applyShortening(yandexSource_->search(query));
|
||||
}
|
||||
return Api::fail(Api::ErrorCode::ServiceUnavailable,
|
||||
"Yandex Music not configured");
|
||||
};
|
||||
const auto soundcloud = [&]() -> Api::Result<Api::SearchResult> {
|
||||
if (youTubeClient_) {
|
||||
return youTubeClient_->searchSoundCloud(query);
|
||||
return applyShortening(youTubeClient_->searchSoundCloud(query));
|
||||
}
|
||||
return Api::fail(Api::ErrorCode::ServiceUnavailable,
|
||||
"SoundCloud search unavailable");
|
||||
@@ -1167,6 +1175,9 @@ namespace Echoion::Core
|
||||
auto selected =
|
||||
(*pending)[index - 1]; // Convert to 0-based (copy to modify)
|
||||
selected.requestedBy = invokerName;
|
||||
if (youTubeClient_) {
|
||||
youTubeClient_->populateShortenedUrl(selected);
|
||||
}
|
||||
|
||||
auto result = queueTrack(selected, clientId);
|
||||
if (!result) {
|
||||
@@ -1569,9 +1580,8 @@ namespace Echoion::Core
|
||||
|
||||
// Queue tracks that are both unplayed-recently and within the
|
||||
// radio duration cap. Stops once maxToQueue have been queued.
|
||||
auto queueRadio =
|
||||
[&](const std::vector<Api::TrackInfo>& tracks,
|
||||
size_t maxToQueue) -> size_t {
|
||||
auto queueRadio = [&](const std::vector<Api::TrackInfo>& tracks,
|
||||
size_t maxToQueue) -> size_t {
|
||||
size_t queued = 0;
|
||||
for (const auto& track : tracks) {
|
||||
if (recentUrls.contains(track.originalUrl)) {
|
||||
@@ -1607,14 +1617,13 @@ namespace Echoion::Core
|
||||
related = youTubeClient_->radioMix(seed, 10);
|
||||
}
|
||||
if (related && !related->empty()) {
|
||||
queued = queueRadio(*related, std::numeric_limits<
|
||||
size_t>::max());
|
||||
queued = queueRadio(*related,
|
||||
std::numeric_limits<size_t>::max());
|
||||
if (queued > 0) {
|
||||
Void::Log::info(
|
||||
"MusicManager", "{}",
|
||||
std::format(
|
||||
"Autoplay queued {} related track(s)",
|
||||
queued));
|
||||
std::format("Autoplay queued {} related track(s)",
|
||||
queued));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1628,10 +1637,9 @@ namespace Echoion::Core
|
||||
random && !random->empty()) {
|
||||
queued = queueRadio(*random, 1);
|
||||
if (queued > 0) {
|
||||
Void::Log::info(
|
||||
"MusicManager", "{}",
|
||||
"Autoplay queued a random music video "
|
||||
"(no unplayed related track found)");
|
||||
Void::Log::info("MusicManager", "{}",
|
||||
"Autoplay queued a random music video "
|
||||
"(no unplayed related track found)");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1641,9 +1649,8 @@ namespace Echoion::Core
|
||||
engine_->start();
|
||||
}
|
||||
} else {
|
||||
Void::Log::debug(
|
||||
"MusicManager", "{}",
|
||||
"Autoplay found no track to queue");
|
||||
Void::Log::debug("MusicManager", "{}",
|
||||
"Autoplay found no track to queue");
|
||||
}
|
||||
autoplayFetching_ = false;
|
||||
});
|
||||
@@ -1706,6 +1713,12 @@ namespace Echoion::Core
|
||||
Api::Result<Api::TrackInfo>
|
||||
MusicManager::resolveQuery(const std::string& query)
|
||||
{
|
||||
const auto finalize = [this](Api::Result<Api::TrackInfo> result) {
|
||||
if (result && youTubeClient_) {
|
||||
youTubeClient_->populateShortenedUrl(*result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
// Playlist URLs are still resolved through the YouTube client (the
|
||||
// router's sources resolve single tracks).
|
||||
if (config_.allowPlaylistImports &&
|
||||
@@ -1717,13 +1730,13 @@ namespace Echoion::Core
|
||||
std::format("Extracted playlist ID: '{}'", *playlistId));
|
||||
auto playlist = youTubeClient_->getPlaylist(*playlistId);
|
||||
if (playlist && !playlist->tracks.empty()) {
|
||||
return playlist->tracks[0];
|
||||
return finalize(playlist->tracks[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (router_) {
|
||||
return router_->resolve(query);
|
||||
return finalize(router_->resolve(query));
|
||||
}
|
||||
|
||||
auto searchResult = youTubeClient_->search(query);
|
||||
@@ -1733,7 +1746,7 @@ namespace Echoion::Core
|
||||
if (searchResult->tracks.empty()) {
|
||||
return Api::fail(Api::ErrorCode::NotFound, "No results found");
|
||||
}
|
||||
return searchResult->tracks[0];
|
||||
return finalize(searchResult->tracks[0]);
|
||||
}
|
||||
|
||||
Api::Result<std::string>
|
||||
|
||||
Reference in new issue
Block a user