Skip to content

Commit 6763d3c

Browse files
author
Jonas Dellinger
committed
Made UserAgent configurable and docs
1 parent 1cae73b commit 6763d3c

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎SpotifyAPI.Docs/docs/SpotifyLocalAPI/index.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,18 @@ _spotify = new SpotifyLocalAPI(new SpotifyLocalAPIConfig
5252
});
5353
```
5454

55+
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:
56+
57+
```cs
58+
var config = new SpotifyLocalAPIConfig { Port = 4371, HostUrl = "https://127.0.0.1" });
59+
_spotify = new SpotifyLocalAPI(config);
60+
61+
var status = _spotify.GetStatus();
62+
config.UserAgent = status.ClientVersion;
63+
64+
// Now you should call auth stuff, like "_spotify.Connect()"
65+
```
66+
5567
## Proxy Settings
5668

5769
You can forward your proxy settings to the local api by using a field in the `SpotifyLocalAPIConfig`.

‎SpotifyAPI/Local/RemoteHandler.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ internal WebClient GetWebClientWithUserAgentHeader()
186186
{
187187
Proxy = _config?.ProxyConfig?.CreateWebProxy()
188188
};
189-
wc.Headers.Add(HttpRequestHeader.UserAgent, "Spotify (1.0.85.257.g0f8531bd)");
189+
wc.Headers.Add(HttpRequestHeader.UserAgent, _config?.UserAgent);
190190

191191
return wc;
192192
}

‎SpotifyAPI/Local/SpotifyLocalAPIConfig.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ public class SpotifyLocalAPIConfig
1010
public int Port { get; set; } = 4381;
1111

1212
public ProxyConfig ProxyConfig { get; set; }
13+
14+
public string UserAgent { get; set; } = "Spotify (1.0.85.257.g0f8531bd)";
1315
}
1416
}

0 commit comments

Comments
 (0)