From e5f7080e094212d2db1c695a5cd8fcc47f4a5bdd Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Sat, 24 Sep 2022 22:04:27 +0800 Subject: Add ncmpcpp config --- mpd/ncmpcpp/bindings | 46 ++++++++ mpd/ncmpcpp/config | 93 +++++++++++++++ mpd/ncmpcpp/config.bak | 66 +++++++++++ mpd/ncmpcpp/error.log | 6 + mpd/ncmpcpp/scripts/album-art | 248 ++++++++++++++++++++++++++++++++++++++++ mpd/ncmpcpp/scripts/music.png | Bin 0 -> 113344 bytes mpd/ncmpcpp/scripts/ncmpcpp-art | 22 ++++ 7 files changed, 481 insertions(+) create mode 100644 mpd/ncmpcpp/bindings create mode 100644 mpd/ncmpcpp/config create mode 100644 mpd/ncmpcpp/config.bak create mode 100644 mpd/ncmpcpp/error.log create mode 100755 mpd/ncmpcpp/scripts/album-art create mode 100644 mpd/ncmpcpp/scripts/music.png create mode 100755 mpd/ncmpcpp/scripts/ncmpcpp-art (limited to 'mpd/ncmpcpp') diff --git a/mpd/ncmpcpp/bindings b/mpd/ncmpcpp/bindings new file mode 100644 index 0000000..d035f7f --- /dev/null +++ b/mpd/ncmpcpp/bindings @@ -0,0 +1,46 @@ +# the t key isn't used and it's easier to press than /, so lets use it +def_key "t" + find +def_key "t" + find_item_forward + +def_key "+" + show_clock +def_key "=" + volume_up + +def_key "j" + scroll_down +def_key "k" + scroll_up + +def_key "ctrl-u" + page_up +def_key "ctrl-d" + page_down + +def_key "h" + previous_column +def_key "l" + next_column + +def_key "." + show_lyrics + +def_key "n" + next_found_item +def_key "N" + previous_found_item + +def_key "J" + move_sort_order_down +def_key "K" + move_sort_order_up + +def_key "g" + move_home +def_key "G" + move_end + +def_key "0" + replay_song diff --git a/mpd/ncmpcpp/config b/mpd/ncmpcpp/config new file mode 100644 index 0000000..84e2519 --- /dev/null +++ b/mpd/ncmpcpp/config @@ -0,0 +1,93 @@ +## Copyright (C) 2020-2021 Aditya Shakya +## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3 + +### Directories ### +ncmpcpp_directory = ~/.config/ncmpcpp/ +lyrics_directory = ~/.config/ncmpcpp/lyrics +mpd_music_dir = ~/Music +mpd_host = "localhost" +mpd_port = "6600" +mpd_crossfade_time = "2" + +### Script ### +execute_on_song_change="~/.config/ncmpcpp/scripts/album-art" + +### Behaviour ### +message_delay_time = 1 +autocenter_mode = "yes" +centered_cursor = "yes" +ignore_leading_the = "yes" +playlist_disable_highlight_delay = 2 +allow_for_physical_item_deletion = "no" + +### Visualizer ### +visualizer_data_source = /tmp/mpd.fifo +visualizer_output_name = "mpd_visualizer" +visualizer_in_stereo = "yes" +visualizer_look = " " +visualizer_type = "ellipse" + +### Appearance ### +playlist_display_mode = "columns" +colors_enabled = "yes" +#user_interface = classic +user_interface = alternative +volume_color = "white" + +### Window ### +song_window_title_format = "Music Player" +#song_window_title_format = "{%a - }{%t}|{%f}" +statusbar_visibility = "no" +header_visibility = "no" +titles_visibility = "yes" + +### Progress bar ### +progressbar_look = "▂▂▂" +progressbar_color = "black" +progressbar_elapsed_color = "yellow" + +### Alternative UI ### +alternative_ui_separator_color = "blue" +alternative_header_first_line_format = $b$5$/b $b$8{%t}|{%f}$/b $/b +alternative_header_second_line_format = {$b{$2 %a$9}{ - $7 %b$9}{ ($2%y$9)}}|{%D} + +### Song list ### +song_status_format = "$7%t" +song_list_format = " $4%t$9 $7$R%a$9 $2%l$9 " +song_library_format = {{%a - %t} (%b)}|{%f} +song_columns_list_format = "(35)[blue]{t} (30)[green]{a} (6)[cyan]{lr}" + +### Colors ### +main_window_color = "blue" +state_line_color = "black" +current_item_prefix = "$(blue)$r" +current_item_suffix = "$/r$(end)" +current_item_inactive_column_prefix = red +current_item_inactive_column_suffix = red +now_playing_prefix = "$4 " +selected_item_prefix = "* " + +color1 = "white" +color2 = "red" + +### Layout ### +startup_screen = visualizer +startup_slave_screen = playlist +startup_slave_screen_focus = yes +locked_screen_width_part = 41 + +### Misc ### +default_place_to_search_in = "database" + +display_bitrate = "no" +enable_window_title = "yes" +follow_now_playing_lyrics = "yes" +empty_tag_marker = "" + +cyclic_scrolling = "yes" +header_text_scrolling = "yes" +jump_to_now_playing_song_at_start = "yes" +lines_scrolled = "2" + +system_encoding = "utf-8" +regular_expressions = "extended" diff --git a/mpd/ncmpcpp/config.bak b/mpd/ncmpcpp/config.bak new file mode 100644 index 0000000..eb3fff6 --- /dev/null +++ b/mpd/ncmpcpp/config.bak @@ -0,0 +1,66 @@ +## Copyright (C) 2020-2021 Aditya Shakya +## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3 + +### Directories ### +ncmpcpp_directory = ~/.ncmpcpp +lyrics_directory = ~/.ncmpcpp/lyrics +mpd_music_dir = ~/Music +mpd_host = "localhost" +mpd_port = "6600" +mpd_crossfade_time = "2" + +### Script ### +execute_on_song_change = "kunst --size 60x60 --silent" + +### Behaviour ### +message_delay_time = 1 +autocenter_mode = "yes" +centered_cursor = "yes" +ignore_leading_the = "yes" +playlist_disable_highlight_delay = 2 +allow_for_physical_item_deletion = "no" + +### Visualizer ### +visualizer_data_source = /tmp/mpd.fifo +visualizer_output_name = "mpd_visualizer" +visualizer_in_stereo = "yes" +visualizer_look = ●● +visualizer_type = "ellipse" + +### Appearance ### +playlist_display_mode = "columns" +colors_enabled = "yes" +#user_interface = classic +user_interface = alternative +volume_color = "white" + +### Window ### +song_window_title_format = "{%a - }{%t}|{%f}" +statusbar_visibility = "no" +header_visibility = "no" +titles_visibility = "no" + +### Progress bar ### +progressbar_look = "▂▂▂" +progressbar_color = "black" +progressbar_elapsed_color = "yellow" + +### Alternative UI ### +alternative_ui_separator_color = "black" +alternative_header_first_line_format = $b$5$/b $b$8{%t}|{%f}$/b $/b +alternative_header_second_line_format = {$b{$2 %a$9}{ - $7 %b$9}{ ($2%y$9)}}|{%D} + +### Song list ### +song_status_format = "$7%t" +song_list_format = " %t $R%a %l " +song_library_format = {{%a - %t} (%b)}|{%f} +song_columns_list_format = "(53)[white]{tr} (45)[blue]{a}" + +### Colors ### +main_window_color = "blue" +current_item_prefix = "$(blue)$r" +current_item_suffix = "$/r$(end)" +current_item_inactive_column_prefix = red +current_item_inactive_column_suffix = red +color1 = "white" +color2 = "red" diff --git a/mpd/ncmpcpp/error.log b/mpd/ncmpcpp/error.log new file mode 100644 index 0000000..15bdf09 --- /dev/null +++ b/mpd/ncmpcpp/error.log @@ -0,0 +1,6 @@ +writeCommonTags: couldn't write 'year' tag to 'Best of Kiasmos-F1gIsoIVQG8.opus' as it's not a positive integer +writeCommonTags: couldn't write 'track' tag to 'Best of Kiasmos-F1gIsoIVQG8.opus' as it's not a positive integer +writeCommonTags: couldn't write 'year' tag to 'Best of Kiasmos-F1gIsoIVQG8.opus' as it's not a positive integer +writeCommonTags: couldn't write 'track' tag to 'Best of Kiasmos-F1gIsoIVQG8.opus' as it's not a positive integer +writeCommonTags: couldn't write 'year' tag to 'Best of Kiasmos-F1gIsoIVQG8.opus' as it's not a positive integer +writeCommonTags: couldn't write 'track' tag to 'Best of Kiasmos-F1gIsoIVQG8.opus' as it's not a positive integer diff --git a/mpd/ncmpcpp/scripts/album-art b/mpd/ncmpcpp/scripts/album-art new file mode 100755 index 0000000..d852f34 --- /dev/null +++ b/mpd/ncmpcpp/scripts/album-art @@ -0,0 +1,248 @@ +#!/usr/bin/env bash + +## Copyright (C) 2020-2021 Aditya Shakya +## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3 + +## Cover art script for ncmpcpp + +# SETTINGS +music_library="$HOME/Music" +padding_top=3 +padding_bottom=0 +padding_right=0 +max_width=40 +reserved_playlist_cols=31 +reserved_cols_in_percent="false" +force_square="true" +square_alignment="top" +left_aligned="true" +padding_left=0 + +# Only set this if the geometries are wrong or ncmpcpp shouts at you to do it. +# Visually select/highlight a character on your terminal, zoom in an image +# editor and count how many pixels a character's width and height are. +font_height= +font_width= + +main() { + kill_previous_instances >/dev/null 2>&1 + find_cover_image >/dev/null 2>&1 + display_cover_image 2>/dev/null + dunstify -u low --replace=69 -i "$cover_path" "$(mpc current)" + detect_window_resizes >/dev/null 2>&1 +} + +# ==== Main functions ========================================================= + +kill_previous_instances() { + script_name=$(basename "$0") + for pid in $(pidof -x "$script_name"); do + if [ "$pid" != $$ ]; then + kill -15 "$pid" + fi + done +} + +find_cover_image() { + + # First we check if the audio file has an embedded album art + ext="$(mpc --format %file% current | sed 's/^.*\.//')" + if [ "$ext" = "flac" ]; then + # since FFMPEG cannot export embedded FLAC art we use metaflac + metaflac --export-picture-to=/tmp/mpd_cover.jpg \ + "$(mpc --format "$music_library"/%file% current)" && + cover_path="/tmp/mpd_cover.jpg" && return + else + ffmpeg -y -i "$(mpc --format "$music_library"/%file% | head -n 1)" \ + /tmp/mpd_cover.jpg && + cover_path="/tmp/mpd_cover.jpg" && return + fi + + # If no embedded art was found we look inside the music file's directory + album="$(mpc --format %album% current)" + file="$(mpc --format %file% current)" + album_dir="${file%/*}" + album_dir="$music_library/$album_dir" + found_covers="$(find "$album_dir" -type d -exec find {} -maxdepth 1 -type f \ + -iregex ".*/.*\(${album}\|cover\|folder\|artwork\|front\).*[.]\\(jpe?g\|png\|gif\|bmp\)" \; )" + cover_path="$(echo "$found_covers" | head -n1)" + if [ -n "$cover_path" ]; then + return + fi + + # If we still failed to find a cover image, we use the fallback + if [ -z "$cover_path" ]; then + cover_path="$HOME/.ncmpcpp/scripts/music.png" + fi +} + +display_cover_image() { + compute_geometry + + send_to_ueberzug \ + action "add" \ + identifier "mpd_cover" \ + path "$cover_path" \ + x "$ueber_left" \ + y "$padding_top" \ + height "$ueber_height" \ + width "$ueber_width" \ + synchronously_draw "True" \ + scaler "forced_cover" \ + scaling_position_x "0.5" +} + +detect_window_resizes() { + { + trap 'display_cover_image' WINCH + while :; do sleep .1; done + } & +} + + +# ==== Helper functions ========================================================= + +compute_geometry() { + unset LINES COLUMNS # Required in order for tput to work in a script + term_lines=$(tput lines) + term_cols=$(tput cols) + if [ -z "$font_height" ] || [ -z "$font_height" ]; then + guess_font_size + fi + + ueber_height=$(( term_lines - padding_top - padding_bottom )) + # Because Ueberzug uses characters as a unit we must multiply + # the line count (height) by the font size ratio in order to + # obtain an equivalent width in column count + ueber_width=$(( ueber_height * font_height / font_width )) + ueber_left=$(( term_cols - ueber_width - padding_right )) + + if [ "$left_aligned" = "true" ]; then + compute_geometry_left_aligned + else + compute_geometry_right_aligned + fi + + apply_force_square_setting +} + +compute_geometry_left_aligned() { + ueber_left=$padding_left + max_width_chars=$(( term_cols * max_width / 100 )) + if [ "$max_width" != 0 ] && + [ $(( ueber_width + padding_right + padding_left )) -gt "$max_width_chars" ]; then + ueber_width=$(( max_width_chars - padding_left - padding_right )) + fi +} + +compute_geometry_right_aligned() { + if [ "$reserved_cols_in_percent" = "true" ]; then + ueber_left_percent=$(printf "%.0f\n" $(calc "$ueber_left" / "$term_cols" '*' 100)) + if [ "$ueber_left_percent" -lt "$reserved_playlist_cols" ]; then + ueber_left=$(( term_cols * reserved_playlist_cols / 100 )) + ueber_width=$(( term_cols - ueber_left - padding_right )) + fi + else + if [ "$ueber_left" -lt "$reserved_playlist_cols" ]; then + ueber_left=$reserved_playlist_cols + ueber_width=$(( term_cols - ueber_left - padding_right )) + fi + + fi + + if [ "$max_width" != 0 ] && [ "$ueber_width" -gt "$max_width" ]; then + ueber_width=$max_width + ueber_left=$(( term_cols - ueber_width - padding_right )) + fi +} + +apply_force_square_setting() { + if [ $force_square = "true" ]; then + ueber_height=$(( ueber_width * font_width / font_height )) + case "$square_alignment" in + center) + area=$(( term_lines - padding_top - padding_bottom )) + padding_top=$(( padding_top + area / 2 - ueber_height / 2 )) + ;; + bottom) + padding_top=$(( term_lines - padding_bottom - ueber_height )) + ;; + *) ;; + esac + fi +} + +guess_font_size() { + # A font width and height estimate is required to + # properly compute the cover width (in columns). + # We are reproducing the arithmetic used by Ueberzug + # to guess font size. + # https://github.com/seebye/ueberzug/blob/master/ueberzug/terminal.py#L24 + + guess_terminal_pixelsize + + approx_font_width=$(( term_width / term_cols )) + approx_font_height=$(( term_height / term_lines )) + + term_xpadding=$(( ( - approx_font_width * term_cols + term_width ) / 2 )) + term_ypadding=$(( ( - approx_font_height * term_lines + term_height ) / 2 )) + + font_width=$(( (term_width - 2 * term_xpadding) / term_cols )) + font_height=$(( (term_height - 2 * term_ypadding) / term_lines )) +} + +guess_terminal_pixelsize() { + # We are re-using the same Python snippet that + # Ueberzug utilizes to retrieve terminal window size. + # https://github.com/seebye/ueberzug/blob/master/ueberzug/terminal.py#L10 + + python < "$FIFO_UEBERZUG" + + IFS=${old_IFS} +} + +main diff --git a/mpd/ncmpcpp/scripts/music.png b/mpd/ncmpcpp/scripts/music.png new file mode 100644 index 0000000..3ded333 Binary files /dev/null and b/mpd/ncmpcpp/scripts/music.png differ diff --git a/mpd/ncmpcpp/scripts/ncmpcpp-art b/mpd/ncmpcpp/scripts/ncmpcpp-art new file mode 100755 index 0000000..38d34c1 --- /dev/null +++ b/mpd/ncmpcpp/scripts/ncmpcpp-art @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +## Copyright (C) 2020-2021 Aditya Shakya +## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3 + +export FIFO_UEBERZUG="/tmp/mpd-ueberzug-${PPID}" + +cleanup() { + rm "$FIFO_UEBERZUG" 2>/dev/null + rm /tmp/mpd_cover.jpg 2>/dev/null + pkill -P $$ 2>/dev/null + pkill album-art +} + +pkill -P $$ 2>/dev/null +rm "$FIFO_UEBERZUG" 2>/dev/null +mkfifo "$FIFO_UEBERZUG" >/dev/null +trap cleanup EXIT 2>/dev/null +tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser simple >/dev/null 2>&1 & + +ncmpcpp -c ~/.ncmpcpp/config-art +cleanup -- cgit v1.2.3-70-g09d2