Core: re-apply YouTube config (API key) on reload
reloadConfig/updateConfig updated the network proxy but never re-pushed the YouTube settings, so editing youtubeApiKey and reloading had no effect — the YouTube client kept its startup key. Add MusicManager::applyYouTubeConfig() (API key, cookies, concurrency, URL shortening; empty key clears it -> yt-dlp fallback) and call it from both reloadConfig and updateConfig. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
7e3081ecd1
commit
5796ccbc74
3 files changed
+36
No files matched your search
@@ -58,6 +58,11 @@ namespace Echoion::Core
|
|||||||
// instead of only living in the config copy.
|
// instead of only living in the config copy.
|
||||||
void applyNetworkConfig(const Api::NetworkConfig& network);
|
void applyNetworkConfig(const Api::NetworkConfig& network);
|
||||||
|
|
||||||
|
// Re-apply YouTube settings (API key, cookies, concurrency, URL
|
||||||
|
// shortening) to the YouTube client after a config reload. Passing
|
||||||
|
// an empty/absent API key clears it, restoring the yt-dlp fallback.
|
||||||
|
void applyYouTubeConfig(const Api::YouTubeConfig& youtube);
|
||||||
|
|
||||||
[[nodiscard]] Api::Result<std::string>
|
[[nodiscard]] Api::Result<std::string>
|
||||||
play(const std::string& query, uint64_t clientId);
|
play(const std::string& query, uint64_t clientId);
|
||||||
[[nodiscard]] Api::Result<void> pause();
|
[[nodiscard]] Api::Result<void> pause();
|
||||||
|
|||||||
@@ -834,6 +834,7 @@ namespace Echoion::Core
|
|||||||
// yt-dlp, ffmpeg), not just the HTTP client.
|
// yt-dlp, ffmpeg), not just the HTTP client.
|
||||||
if (musicManager_) {
|
if (musicManager_) {
|
||||||
musicManager_->applyNetworkConfig(config.network);
|
musicManager_->applyNetworkConfig(config.network);
|
||||||
|
musicManager_->applyYouTubeConfig(config.youtube);
|
||||||
} else if (networkClient_) {
|
} else if (networkClient_) {
|
||||||
networkClient_->setProxy(config.network.proxy);
|
networkClient_->setProxy(config.network.proxy);
|
||||||
}
|
}
|
||||||
@@ -916,6 +917,7 @@ namespace Echoion::Core
|
|||||||
// config copy. Without this the YouTube API kept using the old/no proxy.
|
// config copy. Without this the YouTube API kept using the old/no proxy.
|
||||||
if (musicManager_) {
|
if (musicManager_) {
|
||||||
musicManager_->applyNetworkConfig(config_.network);
|
musicManager_->applyNetworkConfig(config_.network);
|
||||||
|
musicManager_->applyYouTubeConfig(config_.youtube);
|
||||||
} else if (networkClient_) {
|
} else if (networkClient_) {
|
||||||
networkClient_->setProxy(config_.network.proxy);
|
networkClient_->setProxy(config_.network.proxy);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,6 +158,35 @@ namespace Echoion::Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MusicManager::applyYouTubeConfig(const Api::YouTubeConfig& youtube)
|
||||||
|
{
|
||||||
|
if (!youTubeClient_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty string clears the key (hasApiKey() -> false), so search falls
|
||||||
|
// back to yt-dlp.
|
||||||
|
youTubeClient_->setApiKey(youtube.youtubeApiKey.value_or(""));
|
||||||
|
|
||||||
|
if (youtube.youtubeCookiesPath.has_value()) {
|
||||||
|
youTubeClient_->setCookiesPath(*youtube.youtubeCookiesPath);
|
||||||
|
} else if (youtube.cookiesFromBrowser.has_value()) {
|
||||||
|
youTubeClient_->setCookiesFromBrowser(*youtube.cookiesFromBrowser);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (youtube.ytDlpMaxConcurrent > 0) {
|
||||||
|
youTubeClient_->setMaxConcurrentResolutions(
|
||||||
|
youtube.ytDlpMaxConcurrent);
|
||||||
|
}
|
||||||
|
youTubeClient_->setUrlShorteningEnabled(youtube.enableUrlShortening);
|
||||||
|
|
||||||
|
const bool hasKey = youtube.youtubeApiKey.has_value() &&
|
||||||
|
!youtube.youtubeApiKey->empty();
|
||||||
|
Void::Log::info("MusicManager", "{}",
|
||||||
|
std::format("YouTube config re-applied (API key: {})",
|
||||||
|
hasKey ? "set" : "none (yt-dlp)"));
|
||||||
|
}
|
||||||
|
|
||||||
void MusicManager::shutdown()
|
void MusicManager::shutdown()
|
||||||
{
|
{
|
||||||
isPlaying_ = false;
|
isPlaying_ = false;
|
||||||
|
|||||||
Reference in new issue
Block a user