From 6763d3cccc6140066b05f313425e430dd5d9d393 Mon Sep 17 00:00:00 2001 From: Jonas Dellinger Date: Wed, 18 Jul 2018 21:51:56 +0200 Subject: [PATCH] Made UserAgent configurable and docs --- SpotifyAPI.Docs/docs/SpotifyLocalAPI/index.md | 12 ++++++++++++ SpotifyAPI/Local/RemoteHandler.cs | 2 +- SpotifyAPI/Local/SpotifyLocalAPIConfig.cs | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/SpotifyAPI.Docs/docs/SpotifyLocalAPI/index.md b/SpotifyAPI.Docs/docs/SpotifyLocalAPI/index.md index cee0acde..17af3f19 100644 --- a/SpotifyAPI.Docs/docs/SpotifyLocalAPI/index.md +++ b/SpotifyAPI.Docs/docs/SpotifyLocalAPI/index.md @@ -52,6 +52,18 @@ _spotify = new SpotifyLocalAPI(new SpotifyLocalAPIConfig }); ``` +it's also possible to change the current `UserAgent` string, which is needed if the library wasn't updated for some time. In this case, you should first make an unauthenticated call with `spotify.GetStatus()`, receive the current spotify version, and update the config afterwards: + +```cs +var config = new SpotifyLocalAPIConfig { Port = 4371, HostUrl = "https://127.0.0.1" }); +_spotify = new SpotifyLocalAPI(config); + +var status = _spotify.GetStatus(); +config.UserAgent = status.ClientVersion; + +// Now you should call auth stuff, like "_spotify.Connect()" +``` + ## Proxy Settings You can forward your proxy settings to the local api by using a field in the `SpotifyLocalAPIConfig`. diff --git a/SpotifyAPI/Local/RemoteHandler.cs b/SpotifyAPI/Local/RemoteHandler.cs index 2682b38c..d21a79b3 100644 --- a/SpotifyAPI/Local/RemoteHandler.cs +++ b/SpotifyAPI/Local/RemoteHandler.cs @@ -186,7 +186,7 @@ namespace SpotifyAPI.Local { Proxy = _config?.ProxyConfig?.CreateWebProxy() }; - wc.Headers.Add(HttpRequestHeader.UserAgent, "Spotify (1.0.85.257.g0f8531bd)"); + wc.Headers.Add(HttpRequestHeader.UserAgent, _config?.UserAgent); return wc; } diff --git a/SpotifyAPI/Local/SpotifyLocalAPIConfig.cs b/SpotifyAPI/Local/SpotifyLocalAPIConfig.cs index bd9bea54..19cec30b 100644 --- a/SpotifyAPI/Local/SpotifyLocalAPIConfig.cs +++ b/SpotifyAPI/Local/SpotifyLocalAPIConfig.cs @@ -10,5 +10,7 @@ public int Port { get; set; } = 4381; public ProxyConfig ProxyConfig { get; set; } + + public string UserAgent { get; set; } = "Spotify (1.0.85.257.g0f8531bd)"; } } \ No newline at end of file