From 43075d27fea1a786ff04bbd8f0cc6ab84d5d7f88 Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Wed, 14 May 2025 19:57:30 +0200 Subject: [PATCH] music/librespot: Various tweaks * Use pulseaudio backend * Run as separate librespot user * Use linear volume mixer --- roles/music/defaults/main.yaml | 3 +++ roles/music/handlers/main.yaml | 6 +++--- roles/music/tasks/librespot.yaml | 19 ++++++++++++------- roles/music/templates/librespot.service | 9 ++++----- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/roles/music/defaults/main.yaml b/roles/music/defaults/main.yaml index fa95b47..5db2f4c 100644 --- a/roles/music/defaults/main.yaml +++ b/roles/music/defaults/main.yaml @@ -1,2 +1,5 @@ music_audio_user: audio +music_audio_group: audio +music_librespot_user: librespot + music_mqtt_mpd_volume: bitlair/music/space/volume diff --git a/roles/music/handlers/main.yaml b/roles/music/handlers/main.yaml index 2d77dbb..faf76f9 100644 --- a/roles/music/handlers/main.yaml +++ b/roles/music/handlers/main.yaml @@ -8,13 +8,13 @@ state: restarted daemon_reload: true -- name: Rebuild librespot +- name: rebuild librespot ansible.builtin.command: - cmd: /root/.cargo/bin/cargo build --release --features jackaudio-backend + cmd: /root/.cargo/bin/cargo build --release --features pulseaudio-backend args: chdir: /opt/librespot -- name: Restart librespot +- name: restart librespot ansible.builtin.systemd: name: librespot state: restarted diff --git a/roles/music/tasks/librespot.yaml b/roles/music/tasks/librespot.yaml index 2a8d19b..9d062ce 100644 --- a/roles/music/tasks/librespot.yaml +++ b/roles/music/tasks/librespot.yaml @@ -1,8 +1,11 @@ --- -- name: Install dependencies - ansible.builtin.apt: - name: libjack-jackd2-dev - state: present +- name: Create librespot user + user: + name: "{{ music_librespot_user }}" + system: true + home: /var/lib/librespot + groups: + - "{{ music_audio_group }}" - name: Clone librespot source ansible.builtin.git: @@ -11,8 +14,8 @@ dest: /opt/librespot accept_hostkey: yes notify: - - Rebuild librespot - - Restart librespot + - rebuild librespot + - restart librespot - name: Install service file ansible.builtin.template: @@ -21,7 +24,7 @@ owner: root group: root mode: 0644 - notify: Restart librespot + notify: restart librespot - name: Enable Librespot ansible.builtin.systemd: @@ -29,3 +32,5 @@ state: started enabled: true daemon_reload: true + +- meta: flush_handlers diff --git a/roles/music/templates/librespot.service b/roles/music/templates/librespot.service index 8d3b683..c6d8c4a 100644 --- a/roles/music/templates/librespot.service +++ b/roles/music/templates/librespot.service @@ -3,16 +3,15 @@ [Unit] Description=Spotify through Librespot After=network.target -Requires=jackd.service [Service] Type=simple Restart=always RestartSec=2s -ExecStart=/opt/librespot/target/release/librespot --name Trollibox --backend jackaudio -User={{ music_audio_user }} -Group={{ music_audio_user }} -AmbientCapabilities=CAP_IPC_LOCK,CAP_SYS_NICE +ExecStart=/opt/librespot/target/release/librespot --name Trollibox --backend pulseaudio --volume-ctrl linear +Environment="PULSE_SERVER=/tmp/pipewire-pulse-socket" +Environment="XDG_RUNTIME_DIR=/run/user/0" +User={{ music_librespot_user }} [Install] WantedBy=multi-user.target