mirror of
https://github.com/donovanglover/nix-config.git
synced 2024-11-28 19:23:48 +01:00
chore(nix): Clean up ncmpcpp module
This commit is contained in:
parent
ea4c8d16dd
commit
e82b8d40f9
@ -1,55 +1,48 @@
|
|||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
|
|
||||||
|
let
|
||||||
|
inherit (pkgs) mpc-cli;
|
||||||
|
|
||||||
|
musicDirectory = "/home/user/音楽";
|
||||||
|
changeScript = "ncmpcpp/on-song-change.sh";
|
||||||
|
fallbackImage = ../assets/wallpaper.png;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
home.packages = with pkgs; [ mpc-cli ];
|
home.packages = [ mpc-cli ];
|
||||||
|
|
||||||
services.mpd = {
|
services.mpd = {
|
||||||
enable = true;
|
enable = true;
|
||||||
musicDirectory = "/home/user/音楽";
|
inherit musicDirectory;
|
||||||
|
|
||||||
extraConfig = /* config */ ''
|
extraConfig = /* config */ ''
|
||||||
auto_update "yes"
|
auto_update "yes"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
xdg.configFile = {
|
xdg.configFile.${changeScript} = {
|
||||||
"ncmpcpp/on-song-change.sh" = {
|
|
||||||
executable = true;
|
executable = true;
|
||||||
text = /* bash */ ''
|
text = /* bash */ ''
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
music_dir="$HOME/音楽"
|
|
||||||
fallback_image="${../assets/wallpaper.png}"
|
|
||||||
|
|
||||||
main () {
|
|
||||||
find_cover 2>/dev/null
|
|
||||||
send 2>/dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
find_cover () {
|
find_cover () {
|
||||||
ext="$(mpc --format %file% current | sed 's/^.*\.//')"
|
ext="$(mpc --format %file% current | sed 's/^.*\.//')"
|
||||||
if [ "$ext" != "flac" ]; then
|
|
||||||
ffmpeg -y -i "$(mpc --format "$music_dir"/%file% | head -n 1)" \
|
if [ "$ext" == "flac" ]; then
|
||||||
/tmp/cover.jpg && cover_path="/tmp/cover.jpg" && return
|
|
||||||
else
|
|
||||||
# ffmpeg doesn't work for flacs
|
|
||||||
metaflac --export-picture-to=/tmp/cover.jpg \
|
metaflac --export-picture-to=/tmp/cover.jpg \
|
||||||
"$(mpc --format "$music_dir"/%file% current)" && cover_path="/tmp/cover.jpg" && return
|
"$(mpc --format "${musicDirectory}"/%file% current)" && cover_path="/tmp/cover.jpg" && return
|
||||||
|
else
|
||||||
|
ffmpeg -y -i "$(mpc --format "${musicDirectory}"/%file% | head -n 1)"} \
|
||||||
|
/tmp/cover.jpg && cover_path="/tmp/cover.jpg" && return
|
||||||
fi
|
fi
|
||||||
#without embedded images this is used as a fallback
|
|
||||||
file="$music_dir/$(mpc --format %file% current)"
|
file="${musicDirectory}/$(mpc --format %file% current)"
|
||||||
album="''${file%/*}"
|
album="''${file%/*}"
|
||||||
#search for cover image
|
|
||||||
cover_path=$(find "$album" -maxdepth 1 | grep -m 1 ".*\.\(jpg\|png\|gif\|bmp\)")
|
cover_path=$(find "$album" -maxdepth 1 | grep -m 1 ".*\.\(jpg\|png\|gif\|bmp\)")
|
||||||
}
|
}
|
||||||
|
|
||||||
send () {
|
find_cover && notify-send -i "''${cover_path:-${fallbackImage}}" "Now Playing" "$(mpc current)"
|
||||||
notify-send -i "''${cover_path:-$fallback_image}" "Now Playing" "$(mpc current)"
|
|
||||||
}
|
|
||||||
|
|
||||||
main
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
programs.ncmpcpp = {
|
programs.ncmpcpp = {
|
||||||
enable = true;
|
enable = true;
|
||||||
@ -91,7 +84,7 @@
|
|||||||
autocenter_mode = "yes";
|
autocenter_mode = "yes";
|
||||||
allow_for_physical_item_deletion = "no";
|
allow_for_physical_item_deletion = "no";
|
||||||
mouse_support = "no";
|
mouse_support = "no";
|
||||||
execute_on_song_change = "~/.config/ncmpcpp/on-song-change.sh";
|
execute_on_song_change = "~/.config/${changeScript}";
|
||||||
mpd_crossfade_time = 3;
|
mpd_crossfade_time = 3;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user