complete-computing-environment/mpd.org

209 lines
6.1 KiB
Org Mode

:PROPERTIES:
:ID: cce/mpd
:ROAM_REFS: https://www.musicpd.org/
:ROAM_ALIASES: MPD
:END:
#+TITLE: Listening to Music with MPD
#+ARROYO_MODULE_WANTS: cce/configure_packaging.org
#+AUTO_TANGLE: t
#+ARCOLOGY_KEY: cce/mpd
#+ARCOLOGY_ALLOW_CRAWL: t
[[id:c17ac008-acd9-4619-b324-7a56dfa635c5][Listening To]] [[id:3182614c-9122-4b01-ac3f-9f99e56bfdbd][Music]] is something I do a fair lot, and I remain displeased with the clients and interfaces at my disposal. Currently, I use [[https://www.musicpd.org/][MPD]], the Music Playing [[roam:Daemon]] which is a local server and a set of clients. On [[id:188c5167-4966-4a47-aaf1-9b7975192a5f][My Laptop]] where i have [[id:cce/emacs][Emacs]] I use a few different clients for different usecases, each one well works for different uses.
* MPD and Client Setup
#+ARROYO_HOME_MODULE: hm/mpd.nix
#+ARROYO_SYSTEM_EXCLUDE: waterboy
#+begin_src nix :tangle ~/arroyo-nix/hm/mpd.nix
{ config, pkgs, ... }:
{
services.mpd = {
enable = true;
musicDirectory = "/home/rrix/Music";
playlistDirectory = "/home/rrix/Music/playlists";
dataDir = "/home/rrix/Music";
network.listenAddress = "any";
extraConfig = ''
audio_output {
type "pulse"
name "My Pulse Output"
}
audio_output {
type "fifo"
name "my_fifo"
path "/tmp/mpd.fifo"
format "44100:16:2"
}
'';
};
services.mpd-discord-rpc = {
enable = true;
settings = {
hosts = [ "localhost:6600" "fontkeming:6600" ];
format = {
details = "$title";
state = "On $album by $artist";
};
};
};
services.mpdris2.enable = true;
programs.ncmpcpp = {
enable = true;
settings = {
visualizer_data_source = "/tmp/mpd.fifo";
visualizer_output_name = "my_fifo";
visualizer_in_stereo = "yes";
visualizer_type = "spectrum";
visualizer_look = "+|";
};
bindings = [
{ key = "j"; command = "scroll_down"; }
{ key = "k"; command = "scroll_up"; }
{ key = "J"; command = [ "select_item" "scroll_down" ]; }
{ key = "K"; command = [ "select_item" "scroll_up" ]; }
];
package = pkgs.ncmpcpp.override { visualizerSupport = true; };
};
home.packages = [ pkgs.mpc_cli pkgs.cantata ];
}
#+end_src
#+ARROYO_EMACS_MODULE: mpd
#+begin_src emacs-lisp :tangle cce/mpd.el
(use-package mingus)
#+end_src
* Mopidy
:PROPERTIES:
:ID: 20220421T151810.956143
:ROAM_REFS: https://mopidy.com/
:ROAM_ALIASES: "Mopidy is an extensible music server written in Python. "
:END:
Mopidy is an extensible music server written in Python. It's mostly designed to provide an easy hardware jukebox for Spotify or whatever crappy web service you want to use. I use it for Bandcamp, mainly. There is [[id:c75d20e6-8888-4c5a-ac97-5997e2f1c711][NixOS]] module support for it so I enable it in [[id:cce/my_nixos_configuration][My NixOS configuration]]. I want to use it for Youtube Music but this doesn't work reliably because they're fucking cops, though...
#+ARROYO_NIXOS_MODULE: nixos/mopidy.nix
#+ARROYO_SYSTEM_ROLE: endpoint
#+begin_src nix :tangle ~/arroyo-nix/nixos/mopidy.nix :noweb yes
{ pkgs, ...}:
let
mopidy-bandcamp = pkgs.callPackage ../pkgs/mopidy-bandcamp.nix {};
extPkgs = with pkgs; [
mopidy-bandcamp
mopidy-mpd
mopidy-youtube
];
in {
<<pipewire>>
<<firewallPorts>>
services.mopidy = {
enable = true;
extensionPackages = extPkgs;
configuration = ''
[core]
data_dir = /var/lib/mopidy
[audio]
# (ref:output)
output = pulsesink server=127.0.0.1
[bandcamp]
discover_tags = 8-bit, chiptune, idm, ambient, drone, experimental, dark ambient, glitch, cyberpunk, nu-jazz, gameboy, breakcore, edm, indie, indie-folk, indie-punk, indie rock, eugene, seattle, phoenix
identity = ${builtins.readFile /home/rrix/org/cce/bandcamp-cookie.txt}
[mpd]
enabled = true
port = 6601
hostname = ::
[youtube]
musicapi_cookie = ${builtins.readFile /home/rrix/org/cce/ytmusic-cookie.txt}
musicapi_enabled = true
'';
};
}
#+end_src
** Firewall ports for [[id:cce/mpd][MPD]] and Mopidy
#+begin_src nix :noweb-ref firewallPorts
networking.firewall.allowedTCPPorts = [ 6600 6601 ];
#+end_src
** PipeWire-Pulse TCP audio
:PROPERTIES:
:ID: 20220422T092352.846827
:END:
This configures [[id:cce/nixos-audio][PipeWire]] to listen for TCP connections so that the service-user which is set up for Mopidy is able to send audio to my speakers through a PipeWire run through [[id:cce/public_keys][My NixOS user]].
[[(output)]] above points Mopidy at it.
#+name: pipewire
#+begin_src nix
# Set up PipeWire to listen on TCP so that the mopidy user can send audio
services.pipewire.config.pipewire-pulse = {
"context.exec" = [
{
"args" = "load-module module-native-protocol-tcp";
"path" = "pactl";
}
];
"pulse.properties" = {
"server.address" = [
"unix:native"
"tcp:4713"
];
};
};
#+end_src
** Mopidy Bandcamp
:PROPERTIES:
:ID: 20220421T223829.601322
:END:
Here's a simple little PyPI package wrapper. This lets me play from my wishlist and discovery tags and my collection. I add stuff on my phone when I'm bored and decide whether I want to buy them later on.
#+begin_src nix :tangle ~/arroyo-nix/pkgs/mopidy-bandcamp.nix
{ python3Packages, mopidy, yt-dlp, lib, callPackage, ... }:
python3Packages.buildPythonApplication rec {
pname = "mopidy-bandcamp";
version = lib.pkgVersions.mopidy-bandcamp.version;
src = callPackage lib.pkgVersions.mopidy-bandcamp.src {};
propagatedBuildInputs = [
mopidy
];
pythonImportsCheck = [ "mopidy_bandcamp" ];
# has no tests
doCheck = false;
meta = with lib; {
description = "Mopidy extension for playing music from Bandcamp";
homepage = "https://github.com/impliedchaos/mopidy-bandcamp";
license = licenses.mit;
maintainers = [
{
email = "nixpkgs@whatthefuck.computer";
matrix = "@rrix:kickass.systems";
github = "rrix";
githubId = 138102;
name = "rrix";
}
];
};
}
#+end_src