Skip to content

Commit

Permalink
Add support for librespot without --autoplay
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed Sep 10, 2022
1 parent b7d2fc5 commit 7694741
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/spotifyclient/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,17 @@ auto SpotifyClient::Helper::running(const QString &path) -> bool
auto out = ps.readAllStandardOutput();
return QString(out).contains(path);
}

auto SpotifyClient::Helper::supportsAutoplay(const QString &path) -> bool
{
if (clientType(path) != lib::client_type::librespot)
{
return false;
}

const auto help = clientExec(path, {
"--help"
});

return help.contains("--autoplay");
}
7 changes: 7 additions & 0 deletions src/spotifyclient/helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ namespace SpotifyClient
static auto version(const QString &path) -> QString;
static auto running(const QString &path) -> bool;

/**
* Client supports --autoplay argument
* (librespot 0.4.2 and older only)
* @param path Path to client
*/
static auto supportsAutoplay(const QString &path) -> bool;

private:
Helper() = default;

Expand Down
6 changes: 5 additions & 1 deletion src/spotifyclient/runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ auto SpotifyClient::Runner::start() -> QString
arguments.append({
"--name", QString("%1 (librespot)").arg(APP_NAME),
"--initial-volume", "100",
"--autoplay",
"--cache", QString::fromStdString((paths.cache() / "librespot").string()),
});

if (SpotifyClient::Helper::supportsAutoplay(path))
{
arguments.append(QStringLiteral("--autoplay"));
}
}
else if (clientType == lib::client_type::spotifyd)
{
Expand Down

0 comments on commit 7694741

Please sign in to comment.