diff options
| author | Akshay Nair <phenax5@gmail.com> | 2025-07-03 11:11:53 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2025-07-03 11:11:53 +0530 |
| commit | 4dcde73af97061483a95b02c1480fc6917973aa6 (patch) | |
| tree | 0a497afd67027877e75bfed364be9db9e393e8bb | |
| parent | 7fe1a77a1c764eeb3d78153f89d434124189904f (diff) | |
| download | nixos-config-4dcde73af97061483a95b02c1480fc6917973aa6.tar.gz nixos-config-4dcde73af97061483a95b02c1480fc6917973aa6.zip | |
Switch back to mpd
| -rw-r--r-- | modules/music/client.home.nix | 91 | ||||
| -rw-r--r-- | modules/music/config.nix | 4 | ||||
| -rw-r--r-- | modules/music/default.home.nix | 136 | ||||
| -rw-r--r-- | modules/music/mpd.home.nix | 55 | ||||
| -rwxr-xr-x | scripts/commands/:music-web | 5 | ||||
| -rwxr-xr-x | scripts/music/player.sh | 2 | ||||
| -rwxr-xr-x | scripts/music/yt-music.sh | 59 |
7 files changed, 214 insertions, 138 deletions
diff --git a/modules/music/client.home.nix b/modules/music/client.home.nix new file mode 100644 index 0000000..aa106bb --- /dev/null +++ b/modules/music/client.home.nix @@ -0,0 +1,91 @@ +{ pkgs, ... }@moduleAttrs: +let + cfg = import ./config.nix moduleAttrs; +in +{ + home.packages = with pkgs; [ mpc_cli playerctl ]; + + programs.ncmpcpp = { + enable = true; + package = pkgs.ncmpcpp.override { visualizerSupport = true; }; + + bindings = with builtins; let + toBinding = s: let get = elemAt s; in { key = get 0; command = get 1; }; + in + map toBinding [ + [ "h" [ "previous_column" "master_screen" "jump_to_parent_directory" ] ] + [ "l" [ "next_column" "slave_screen" "enter_directory" ] ] + [ "k" "scroll_up" ] + [ "j" "scroll_down" ] + [ "g" "page_up" ] + [ "G" "page_down" ] + [ "d" "delete_playlist_items" ] + [ "n" "next_found_item" ] + [ "N" "previous_found_item" ] + [ "P" "show_playlist_editor" ] + [ "B" "show_browser" ] + [ "s" "show_search_engine" ] + [ "S" "show_search_engine" ] + [ "8" "show_visualizer" ] + [ "ctrl-s" "save_playlist" ] + [ "c" "clear_main_playlist" ] + [ "ctrl-l" "show_lyrics" ] + + [ "ctrl-k" "move_sort_order_up" ] + [ "ctrl-k" "move_selected_items_up" ] + [ "ctrl-j" "move_sort_order_down" ] + [ "ctrl-j" "move_selected_items_down" ] + ]; + + settings = { + user_interface = "alternative"; + playlist_display_mode = "columns"; + browser_display_mode = "columns"; + playlist_editor_display_mode = "classic"; + + empty_tag_color = "magenta"; + header_window_color = "magenta"; + volume_color = "cyan"; + state_line_color = "magenta"; + state_flags_color = "magenta:b"; + color1 = "white"; + color2 = "magenta"; + main_window_color = "white"; + progressbar_color = "black:b"; + progressbar_elapsed_color = "magenta:b"; + statusbar_color = "magenta"; + statusbar_time_color = "magenta:b"; + player_state_color = "magenta:b"; + alternative_ui_separator_color = "magenta"; + window_border_color = "magenta"; + active_window_border = "red"; + + progressbar_look = "=>-"; + now_playing_prefix = "$(blue)$b"; + now_playing_suffix = "$/b$(end)"; + current_item_prefix = "$(magenta)$r$b"; + current_item_suffix = "$/r$(end)$/b"; + current_item_inactive_column_prefix = "$(white)$r"; + current_item_inactive_column_suffix = "$/r$(end)"; + + media_library_primary_tag = "album_artist"; + media_library_albums_split_by_date = "no"; + startup_screen = "browser"; + ignore_leading_the = "yes"; + display_volume_level = "no"; + external_editor = "sensible-editor"; + use_console_editor = "yes"; + mouse_support = "yes"; + + visualizer_data_source = cfg.mpd.visualizer_fifo; + visualizer_output_name = cfg.mpd.visualizer_name; + visualizer_type = "spectrum"; + visualizer_in_stereo = "yes"; + visualizer_look = "●●"; + visualizer_color = "white, cyan, blue, magenta, red, red, black"; + visualizer_spectrum_smooth_look = "yes"; + visualizer_autoscale = "yes"; + visualizer_spectrum_dft_size = 3; + }; + }; +} diff --git a/modules/music/config.nix b/modules/music/config.nix index 3e02957..502b9eb 100644 --- a/modules/music/config.nix +++ b/modules/music/config.nix @@ -1,10 +1,12 @@ { config, ... } : { - mopidyHttpPort = 6680; + # mopidyHttpPort = 6680; mpd = { host = "127.0.0.1"; port = 6600; musicDir = "${config.home.homeDirectory}/Downloads/music"; playlistDir = "${config.home.homeDirectory}/Downloads/music/playlist"; + visualizer_name = "my_fifo"; + visualizer_fifo = "/tmp/mpd.fifo"; }; } diff --git a/modules/music/default.home.nix b/modules/music/default.home.nix index 10c91bc..ac4f9d6 100644 --- a/modules/music/default.home.nix +++ b/modules/music/default.home.nix @@ -1,133 +1,7 @@ -{ config, pkgs, ... }@moduleAttrs: -let - cfg = import ./config.nix moduleAttrs; -in +{ ... }: { - home.packages = with pkgs; [ mpc_cli playerctl ]; - - services.mopidy = { - enable = true; - extensionPackages = with pkgs; [ - mopidy-mpd - mopidy-mpris - mopidy-spotify - mopidy-iris - # mopidy-ytmusic - ]; - settings = { - core = { - restore_state = true; - }; - file = { - enabled = true; - media_dirs = [ cfg.mpd.musicDir ]; - show_dotfiles = false; - }; - m3u = { - enabled = true; - playlists_dir = cfg.mpd.playlistDir; - }; - audio = { - mixer = "software"; - output = "autoaudiosink"; - }; - mpris = { - enabled = true; - bus_type = "session"; - }; - mpd = { - enabled = true; - hostname = cfg.mpd.host; - port = cfg.mpd.port; - max_connections = 20; - connection_timeout = 60; - }; - http = { - enabled = true; - hostname = "0.0.0.0"; - port = cfg.mopidyHttpPort; - default_app = "iris"; - }; - softwaremixer.enabled = true; - stream.enabled = true; - spotify = (import ./spotify.private.nix) // { - timeout = 20000; - bitrate = 320; - cache_size = 32 * 1024; - }; - # ytmusic = { - # enabled = true; - # oauth_json = "~/.local/share/mopidy/ytmusic-auth.json"; - # }; - }; - }; - - programs.ncmpcpp = { - enable = true; - package = pkgs.ncmpcpp; - - bindings = with builtins; let - toBinding = s: let get = elemAt s; in { key = get 0; command = get 1; }; - in - map toBinding [ - [ "h" [ "previous_column" "master_screen" "jump_to_parent_directory" ] ] - [ "l" [ "next_column" "slave_screen" "enter_directory" ] ] - [ "k" "scroll_up" ] - [ "j" "scroll_down" ] - [ "g" "page_up" ] - [ "G" "page_down" ] - [ "d" "delete_playlist_items" ] - [ "n" "next_found_item" ] - [ "N" "previous_found_item" ] - [ "P" "show_playlist_editor" ] - [ "B" "show_browser" ] - [ "s" "show_search_engine" ] - [ "S" "show_search_engine" ] - [ "8" "show_visualizer" ] - [ "ctrl-s" "save_playlist" ] - [ "c" "clear_main_playlist" ] - [ "ctrl-l" "show_lyrics" ] - ]; - - settings = { - user_interface = "alternative"; - playlist_display_mode = "columns"; - browser_display_mode = "columns"; - playlist_editor_display_mode = "classic"; - - empty_tag_color = "magenta"; - header_window_color = "magenta"; - volume_color = "cyan"; - state_line_color = "magenta"; - state_flags_color = "magenta:b"; - color1 = "white"; - color2 = "magenta"; - main_window_color = "white"; - progressbar_color = "black:b"; - progressbar_elapsed_color = "magenta:b"; - statusbar_color = "magenta"; - statusbar_time_color = "magenta:b"; - player_state_color = "magenta:b"; - alternative_ui_separator_color = "magenta"; - window_border_color = "magenta"; - active_window_border = "red"; - - progressbar_look = "=>-"; - now_playing_prefix = "$(blue)$b"; - now_playing_suffix = "$/b$(end)"; - current_item_prefix = "$(magenta)$r$b"; - current_item_suffix = "$/r$(end)$/b"; - current_item_inactive_column_prefix = "$(white)$r"; - current_item_inactive_column_suffix = "$/r$(end)"; - - media_library_primary_tag = "album_artist"; - media_library_albums_split_by_date = "no"; - startup_screen = "browser"; - ignore_leading_the = "yes"; - display_volume_level = "no"; - external_editor = "sensible-editor"; - use_console_editor = "yes"; - mouse_support = "yes"; - }; - }; + imports = [ + ./mpd.home.nix + ./client.home.nix + ]; } diff --git a/modules/music/mpd.home.nix b/modules/music/mpd.home.nix new file mode 100644 index 0000000..3619786 --- /dev/null +++ b/modules/music/mpd.home.nix @@ -0,0 +1,55 @@ +{ ... }@moduleAttrs: +let + cfg = import ./config.nix moduleAttrs; +in +{ + services.mpd = { + enable = true; + musicDirectory = cfg.mpd.musicDir; + playlistDirectory = cfg.mpd.playlistDir; + network = { + listenAddress = cfg.mpd.host; + port = cfg.mpd.port; + }; + extraConfig = '' + user "imsohexy" + group "users" + restore_paused "yes" + metadata_to_use "artist,album,title,track,name,genre,date,composer,performer,disc" + auto_update "yes" + auto_update_depth "5" + follow_outside_symlinks "yes" + follow_inside_symlinks "yes" + + input { + plugin "curl" + } + + audio_output { + type "pipewire" + name "My PipeWire Device" + } + + audio_output { + type "fifo" + name "${cfg.mpd.visualizer_name}" + path "${cfg.mpd.visualizer_fifo}" + format "44100:16:2" + } + + filesystem_charset "UTF-8" + ''; + }; + + services.mpdris2 = { + # TODO: Hook to update dwmblock + enable = true; + notifications = false; + multimediaKeys = false; + mpd = { + host = cfg.mpd.host; + port = cfg.mpd.port; + musicDirectory = cfg.mpd.musicDir; + }; + }; +} diff --git a/scripts/commands/:music-web b/scripts/commands/:music-web deleted file mode 100755 index a14afc8..0000000 --- a/scripts/commands/:music-web +++ /dev/null @@ -1,5 +0,0 @@ -#!/usr/bin/env sh - -xdg-open 'http://localhost:6680' - -# spotify diff --git a/scripts/music/player.sh b/scripts/music/player.sh index 270d02f..2c89914 100755 --- a/scripts/music/player.sh +++ b/scripts/music/player.sh @@ -2,7 +2,7 @@ MAX_CHARS=36 -player() { playerctl --player=mopidy "$@"; } +player() { playerctl --player=mpd "$@"; } # Get player state #get_play_state() { player metadata --format '{{status}}' || echo 'Stopped'; } diff --git a/scripts/music/yt-music.sh b/scripts/music/yt-music.sh new file mode 100755 index 0000000..abf2fac --- /dev/null +++ b/scripts/music/yt-music.sh @@ -0,0 +1,59 @@ +#!/usr/bin/env sh + +set -e -o pipefail + +MUSIC_DIR="$HOME/Downloads/music" + +yt_download() { + local url="$1" + + if [ -z "$url" ]; then + url=$(echo -n "" | dmenu -p "YT music URL :: ") + fi + + if [ -z "$url" ]; then + echo "Nothing to download"; + exit 1; + fi + + if is_downloaded "$url" && [ ! "$FORCE" == "1" ]; then + echo "== already downloaded ==" + return 0; + fi + + yt-dlp -x --audio-format mp3 \ + --embed-metadata --embed-thumbnail \ + --parse-metadata "playlist_index:%(track_number)s" --add-metadata \ + -o "$MUSIC_DIR/%(artist|Others)s/%(album,playlist)s/%(playlist_index)02d - %(title)s.%(ext)s" \ + "$url" \ + && mark_as_done "$url" +} + +is_downloaded() { grep "$1" "$MUSIC_DIR/music.lock" > /dev/null 1>&2; } + +mark_as_done() { + echo "$1" >> "$MUSIC_DIR/music.lock" + sort -u "$MUSIC_DIR/music.lock" -o "$MUSIC_DIR/music.lock" +} + +library_data() { jq -r "$1" "$MUSIC_DIR/music.json"; } + +sync_library() { + library_data ".[].url" | while read url; do + yt_download "$url" || notify-send -u critical "Sync failed for $url" + done +} + +cmd="$1"; shift 1; +case "$cmd" in + yt) + yt_download "$@" \ + && notify-send "Music downloaded" \ + || notify-send -u critical "Music download failed" + ;; + sync) + sync_library && notify-send "Sync done" + ;; + *) echo "invalid cmd. (yt | sync)"; exit 1 ;; +esac + |
