aboutsummaryrefslogtreecommitdiffhomepage
path: root/X11/mpd/ncmpcpp
diff options
context:
space:
mode:
Diffstat (limited to 'X11/mpd/ncmpcpp')
-rw-r--r--X11/mpd/ncmpcpp/.gitignore1
-rw-r--r--X11/mpd/ncmpcpp/bindings46
-rw-r--r--X11/mpd/ncmpcpp/config95
-rw-r--r--X11/mpd/ncmpcpp/config.bak66
-rwxr-xr-xX11/mpd/ncmpcpp/cover.sh18
-rwxr-xr-xX11/mpd/ncmpcpp/cover_obs.sh21
-rw-r--r--X11/mpd/ncmpcpp/default_cover.pngbin0 -> 42425 bytes
-rwxr-xr-xX11/mpd/ncmpcpp/scripts/album-art248
-rw-r--r--X11/mpd/ncmpcpp/scripts/music.pngbin0 -> 113344 bytes
-rwxr-xr-xX11/mpd/ncmpcpp/scripts/ncmpcpp-art22
-rw-r--r--X11/mpd/ncmpcpp/tsession32
11 files changed, 549 insertions, 0 deletions
diff --git a/X11/mpd/ncmpcpp/.gitignore b/X11/mpd/ncmpcpp/.gitignore
new file mode 100644
index 0000000..397b4a7
--- /dev/null
+++ b/X11/mpd/ncmpcpp/.gitignore
@@ -0,0 +1 @@
*.log
diff --git a/X11/mpd/ncmpcpp/bindings b/X11/mpd/ncmpcpp/bindings
new file mode 100644
index 0000000..d035f7f
--- /dev/null
+++ b/X11/mpd/ncmpcpp/bindings
@@ -0,0 +1,46 @@
1# the t key isn't used and it's easier to press than /, so lets use it
2def_key "t"
3 find
4def_key "t"
5 find_item_forward
6
7def_key "+"
8 show_clock
9def_key "="
10 volume_up
11
12def_key "j"
13 scroll_down
14def_key "k"
15 scroll_up
16
17def_key "ctrl-u"
18 page_up
19def_key "ctrl-d"
20 page_down
21
22def_key "h"
23 previous_column
24def_key "l"
25 next_column
26
27def_key "."
28 show_lyrics
29
30def_key "n"
31 next_found_item
32def_key "N"
33 previous_found_item
34
35def_key "J"
36 move_sort_order_down
37def_key "K"
38 move_sort_order_up
39
40def_key "g"
41 move_home
42def_key "G"
43 move_end
44
45def_key "0"
46 replay_song
diff --git a/X11/mpd/ncmpcpp/config b/X11/mpd/ncmpcpp/config
new file mode 100644
index 0000000..e818015
--- /dev/null
+++ b/X11/mpd/ncmpcpp/config
@@ -0,0 +1,95 @@
1## Copyright (C) 2020-2021 Aditya Shakya <adi1090x@gmail.com>
2## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3
3
4### Directories ###
5ncmpcpp_directory = ~/.config/ncmpcpp/
6lyrics_directory = ~/.config/ncmpcpp/lyrics
7mpd_music_dir = ~/Music
8mpd_host = "localhost"
9mpd_port = "6600"
10mpd_crossfade_time = "2"
11
12### Script ###
13#execute_on_song_change="~/.config/ncmpcpp/scripts/album-art"
14#execute_on_song_change = "~/.ncmpcpp/cover_obs.sh"
15
16### Behaviour ###
17message_delay_time = 1
18autocenter_mode = "yes"
19centered_cursor = "yes"
20ignore_leading_the = "yes"
21playlist_disable_highlight_delay = 2
22allow_for_physical_item_deletion = "no"
23
24### Visualizer ###
25#visualizer_data_source = /tmp/mpd.fifo
26#visualizer_output_name = "mpd_visualizer"
27#visualizer_in_stereo = "yes"
28#visualizer_look = " "
29visualizer_type = "spectrum"
30
31### Appearance ###
32playlist_display_mode = "columns"
33colors_enabled = "yes"
34#user_interface = classic
35user_interface = alternative
36volume_color = "white"
37
38### Window ###
39song_window_title_format = "Music Player"
40#song_window_title_format = "{%a - }{%t}|{%f}"
41statusbar_visibility = "no"
42header_visibility = "no"
43titles_visibility = "yes"
44
45### Progress bar ###
46progressbar_look = "▂▂▂"
47progressbar_color = "black"
48progressbar_elapsed_color = "yellow"
49
50### Alternative UI ###
51alternative_ui_separator_color = "blue"
52alternative_header_first_line_format = $b$5$/b $b$8{%t}|{%f}$/b $/b
53alternative_header_second_line_format = {$b{$2 %a$9}{ - $7 %b$9}{ ($2%y$9)}}|{%D}
54
55### Song list ###
56song_status_format = "$7%t"
57song_list_format = " $4%t$9 $7$R%a$9 $2%l$9 "
58song_library_format = {{%a - %t} (%b)}|{%f}
59song_columns_list_format = "(35)[blue]{t} (30)[green]{a} (6)[cyan]{lr}"
60
61### Colors ###
62main_window_color = "blue"
63state_line_color = "black"
64current_item_prefix = "$(blue)$r"
65current_item_suffix = "$/r$(end)"
66current_item_inactive_column_prefix = red
67current_item_inactive_column_suffix = red
68now_playing_prefix = "$4 "
69selected_item_prefix = "* "
70
71color1 = "white"
72color2 = "red"
73
74### Layout ###
75startup_screen = visualizer
76startup_slave_screen = playlist
77startup_slave_screen_focus = yes
78locked_screen_width_part = 25
79
80### Misc ###
81default_place_to_search_in = "database"
82
83display_bitrate = "no"
84enable_window_title = "yes"
85follow_now_playing_lyrics = "yes"
86empty_tag_marker = ""
87
88cyclic_scrolling = "yes"
89header_text_scrolling = "yes"
90jump_to_now_playing_song_at_start = "yes"
91lines_scrolled = "2"
92
93system_encoding = "utf-8"
94regular_expressions = "extended"
95
diff --git a/X11/mpd/ncmpcpp/config.bak b/X11/mpd/ncmpcpp/config.bak
new file mode 100644
index 0000000..eb3fff6
--- /dev/null
+++ b/X11/mpd/ncmpcpp/config.bak
@@ -0,0 +1,66 @@
1## Copyright (C) 2020-2021 Aditya Shakya <adi1090x@gmail.com>
2## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3
3
4### Directories ###
5ncmpcpp_directory = ~/.ncmpcpp
6lyrics_directory = ~/.ncmpcpp/lyrics
7mpd_music_dir = ~/Music
8mpd_host = "localhost"
9mpd_port = "6600"
10mpd_crossfade_time = "2"
11
12### Script ###
13execute_on_song_change = "kunst --size 60x60 --silent"
14
15### Behaviour ###
16message_delay_time = 1
17autocenter_mode = "yes"
18centered_cursor = "yes"
19ignore_leading_the = "yes"
20playlist_disable_highlight_delay = 2
21allow_for_physical_item_deletion = "no"
22
23### Visualizer ###
24visualizer_data_source = /tmp/mpd.fifo
25visualizer_output_name = "mpd_visualizer"
26visualizer_in_stereo = "yes"
27visualizer_look = ●●
28visualizer_type = "ellipse"
29
30### Appearance ###
31playlist_display_mode = "columns"
32colors_enabled = "yes"
33#user_interface = classic
34user_interface = alternative
35volume_color = "white"
36
37### Window ###
38song_window_title_format = "{%a - }{%t}|{%f}"
39statusbar_visibility = "no"
40header_visibility = "no"
41titles_visibility = "no"
42
43### Progress bar ###
44progressbar_look = "▂▂▂"
45progressbar_color = "black"
46progressbar_elapsed_color = "yellow"
47
48### Alternative UI ###
49alternative_ui_separator_color = "black"
50alternative_header_first_line_format = $b$5$/b $b$8{%t}|{%f}$/b $/b
51alternative_header_second_line_format = {$b{$2 %a$9}{ - $7 %b$9}{ ($2%y$9)}}|{%D}
52
53### Song list ###
54song_status_format = "$7%t"
55song_list_format = " %t $R%a %l "
56song_library_format = {{%a - %t} (%b)}|{%f}
57song_columns_list_format = "(53)[white]{tr} (45)[blue]{a}"
58
59### Colors ###
60main_window_color = "blue"
61current_item_prefix = "$(blue)$r"
62current_item_suffix = "$/r$(end)"
63current_item_inactive_column_prefix = red
64current_item_inactive_column_suffix = red
65color1 = "white"
66color2 = "red"
diff --git a/X11/mpd/ncmpcpp/cover.sh b/X11/mpd/ncmpcpp/cover.sh
new file mode 100755
index 0000000..8fe8d4d
--- /dev/null
+++ b/X11/mpd/ncmpcpp/cover.sh
@@ -0,0 +1,18 @@
1#!/bin/bash
2
3source "`ueberzug library`"
4COVER="/tmp/album_cover.png"
5
6function add_cover {
7 ImageLayer::add [identifier]="img" [x]="2" [y]="1" [path]="$COVER"
8}
9
10ImageLayer 0< <(
11if [ ! -f "$COVER" ]; then
12 cp "$HOME/.ncmpcpp/default_cover.png" "$COVER"
13fi
14#rerender image when changed
15while inotifywait -q -q -e close_write "$COVER"; do
16 add_cover
17done
18)
diff --git a/X11/mpd/ncmpcpp/cover_obs.sh b/X11/mpd/ncmpcpp/cover_obs.sh
new file mode 100755
index 0000000..032bd08
--- /dev/null
+++ b/X11/mpd/ncmpcpp/cover_obs.sh
@@ -0,0 +1,21 @@
1#!/bin/bash
2
3COVER="/tmp/album_cover.png"
4COVER_SIZE="400"
5
6#path to current song
7file="$MUSIC_DIR/$(mpc --format %file% current)"
8album="${file%/*}"
9#search for cover image
10#use embedded image if present, otherwise take it from the current folder
11err=$(ffmpeg -loglevel 16 -y -i "$file" -an -vcodec copy $EMB_COVER 2>&1)
12if [ "$err" != "" ]; then
13 art=$(find "$album" -maxdepth 1 | grep -m 1 ".*\.\(jpg\|png\|gif\|bmp\)")
14else
15 art=$EMB_COVER
16fi
17if [ "$art" = "" ]; then
18 art="$HOME/.ncmpcpp/default_cover.png"
19fi
20#copy and resize image to destination
21ffmpeg -loglevel 0 -y -i "$art" -vf "scale=$COVER_SIZE:-1" "$COVER" \ No newline at end of file
diff --git a/X11/mpd/ncmpcpp/default_cover.png b/X11/mpd/ncmpcpp/default_cover.png
new file mode 100644
index 0000000..c02d40b
--- /dev/null
+++ b/X11/mpd/ncmpcpp/default_cover.png
Binary files differ
diff --git a/X11/mpd/ncmpcpp/scripts/album-art b/X11/mpd/ncmpcpp/scripts/album-art
new file mode 100755
index 0000000..d852f34
--- /dev/null
+++ b/X11/mpd/ncmpcpp/scripts/album-art
@@ -0,0 +1,248 @@
1#!/usr/bin/env bash
2
3## Copyright (C) 2020-2021 Aditya Shakya <adi1090x@gmail.com>
4## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3
5
6## Cover art script for ncmpcpp
7
8# SETTINGS
9music_library="$HOME/Music"
10padding_top=3
11padding_bottom=0
12padding_right=0
13max_width=40
14reserved_playlist_cols=31
15reserved_cols_in_percent="false"
16force_square="true"
17square_alignment="top"
18left_aligned="true"
19padding_left=0
20
21# Only set this if the geometries are wrong or ncmpcpp shouts at you to do it.
22# Visually select/highlight a character on your terminal, zoom in an image
23# editor and count how many pixels a character's width and height are.
24font_height=
25font_width=
26
27main() {
28 kill_previous_instances >/dev/null 2>&1
29 find_cover_image >/dev/null 2>&1
30 display_cover_image 2>/dev/null
31 dunstify -u low --replace=69 -i "$cover_path" "$(mpc current)"
32 detect_window_resizes >/dev/null 2>&1
33}
34
35# ==== Main functions =========================================================
36
37kill_previous_instances() {
38 script_name=$(basename "$0")
39 for pid in $(pidof -x "$script_name"); do
40 if [ "$pid" != $$ ]; then
41 kill -15 "$pid"
42 fi
43 done
44}
45
46find_cover_image() {
47
48 # First we check if the audio file has an embedded album art
49 ext="$(mpc --format %file% current | sed 's/^.*\.//')"
50 if [ "$ext" = "flac" ]; then
51 # since FFMPEG cannot export embedded FLAC art we use metaflac
52 metaflac --export-picture-to=/tmp/mpd_cover.jpg \
53 "$(mpc --format "$music_library"/%file% current)" &&
54 cover_path="/tmp/mpd_cover.jpg" && return
55 else
56 ffmpeg -y -i "$(mpc --format "$music_library"/%file% | head -n 1)" \
57 /tmp/mpd_cover.jpg &&
58 cover_path="/tmp/mpd_cover.jpg" && return
59 fi
60
61 # If no embedded art was found we look inside the music file's directory
62 album="$(mpc --format %album% current)"
63 file="$(mpc --format %file% current)"
64 album_dir="${file%/*}"
65 album_dir="$music_library/$album_dir"
66 found_covers="$(find "$album_dir" -type d -exec find {} -maxdepth 1 -type f \
67 -iregex ".*/.*\(${album}\|cover\|folder\|artwork\|front\).*[.]\\(jpe?g\|png\|gif\|bmp\)" \; )"
68 cover_path="$(echo "$found_covers" | head -n1)"
69 if [ -n "$cover_path" ]; then
70 return
71 fi
72
73 # If we still failed to find a cover image, we use the fallback
74 if [ -z "$cover_path" ]; then
75 cover_path="$HOME/.ncmpcpp/scripts/music.png"
76 fi
77}
78
79display_cover_image() {
80 compute_geometry
81
82 send_to_ueberzug \
83 action "add" \
84 identifier "mpd_cover" \
85 path "$cover_path" \
86 x "$ueber_left" \
87 y "$padding_top" \
88 height "$ueber_height" \
89 width "$ueber_width" \
90 synchronously_draw "True" \
91 scaler "forced_cover" \
92 scaling_position_x "0.5"
93}
94
95detect_window_resizes() {
96 {
97 trap 'display_cover_image' WINCH
98 while :; do sleep .1; done
99 } &
100}
101
102
103# ==== Helper functions =========================================================
104
105compute_geometry() {
106 unset LINES COLUMNS # Required in order for tput to work in a script
107 term_lines=$(tput lines)
108 term_cols=$(tput cols)
109 if [ -z "$font_height" ] || [ -z "$font_height" ]; then
110 guess_font_size
111 fi
112
113 ueber_height=$(( term_lines - padding_top - padding_bottom ))
114 # Because Ueberzug uses characters as a unit we must multiply
115 # the line count (height) by the font size ratio in order to
116 # obtain an equivalent width in column count
117 ueber_width=$(( ueber_height * font_height / font_width ))
118 ueber_left=$(( term_cols - ueber_width - padding_right ))
119
120 if [ "$left_aligned" = "true" ]; then
121 compute_geometry_left_aligned
122 else
123 compute_geometry_right_aligned
124 fi
125
126 apply_force_square_setting
127}
128
129compute_geometry_left_aligned() {
130 ueber_left=$padding_left
131 max_width_chars=$(( term_cols * max_width / 100 ))
132 if [ "$max_width" != 0 ] &&
133 [ $(( ueber_width + padding_right + padding_left )) -gt "$max_width_chars" ]; then
134 ueber_width=$(( max_width_chars - padding_left - padding_right ))
135 fi
136}
137
138compute_geometry_right_aligned() {
139 if [ "$reserved_cols_in_percent" = "true" ]; then
140 ueber_left_percent=$(printf "%.0f\n" $(calc "$ueber_left" / "$term_cols" '*' 100))
141 if [ "$ueber_left_percent" -lt "$reserved_playlist_cols" ]; then
142 ueber_left=$(( term_cols * reserved_playlist_cols / 100 ))
143 ueber_width=$(( term_cols - ueber_left - padding_right ))
144 fi
145 else
146 if [ "$ueber_left" -lt "$reserved_playlist_cols" ]; then
147 ueber_left=$reserved_playlist_cols
148 ueber_width=$(( term_cols - ueber_left - padding_right ))
149 fi
150
151 fi
152
153 if [ "$max_width" != 0 ] && [ "$ueber_width" -gt "$max_width" ]; then
154 ueber_width=$max_width
155 ueber_left=$(( term_cols - ueber_width - padding_right ))
156 fi
157}
158
159apply_force_square_setting() {
160 if [ $force_square = "true" ]; then
161 ueber_height=$(( ueber_width * font_width / font_height ))
162 case "$square_alignment" in
163 center)
164 area=$(( term_lines - padding_top - padding_bottom ))
165 padding_top=$(( padding_top + area / 2 - ueber_height / 2 ))
166 ;;
167 bottom)
168 padding_top=$(( term_lines - padding_bottom - ueber_height ))
169 ;;
170 *) ;;
171 esac
172 fi
173}
174
175guess_font_size() {
176 # A font width and height estimate is required to
177 # properly compute the cover width (in columns).
178 # We are reproducing the arithmetic used by Ueberzug
179 # to guess font size.
180 # https://github.com/seebye/ueberzug/blob/master/ueberzug/terminal.py#L24
181
182 guess_terminal_pixelsize
183
184 approx_font_width=$(( term_width / term_cols ))
185 approx_font_height=$(( term_height / term_lines ))
186
187 term_xpadding=$(( ( - approx_font_width * term_cols + term_width ) / 2 ))
188 term_ypadding=$(( ( - approx_font_height * term_lines + term_height ) / 2 ))
189
190 font_width=$(( (term_width - 2 * term_xpadding) / term_cols ))
191 font_height=$(( (term_height - 2 * term_ypadding) / term_lines ))
192}
193
194guess_terminal_pixelsize() {
195 # We are re-using the same Python snippet that
196 # Ueberzug utilizes to retrieve terminal window size.
197 # https://github.com/seebye/ueberzug/blob/master/ueberzug/terminal.py#L10
198
199 python <<END
200import sys, struct, fcntl, termios
201
202def get_geometry():
203 fd_pty = sys.stdout.fileno()
204 farg = struct.pack("HHHH", 0, 0, 0, 0)
205 fretint = fcntl.ioctl(fd_pty, termios.TIOCGWINSZ, farg)
206 rows, cols, xpixels, ypixels = struct.unpack("HHHH", fretint)
207 return "{} {}".format(xpixels, ypixels)
208
209output = get_geometry()
210f = open("/tmp/ncmpcpp_geometry.txt", "w")
211f.write(output)
212f.close()
213END
214
215 # ioctl doesn't work inside $() for some reason so we
216 # must use a temporary file
217 term_width=$(awk '{print $1}' /tmp/ncmpcpp_geometry.txt)
218 term_height=$(awk '{print $2}' /tmp/ncmpcpp_geometry.txt)
219 rm "/tmp/ncmpcpp_geometry.txt"
220
221 if ! is_font_size_successfully_computed; then
222 echo "Failed to guess font size, try setting it in `basename $0` settings"
223 fi
224}
225
226is_font_size_successfully_computed() {
227 [ -n "$term_height" ] && [ -n "$term_width" ] &&
228 [ "$term_height" != "0" ] && [ "$term_width" != "0" ]
229}
230
231
232calc() {
233 awk "BEGIN{print $*}"
234}
235
236send_to_ueberzug() {
237 old_IFS="$IFS"
238
239 # Ueberzug's "simple parser" uses tab-separated
240 # keys and values so we separate words with tabs
241 # and send the result to the wrapper's FIFO
242 IFS="$(printf "\t")"
243 echo "$*" > "$FIFO_UEBERZUG"
244
245 IFS=${old_IFS}
246}
247
248main
diff --git a/X11/mpd/ncmpcpp/scripts/music.png b/X11/mpd/ncmpcpp/scripts/music.png
new file mode 100644
index 0000000..3ded333
--- /dev/null
+++ b/X11/mpd/ncmpcpp/scripts/music.png
Binary files differ
diff --git a/X11/mpd/ncmpcpp/scripts/ncmpcpp-art b/X11/mpd/ncmpcpp/scripts/ncmpcpp-art
new file mode 100755
index 0000000..38d34c1
--- /dev/null
+++ b/X11/mpd/ncmpcpp/scripts/ncmpcpp-art
@@ -0,0 +1,22 @@
1#!/usr/bin/env bash
2
3## Copyright (C) 2020-2021 Aditya Shakya <adi1090x@gmail.com>
4## Everyone is permitted to copy and distribute copies of this file under GNU-GPL3
5
6export FIFO_UEBERZUG="/tmp/mpd-ueberzug-${PPID}"
7
8cleanup() {
9 rm "$FIFO_UEBERZUG" 2>/dev/null
10 rm /tmp/mpd_cover.jpg 2>/dev/null
11 pkill -P $$ 2>/dev/null
12 pkill album-art
13}
14
15pkill -P $$ 2>/dev/null
16rm "$FIFO_UEBERZUG" 2>/dev/null
17mkfifo "$FIFO_UEBERZUG" >/dev/null
18trap cleanup EXIT 2>/dev/null
19tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser simple >/dev/null 2>&1 &
20
21ncmpcpp -c ~/.ncmpcpp/config-art
22cleanup
diff --git a/X11/mpd/ncmpcpp/tsession b/X11/mpd/ncmpcpp/tsession
new file mode 100644
index 0000000..e34d4b8
--- /dev/null
+++ b/X11/mpd/ncmpcpp/tsession
@@ -0,0 +1,32 @@
1neww
2set -g status off
3
4#image pane; run cover script, disable text output and remove prompt
5send-keys "stty -echo" C-m
6send-keys "tput civis -- invisible" C-m
7send-keys "export PS1=''" C-m
8send-keys "clear" C-m
9send-keys "~/.ncmpcpp/cover.sh " C-m
10
11#catalog pane; run instance of ncmpcpp
12split-window -v
13select-pane -t 1
14send-keys "ncmpcpp --config='~/.ncmpcpp/catalog.conf'" C-m
15send-keys 1
16
17#visualizer pane; run instance of ncmpcpp in visualizer mode
18select-pane -t 0
19split-window -h
20send-keys "ncmpcpp --config='~/.ncmpcpp/visualizer.conf'" C-m
21send-keys 8
22send-keys u
23
24#resize image and visualizer pane to fit image
25resize-pane -t 0 -x 49 -y 23
26resize-pane -t 1 -y 23
27
28#hook for keeping the image pane size constant
29set-hook client-resized 'resize-pane -t 0 -x 49 -y 23'
30
31#focus on catalog pane
32select-pane -t 2 \ No newline at end of file