Add option to not kill all librespot instances

This commit is contained in:
Christian Flach 2020-01-30 14:15:54 +01:00
parent 2158c3e085
commit 678f102a98
No known key found for this signature in database
GPG key ID: 02D48802CD830869
3 changed files with 10 additions and 4 deletions

View file

@ -151,11 +151,11 @@ Snapserver supports [shairport-sync](https://github.com/mikebrady/shairport-sync
### Spotify
Snapserver supports [librespot](https://github.com/librespot-org/librespot) with the `pipe` backend.
1. Build and copy the `librespot` binary somewhere to your `PATH`, e.g. `/usr/local/bin/`
2. Configure snapserver with `stream = spotify:///librespot?name=Spotify[&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320][&onstart=<start command>][&onstop=<stop command>][&volume=<volume in percent>][&cache=<cache dir>]`
2. Configure snapserver with `stream = spotify:///librespot?name=Spotify[&username=<my username>&password=<my password>][&devicename=Snapcast][&bitrate=320][&onstart=<start command>][&onstop=<stop command>][&volume=<volume in percent>][&cache=<cache dir>][&killall=true]`
* Valid bitrates are 96, 160, 320
* `start command` and `stop command` are executed by Librespot at start/stop
* For example: `onstart=/usr/bin/logger -t Snapcast Starting spotify...`
* If `killall` is `true` (default), all running instances of Librespot will be killed. This MUST be disabled on all spotify streams by setting it to `false` if you want to use multiple spotify streams.
### Process
Snapserver can start any process and read PCM data from the stdout of the process:

View file

@ -44,6 +44,7 @@ LibrespotStream::LibrespotStream(PcmListener* pcmListener, boost::asio::io_conte
string devicename = uri_.getQuery("devicename", "Snapcast");
string onevent = uri_.getQuery("onevent", "");
bool normalize = (uri_.getQuery("normalize", "false") == "true");
killall_ = (uri_.getQuery("killall", "true") == "true");
if (username.empty() != password.empty())
throw SnapException("missing parameter \"username\" or \"password\" (must provide both, or neither)");
@ -87,8 +88,11 @@ void LibrespotStream::initExeAndPath(const std::string& filename)
exe_ = exe_.substr(exe_.find_last_of("/") + 1);
}
/// kill if it's already running
execGetOutput("killall " + exe_);
if (killall_)
{
/// kill if it's already running
execGetOutput("killall " + exe_);
}
}

View file

@ -40,6 +40,8 @@ public:
LibrespotStream(PcmListener* pcmListener, boost::asio::io_context& ioc, const StreamUri& uri);
protected:
bool killall_;
void onStderrMsg(const std::string& line) override;
void initExeAndPath(const std::string& filename) override;
};