Refactor MPD setup

This commit is contained in:
Sonny Bakker 2024-05-31 08:00:05 +02:00
parent d320ba7ee1
commit abcd234b3d
10 changed files with 149 additions and 23 deletions

View file

@ -69,3 +69,19 @@
loop: loop:
- { name: 'pipewire-pulse.socket', enabled: true } - { name: 'pipewire-pulse.socket', enabled: true }
- { name: 'pipewire-pulse.service', enabled: false } - { name: 'pipewire-pulse.service', enabled: false }
- name: stop mpd service
systemd:
name: mpd.service
state: stopped
enabled: false
scope: user
daemon-reload: true
- name: restart mpd socket
systemd:
name: mpd
state: restarted
enabled: true
scope: user
daemon-reload: true

View file

@ -1,14 +1,48 @@
# remote mpd server is used now - name: copy systemd configuration files
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- {
src: 'templates/mpd/service.j2',
dest: '{{ xdg_config_dir }}/systemd/user/mpd.service',
}
- {
src: 'templates/mpd/socket.j2',
dest: '{{ xdg_config_dir }}/systemd/user/mpd.socket',
}
notify:
- stop mpd service
- restart mpd socket
- name: check for mpd socket - name: create mpd files
stat: file:
path: '{{ xdg_config_dir }}/systemd/user/mpd.socket' path: '{{ item.path }}'
register: mpd_socket state: '{{ item.state }}'
loop:
- { path: '{{ mpd_configuration_dir }}', state: 'directory' }
- { path: '{{ ncmpc_configuration_dir }}', state: 'directory' }
- { path: '{{ mpd_configuration_dir }}/playlists', state: 'directory' }
- name: disable mpd socket - name: remove previous mpd files
systemd: file:
name: mpd.socket path: '{{ item.path }}'
state: stopped state: '{{ item.state }}'
enabled: no loop:
scope: user - { path: '{{ mpd_configuration_dir }}/log', state: 'absent' }
when: mpd_socket.stat.exists - { path: '{{ mpd_configuration_dir }}/database', state: 'absent' }
- { path: '{{ mpd_configuration_dir }}/sticker.sql', state: 'absent' }
- name: copy configuration files
template:
src: '{{ item.src }}'
dest: '{{ item.dest }}'
loop:
- { src: 'templates/mpd/mpd.conf.j2', dest: '{{ mpd_configuration_dir }}/mpd.conf' }
- { src: 'templates/mpd/ncmpc.j2', dest: '{{ ncmpc_configuration_dir }}/config' }
notify:
- stop mpd service
# Use mpc to control local mpd server.
# Use $ mpc add http://{{ mpd_remote_address }}:{{ mpd_remote_stream_port }}
# to add the HTTP stream to the playlist.
# Use nmcpc to control remote mpd server.

33
templates/mpd/mpd.conf.j2 Normal file
View file

@ -0,0 +1,33 @@
bind_to_address "{{ mpd_listen_address }}"
port "{{ mpd_listen_port }}"
playlist_directory "{{ mpd_configuration_dir }}/playlists"
database {
plugin "proxy"
host "{{ mpd_remote_address }}"
port "{{ mpd_remote_port }}"
}
audio_output {
type "pulse"
name "mpd"
replay_gain_handler "software"
mixer_type "hardware"
format "96000:24:1"
}
input {
enabled "no"
plugin "tidal"
}
input {
enabled "no"
plugin "qobuz"
}
decoder {
enabled "no"
plugin "wildmidi"
}

30
templates/mpd/ncmpc.j2 Normal file
View file

@ -0,0 +1,30 @@
##
## Configuration file for ncmpc (~/.config/ncmpc/config)
##
############## Connection ###################
## Connect to mpd running on a specified host
host = {{ mpd_remote_address }}
## Connect to mpd on the specified port.
port = {{ mpd_remote_port }}
############## Theme ###################
# Topbar
color title = 0/254
color line = 0/254
# Main window
color background = 15
color list = 239/15
color browser-directory = 239/15
color browser-playlist = 239/15
# Selected
color list-bold = 147/255
# Bottombar
color progressbar = 0
color status-state = 0/255
color status-song = 0/255
color status-time = 0/255

10
templates/mpd/service.j2 Normal file
View file

@ -0,0 +1,10 @@
[Unit]
Description=Music Player Daemon
Documentation=man:mpd(1) man:mpd.conf(5)
[Service]
Type=notify
ExecStart=/usr/bin/mpd --systemd
Restart=on-failure
RestartSec=15s
TimeoutStopSec=3

9
templates/mpd/socket.j2 Normal file
View file

@ -0,0 +1,9 @@
[Socket]
ListenStream=/run/user/1000/mpd.socket
ListenStream={{ mpd_listen_port }}
Backlog=5
KeepAlive=true
PassCredentials=true
[Install]
WantedBy=sockets.target

View file

@ -25,5 +25,3 @@ vpn_peers:
preshared_key_source_path: 'files/desktop/wireguard/preshared.psk', preshared_key_source_path: 'files/desktop/wireguard/preshared.psk',
preshared_key: !vault "$ANSIBLE_VAULT;1.1;AES256\r\n363333633336613939306632323163396239303739366135393232396134393266623939613534326238393638333137383235313039623264343932303038330a633934373638363966306533346235326234663464313963356238623064666430303030643533666536393662316237333463336462376366343335363131350a333135366239633765633136316133653535336661666461666365636233656165666635663037386666323931643265623233366133623237663734623661623661316436396465343866363266393565653237636136626536353630383263", preshared_key: !vault "$ANSIBLE_VAULT;1.1;AES256\r\n363333633336613939306632323163396239303739366135393232396134393266623939613534326238393638333137383235313039623264343932303038330a633934373638363966306533346235326234663464313963356238623064666430303030643533666536393662316237333463336462376366343335363131350a333135366239633765633136316133653535336661666461666365636233656165666635663037386666323931643265623233366133623237663734623661623661316436396465343866363266393565653237636136626536353630383263",
} }
pulse_port: 20808

View file

@ -27,5 +27,3 @@ vpn_peers:
preshared_key_source_path: 'files/laptop/wireguard/preshared.psk', preshared_key_source_path: 'files/laptop/wireguard/preshared.psk',
preshared_key: !vault "$ANSIBLE_VAULT;1.1;AES256\r\n376463366339376639373237363632363836653266353534343331333831646366373430333163383838313835613565646466653139666337626237313737300a333761383466626637336164363235643861643865653536663433373762343637303334613862373663626663616138333964386333373633643431326233370a386664366238633533356235613332373630353731306233623364623239353564313631373061393535336532393439343432373435336538666334666335633737633030386438616566376131646662316464333765636331343262663437", preshared_key: !vault "$ANSIBLE_VAULT;1.1;AES256\r\n376463366339376639373237363632363836653266353534343331333831646366373430333163383838313835613565646466653139666337626237313737300a333761383466626637336164363235643861643865653536663433373762343637303334613862373663626663616138333964386333373633643431326233370a386664366238633533356235613332373630353731306233623364623239353564313631373061393535336532393439343432373435336538666334666335633737633030386438616566376131646662316464333765636331343262663437",
} }
pulse_port: 20808

View file

@ -14,7 +14,7 @@ packages:
- postgresql - postgresql
- plasma-meta - plasma-meta
- syncthing - syncthing
- alacritty - alacritty # TODO: add configuration file
- tmux - tmux
- unrar - unrar
- vim - vim

View file

@ -1,11 +1,9 @@
mpd_listen_address: '127.0.0.1' mpd_listen_address: '127.0.0.1'
mpd_listen_port: '6600' mpd_listen_port: '6600'
mpd_database_address: '10.8.0.1' mpd_remote_address: '10.0.0.1'
mpd_database_port: '21000' mpd_remote_port: '21000'
mpd_remote_stream_port: '8000' # note that this is not used (yet)
mpd_configuration_dir: '{{ ansible_env.HOME }}/.config/mpd' mpd_configuration_dir: '{{ ansible_env.HOME }}/.config/mpd'
mpd_music_dir: '{{ ansible_env.HOME }}/music' ncmpc_configuration_dir: '{{ ansible_env.HOME }}/.config/ncmpc'
mpd_playlist_dir: '{{ mpd_configuration_dir }}/playlists'
mpd_state_path: '{{ mpd_configuration_dir }}/state'
mpd_sticker_path: '{{ mpd_configuration_dir }}/sticker.sql'