forked from munguua/ncmpcpp-ueberzug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathncmpcpp_cover_art.sh
More file actions
executable file
·55 lines (47 loc) · 1.7 KB
/
ncmpcpp_cover_art.sh
File metadata and controls
executable file
·55 lines (47 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
# Cover art script for ncmpcpp-ueberzug
# SETTINGS
music_library="$HOME/Music"
fallback_image="$HOME/.ncmpcpp/img/fallback.png"
# ==== 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
#}
main() {
find_cover_image >/dev/null 2>&1
}
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=$fallback_image
fi
}
main