forked from seebye/fmui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpc.sh
70 lines (52 loc) · 2.02 KB
/
mpc.sh
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# This file is part of fzf mpd user interface (FMUI).
#
# FMUI is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Foobar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar. If not, see <http://www.gnu.org/licenses/>.
source "$PROJECT_ROOT/essentials.sh"
lazy_declare FMUI_MPC_SH || return
source "$PROJECT_ROOT/defaults.sh"
function Mpc::get_raw_song_info {
mpc | grep --perl-regexp ']\s*#'
}
function Mpc::get_song_progress {
Mpc::get_raw_song_info | \
grep --only-matching --perl-regexp '(?<=\()[0-9]+(?=%)'
}
function Mpc::get_song_duration {
local duration=`mpc current --format "%time%"`
local seconds=$((
$(( 10#`grep --only-matching --perl-regexp '([0-9]+)(?=:)' <<< "$duration"` * 60 )) +
10#`grep --only-matching --perl-regexp '(?<=:)([0-9]+)' <<< "$duration"` ))
echo -n "${seconds:-1}"
}
function Mpc::get_song_name {
mpc current --format "${song_format:-${DEFAULT_SONG_FORMAT}}"
}
function Mpc::get_options {
mpc | grep "volume" | sed 's|:\([^ ]\)|: \1|' | head --lines 1
}
function Mpc::get_playlist {
mpc playlist --format "%position%. ${song_list_format:-$DEFAULT_SONG_LIST_FORMAT}"
}
function Mpc::get_playlist_filename {
mpc playlist --format '%file%' | head --lines "$1" | tail --lines 1
}
function Mpc::update-queue {
# adds every song to the queue if it's not already part of it
diff --unchanged-group-format="" --new-group-format="%>" \
<(mpc playlist --format '%file%' | sort) <(mpc ls --format '%file%' | sort) | \
mpc add &>/dev/null
}
function Mpc::clear-queue {
mpc clear &>/dev/null
}