diff --git a/handlers.yml b/handlers.yml index dccba92..ab48d05 100644 --- a/handlers.yml +++ b/handlers.yml @@ -69,3 +69,19 @@ loop: - { name: 'pipewire-pulse.socket', enabled: true } - { 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 diff --git a/tasks/mpd.yml b/tasks/mpd.yml index 53217f3..6d4f556 100644 --- a/tasks/mpd.yml +++ b/tasks/mpd.yml @@ -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 - stat: - path: '{{ xdg_config_dir }}/systemd/user/mpd.socket' - register: mpd_socket +- name: create mpd files + file: + path: '{{ item.path }}' + 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 - systemd: - name: mpd.socket - state: stopped - enabled: no - scope: user - when: mpd_socket.stat.exists +- name: remove previous mpd files + file: + path: '{{ item.path }}' + state: '{{ item.state }}' + loop: + - { path: '{{ mpd_configuration_dir }}/log', state: 'absent' } + - { 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. diff --git a/templates/mpd/mpd.conf.j2 b/templates/mpd/mpd.conf.j2 new file mode 100644 index 0000000..8f9b5a8 --- /dev/null +++ b/templates/mpd/mpd.conf.j2 @@ -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" +} diff --git a/templates/mpd/ncmpc.j2 b/templates/mpd/ncmpc.j2 new file mode 100644 index 0000000..449f49e --- /dev/null +++ b/templates/mpd/ncmpc.j2 @@ -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 diff --git a/templates/mpd/service.j2 b/templates/mpd/service.j2 new file mode 100644 index 0000000..985c13f --- /dev/null +++ b/templates/mpd/service.j2 @@ -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 diff --git a/templates/mpd/socket.j2 b/templates/mpd/socket.j2 new file mode 100644 index 0000000..d479add --- /dev/null +++ b/templates/mpd/socket.j2 @@ -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 diff --git a/vars/desktop.yml b/vars/desktop.yml index 7893c37..5ef0d4a 100644 --- a/vars/desktop.yml +++ b/vars/desktop.yml @@ -25,5 +25,3 @@ vpn_peers: preshared_key_source_path: 'files/desktop/wireguard/preshared.psk', preshared_key: !vault "$ANSIBLE_VAULT;1.1;AES256\r\n363333633336613939306632323163396239303739366135393232396134393266623939613534326238393638333137383235313039623264343932303038330a633934373638363966306533346235326234663464313963356238623064666430303030643533666536393662316237333463336462376366343335363131350a333135366239633765633136316133653535336661666461666365636233656165666635663037386666323931643265623233366133623237663734623661623661316436396465343866363266393565653237636136626536353630383263", } - -pulse_port: 20808 diff --git a/vars/laptop.yml b/vars/laptop.yml index 68d8975..3bf6e7d 100644 --- a/vars/laptop.yml +++ b/vars/laptop.yml @@ -27,5 +27,3 @@ vpn_peers: preshared_key_source_path: 'files/laptop/wireguard/preshared.psk', preshared_key: !vault "$ANSIBLE_VAULT;1.1;AES256\r\n376463366339376639373237363632363836653266353534343331333831646366373430333163383838313835613565646466653139666337626237313737300a333761383466626637336164363235643861643865653536663433373762343637303334613862373663626663616138333964386333373633643431326233370a386664366238633533356235613332373630353731306233623364623239353564313631373061393535336532393439343432373435336538666334666335633737633030386438616566376131646662316464333765636331343262663437", } - -pulse_port: 20808 diff --git a/vars/main.yml b/vars/main.yml index 547dbde..bdd9a05 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -14,7 +14,7 @@ packages: - postgresql - plasma-meta - syncthing - - alacritty + - alacritty # TODO: add configuration file - tmux - unrar - vim diff --git a/vars/mpd.yml b/vars/mpd.yml index 7247e78..8e2e696 100644 --- a/vars/mpd.yml +++ b/vars/mpd.yml @@ -1,11 +1,9 @@ mpd_listen_address: '127.0.0.1' mpd_listen_port: '6600' -mpd_database_address: '10.8.0.1' -mpd_database_port: '21000' +mpd_remote_address: '10.0.0.1' +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_music_dir: '{{ ansible_env.HOME }}/music' -mpd_playlist_dir: '{{ mpd_configuration_dir }}/playlists' -mpd_state_path: '{{ mpd_configuration_dir }}/state' -mpd_sticker_path: '{{ mpd_configuration_dir }}/sticker.sql' +ncmpc_configuration_dir: '{{ ansible_env.HOME }}/.config/ncmpc'