Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/prebuilt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
with:
version: 6.10.3
arch: win64_msvc2022_64
modules: qtshadertools
modules: qtshadertools qtwebsockets
cache: true

- name: build
Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
with:
version: 6.12.0
arch: linux_gcc_64
# soloist, which is only built for linux, talks to spotify's soloist over websockets
# soloist talks to spotify's soloist over websockets
modules: qtshadertools qtwebsockets
cache: true

Expand Down Expand Up @@ -193,7 +193,7 @@ jobs:
host: mac
target: desktop
arch: clang_64
modules: qtshadertools
modules: qtshadertools qtwebsockets
cache: true

- name: build
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.24)

project(Swiftify
VERSION 0.20.3
VERSION 0.21.0
DESCRIPTION "A native Spotify client"
LANGUAGES C CXX)

Expand Down Expand Up @@ -40,8 +40,8 @@ endif()
# can be built and tested on a development machine without them.
option(SWIFTIFY_DESKTOP_INTEGRATION "Build the Linux desktop integration" ${SWIFTIFY_IS_LINUX})
# spotify soloist plays spotify's songs for accounts spotify no longer gives
# librespot the keys for. it is only built for linux.
option(SWIFTIFY_SOLOIST "Play Spotify songs through Spotify Soloist when it is installed" ${SWIFTIFY_IS_LINUX})
# librespot the keys for.
option(SWIFTIFY_SOLOIST "Play Spotify songs through Spotify Soloist when it is installed" ON)

find_package(Qt6 6.10 REQUIRED COMPONENTS
Core Gui Network Concurrent Qml Quick QuickControls2 ShaderTools)
Expand Down
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ first image shows equalizer, tempo and pitch settings. second picture shows how
### "spotify could not load this track" (soloist)

spotify refuses librespot the keys to decrypt songs on newer accounts (librespot's
logs say `error audio key 0 1`), so every song fails. on linux swiftify can play
logs say `error audio key 0 1`), so every song fails. swiftify can play
spotify's songs through [spotify soloist](https://developer.spotify.com/documentation/soloist)
instead, spotify's own connect client, which isnt affected.

1. install soloist from its [getting started guide](https://developer.spotify.com/documentation/soloist/tutorials/getting-started)
(`~/.local/bin/soloist` is fine)
(`~/.local/bin/soloist`, `/opt/homebrew/bin/soloist`, on your `PATH`, or beside `swiftify.exe` on windows)
2. make a soloist api key in the [developer dashboard](https://developer.spotify.com/dashboard/soloist)
and put it in `~/.config/soloist/api-key` (or `SOLOIST_API_KEY`)
and put it in `~/.config/soloist/api-key` (or `%LOCALAPPDATA%\soloist\api-key` on windows, or `SOLOIST_API_KEY`)
3. start swiftify. it starts soloist itself, as a connect device called "Swiftify".
the first time, pick "Swiftify" once in the devices list of the spotify desktop app on
the same computer (or the phone app), so soloist is signed in
4. press play in swiftify

with soloist, swiftify makes a sink called "Swiftify (Soloist)" for soloist to play into,
on linux with pipewire, swiftify makes a sink called "Swiftify (Soloist)" for soloist to play into,
and plays that on through its own output, so the equalizer and the visualizers still work.
this needs pipewire, under pulseaudio alone soloist plays straight to the speakers.
under pulseaudio alone, or on macos and windows, soloist plays straight to the speakers.
`SWIFTIFY_SOLOIST_ROUTE=off` does that on purpose. tempo and pitch only work on your own
music files, and crossfade waits for each song to end. soloist builds expire after 90 days,
download a new one when it says so.
Expand Down Expand Up @@ -101,7 +101,7 @@ and a macos dmg for apple silicon.

### Build requirements

- Qt 6.10 or newer: Qt Base, Qt Declarative and Qt Shader Tools, and on linux Qt WebSockets (for soloist)
- Qt 6.10 or newer: Qt Base, Qt Declarative, Qt Shader Tools and Qt WebSockets
- QtKeychain and QCoro 0.10 or newer, both built for Qt 6
- CMake 3.24 or newer, Ninja, and a C++20 compiler
- Rust (stable, from [rustup](https://rustup.rs))
Expand All @@ -118,7 +118,7 @@ build, drop that and run `ctest --test-dir build` if u want them.
u need [homebrew](https://brew.sh) and apple's command line tools (`xcode-select --install`, or full xcode). then:

```sh
brew install qtbase qtdeclarative qtshadertools qtkeychain qcoro6 cmake ninja
brew install qtbase qtdeclarative qtshadertools qtwebsockets qtkeychain qcoro6 cmake ninja
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source "$HOME/.cargo/env"

Expand Down Expand Up @@ -196,7 +196,7 @@ the tray. `-DSWIFTIFY_DESKTOP_INTEGRATION=OFF` turns those off.

**because most Windows users cant even use their own OS, i made a script that handles building so it's as simple as possible :)**

first install Qt 6.10+ with *Qt Shader Tools*, CMake and Ninja from the Qt online installer,
first install Qt 6.10+ with *Qt Shader Tools* and *Qt WebSockets*, CMake and Ninja from the Qt online installer,
Rust from [rustup](https://rustup.rs), and Git. choose either Qt for *MSVC 2022 64-bit*
with Visual Studio 2022 17.1+ (or Build Tools) and its *Desktop development with C++*
workload, or Qt for *MinGW 64-bit* with its matching MinGW toolchain.
Expand Down
86 changes: 79 additions & 7 deletions src/soloist/SoloistCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <swiftify_core.h>

#include <QCoroSignal>
#include <QCoreApplication>
#include <QDateTime>
#include <QDir>
#include <QFile>
Expand All @@ -25,6 +26,11 @@
#ifdef Q_OS_LINUX
#include <csignal>
#include <sys/prctl.h>
#elif defined(Q_OS_MACOS)
#include <csignal>
#include <libproc.h>
#elif defined(Q_OS_WIN)
#include <windows.h>
#endif

Q_LOGGING_CATEGORY(lcSoloist, "swiftify.soloist")
Expand Down Expand Up @@ -72,6 +78,25 @@ SoloistCore::SoloistCore(PlaybackCore *fallback, SoloistConfig config, QObject *
// soloist goes with a swiftify that crashes or is killed too. one left
// behind holds the data directory, and the next soloist will not start
m_process.setChildProcessModifier([] { ::prctl(PR_SET_PDEATHSIG, SIGTERM); });
#elif defined(Q_OS_WIN)
m_process.setCreateProcessArgumentsModifier([](QProcess::CreateProcessArguments *args) {
args->flags |= CREATE_NO_WINDOW;
});
m_job = ::CreateJobObjectW(nullptr, nullptr);
if (m_job) {
JOBOBJECT_EXTENDED_LIMIT_INFORMATION info{};
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
::SetInformationJobObject(m_job, JobObjectExtendedLimitInformation, &info, sizeof(info));
}
connect(&m_process, &QProcess::started, this, [this] {
if (!m_job) {
return;
}
if (HANDLE child = ::OpenProcess(PROCESS_SET_QUOTA | PROCESS_TERMINATE, FALSE, DWORD(m_process.processId()))) {
::AssignProcessToJobObject(m_job, child);
::CloseHandle(child);
}
});
#endif
connect(&m_process, &QProcess::readyRead, this, [this] {
const QString output = QString::fromUtf8(m_process.readAll());
Expand Down Expand Up @@ -144,12 +169,22 @@ SoloistCore::~SoloistCore()
m_socket.abort();
if (m_process.state() != QProcess::NotRunning) {
m_process.disconnect(this);
#ifdef Q_OS_WIN
m_process.kill();
m_process.waitForFinished(1000);
#else
m_process.terminate();
if (!m_process.waitForFinished(2000)) {
m_process.kill();
m_process.waitForFinished(1000);
}
#endif
}
#ifdef Q_OS_WIN
if (m_job) {
::CloseHandle(m_job);
}
#endif
}

std::optional<SoloistConfig> SoloistCore::detect()
Expand All @@ -165,9 +200,19 @@ std::optional<SoloistConfig> SoloistCore::detect()
}
if (config.program.isEmpty()) {
// a launcher's PATH often leaves out ~/.local/bin, where soloist's
// guide installs it without sudo
config.program = QStandardPaths::findExecutable(QStringLiteral("soloist"),
{QDir::homePath() + QStringLiteral("/.local/bin")});
// guide installs it without sudo, and homebrew's bin on macos
const QStringList extraPaths{
QCoreApplication::applicationDirPath(),
QDir::homePath() + QStringLiteral("/.local/bin"),
#ifdef Q_OS_MACOS
QStringLiteral("/opt/homebrew/bin"),
QStringLiteral("/usr/local/bin"),
#elif defined(Q_OS_WIN)
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + QStringLiteral("/soloist"),
QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/Programs/soloist"),
#endif
};
config.program = QStandardPaths::findExecutable(QStringLiteral("soloist"), extraPaths);
}
if (config.program.isEmpty()) {
qCInfo(lcSoloist) << "Soloist not found; playing through librespot";
Expand All @@ -176,10 +221,24 @@ std::optional<SoloistConfig> SoloistCore::detect()

config.apiKey = qEnvironmentVariable("SOLOIST_API_KEY").trimmed();
if (config.apiKey.isEmpty()) {
QFile file(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)
+ QStringLiteral("/soloist/api-key"));
if (file.open(QIODevice::ReadOnly)) {
config.apiKey = QString::fromUtf8(file.readAll()).trimmed();
const QString configDir = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation);
const QString dotConfig = QDir::homePath() + QStringLiteral("/.config");
const QStringList candidates{
configDir + QStringLiteral("/soloist/api-key"),
dotConfig + QStringLiteral("/soloist/api-key"),
#ifdef Q_OS_WIN
configDir + QStringLiteral("/soloist/api-key.txt"),
dotConfig + QStringLiteral("/soloist/api-key.txt"),
#endif
};
for (const QString &path : candidates) {
QFile file(path);
if (file.open(QIODevice::ReadOnly)) {
config.apiKey = QString::fromUtf8(file.readAll()).trimmed();
if (!config.apiKey.isEmpty()) {
break;
}
}
}
}
if (config.apiKey.isEmpty()) {
Expand All @@ -202,6 +261,19 @@ void SoloistCore::startDaemon()
m_failure.clear();
m_processOutput.clear();
QDir().mkpath(m_config.dataDirectory);
#ifdef Q_OS_MACOS
// macos has no PR_SET_PDEATHSIG; a soloist left behind by a killed
// swiftify holds the data directory until it is stopped
if (QFile pidFile(m_config.dataDirectory + QStringLiteral("/soloist.pid")); pidFile.open(QIODevice::ReadOnly)) {
bool ok = false;
const pid_t pid = pidFile.readAll().trimmed().toInt(&ok);
char path[PROC_PIDPATHINFO_MAXSIZE]{};
if (ok && pid > 1 && ::proc_pidpath(pid, path, sizeof(path)) > 0
&& QString::fromUtf8(path).endsWith(QLatin1StringView("/soloist"))) {
::kill(pid, SIGTERM);
}
}
#endif
#ifdef SWIFTIFY_DESKTOP_INTEGRATION
if (!m_route && qEnvironmentVariable("SWIFTIFY_SOLOIST_ROUTE") != QLatin1StringView("off")) {
// recorded at the rate swiftify's output plays at, so it is played
Expand Down
3 changes: 3 additions & 0 deletions src/soloist/SoloistCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ class SoloistCore : public PlaybackCore {
std::unique_ptr<SwiftifyLiveBuffer, void (*)(SwiftifyLiveBuffer *)> m_liveBuffer;
#ifdef SWIFTIFY_DESKTOP_INTEGRATION
std::unique_ptr<SoloistAudioRoute> m_route;
#endif
#ifdef Q_OS_WIN
void *m_job = nullptr;
#endif
/// soloist plays into m_route's sink
bool m_routed = false;
Expand Down
7 changes: 7 additions & 0 deletions src/system/windows/WindowsIntegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ struct WindowsIntegration::Native {
void WindowsIntegration::initializeProcess()
{
SetCurrentProcessExplicitAppUserModelID(L"dev.addenator.Swiftify.Qt");
const HANDLE err = GetStdHandle(STD_ERROR_HANDLE);
if ((err && err != INVALID_HANDLE_VALUE && GetFileType(err) != FILE_TYPE_UNKNOWN)
|| AttachConsole(ATTACH_PARENT_PROCESS)) {
if (!qEnvironmentVariableIsSet("QT_FORCE_STDERR_LOGGING")) {
qputenv("QT_FORCE_STDERR_LOGGING", "1");
}
}
}

void WindowsIntegration::setNativeTitleBar(QWindow *window, bool enabled)
Expand Down
2 changes: 1 addition & 1 deletion tests/check_windows_build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ try {
$buildRoot = Join-Path $fixture 'build'
$installPrefix = Join-Path $fixture 'installed'
New-FixtureFile "$qtPath\mkspecs\qconfig.pri" "QT_VERSION = 6.12.0`nQT_ARCH = x86_64`nQT_GCC_MAJOR_VERSION = 15`nQT_GCC_MINOR_VERSION = 1`nQT_GCC_PATCH_VERSION = 0"
foreach ($module in @('Qt6Core', 'Qt6Widgets', 'Qt6Quick', 'Qt6QuickControls2', 'Qt6ShaderTools')) {
foreach ($module in @('Qt6Core', 'Qt6Widgets', 'Qt6Quick', 'Qt6QuickControls2', 'Qt6ShaderTools', 'Qt6WebSockets')) {
New-FixtureFile "$qtPath\lib\cmake\$module\${module}Config.cmake"
}
foreach ($file in @('gcc.exe', 'g++.exe', 'libstdc++-6.dll', 'libgcc_s_seh-1.dll', 'libwinpthread-1.dll')) {
Expand Down
35 changes: 35 additions & 0 deletions tests/tst_soloist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,24 @@ private slots:
QVERIFY(m_dir->isValid());
// stands in for the soloist binary: writes the port the fake listens
// on where soloist would, and waits to be stopped
#ifdef Q_OS_WIN
m_program = m_dir->filePath(QStringLiteral("soloist.cmd"));
QFile script(m_program);
QVERIFY(script.open(QIODevice::WriteOnly));
script.write("@echo off\r\n"
":loop\r\n"
"if \"%~1\"==\"\" goto done\r\n"
"if \"%~1\"==\"--data-dir\" (\r\n"
" set \"d=%~2\"\r\n"
" shift\r\n"
")\r\n"
"shift\r\n"
"goto loop\r\n"
":done\r\n"
"<nul set /p=\"%FAKE_SOLOIST_PORT%\" > \"%d%\\ws.port\"\r\n"
"ping -n 600 127.0.0.1 >nul\r\n");
script.close();
#else
m_program = m_dir->filePath(QStringLiteral("soloist"));
QFile script(m_program);
QVERIFY(script.open(QIODevice::WriteOnly));
Expand All @@ -180,6 +198,7 @@ private slots:
"exec sleep 600\n");
script.close();
script.setPermissions(script.permissions() | QFile::ExeOwner);
#endif
m_soloist = std::make_unique<FakeSoloist>();
qputenv("FAKE_SOLOIST_PORT", QByteArray::number(m_soloist->port()));
// no sink in the real sound server for a test
Expand Down Expand Up @@ -417,6 +436,22 @@ private slots:
QVERIFY(m_fallback->log.contains(QStringLiteral("pause")));
}

void detectsSoloistAndApiKey()
{
qputenv("SWIFTIFY_SOLOIST", m_program.toUtf8());
qputenv("SOLOIST_API_KEY", "test-api-key");
qputenv("SWIFTIFY_PLAYBACK", "librespot");
QVERIFY(!SoloistCore::detect().has_value());

qunsetenv("SWIFTIFY_PLAYBACK");
const auto detected = SoloistCore::detect();
QVERIFY(detected.has_value());
QCOMPARE(detected->program, m_program);
QCOMPARE(detected->apiKey, QStringLiteral("test-api-key"));
qunsetenv("SWIFTIFY_SOLOIST");
qunsetenv("SOLOIST_API_KEY");
}

void settingVolumeSendsSetVolumeToSoloist()
{
QCoro::waitFor(m_core->playTrack(QStringLiteral("spotify:track:a")));
Expand Down
Loading