Making the librespot "username" and "password" params optional, and only throwing an error if one is provided without the the other.

This commit is contained in:
Tommy Goode 2017-02-08 00:07:59 -06:00
parent 0f2359c971
commit 1401ef76bd

View file

@ -37,12 +37,13 @@ SpotifyStream::SpotifyStream(PcmListener* pcmListener, const StreamUri& uri) : P
string bitrate = uri_.getQuery("bitrate", "320");
string devicename = uri_.getQuery("devicename", "Snapcast");
if (username.empty())
throw SnapException("missing parameter \"username\"");
if (password.empty())
throw SnapException("missing parameter \"password\"");
if (username.empty() != password.empty())
throw SnapException("missing parameter \"username\" or \"password\" (must provide both, or neither)");
params_ = "--name \"" + devicename + "\" --username \"" + username + "\" --password \"" + password + "\" --bitrate " + bitrate + " --backend pipe";
params_ = "--name \"" + devicename + "\"";
if (!username.empty() && !password.empty())
params_ += " --username \"" + username + "\" --password \"" + password + "\"";
params_ += " --bitrate " + bitrate + " --backend pipe";
// logO << "params: " << params << "\n";
}