aboutsummaryrefslogtreecommitdiff
path: root/scripts/music/player.sh
blob: 270d02ff753424ce529d6ac4fb5930a8decba4cd (plain) (blame)
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
#!/usr/bin/env bash

MAX_CHARS=36

player() { playerctl --player=mopidy "$@"; }

# Get player state
#get_play_state() { player metadata --format '{{status}}' || echo 'Stopped'; }
get_play_state() {
  local state=$(mpc status | awk '/\[\w*\]/ {print $1}');
  case "$state" in
    '[playing]') echo "Playing" ;;
    '[paused]') echo "Paused" ;;
    *) echo "Stopped" ;;
  esac;
}

# Get title - artist (song label)
#get_label() { player metadata --format '{{title}} - {{artist}}' || echo '...'; }
get_label() {
  echo -n "$(mpc current | cut -c1-"$MAX_CHARS")";
  echo "...";
}

# Play/Pause toggle:
play_pause() {
  #player play-pause;
  mpc toggle;
  update-dwmblock music;
}

# Next/Prev
next() {
  #player next;
  mpc next;
  update-dwmblock music;
}
prev() {
  #player previous;
  mpc prev;
  update-dwmblock music;
}

notify() {
  update-dwmblock music;
}

case "$1" in
  play_pause|pp) play_pause ;;
  next|n) next ;;
  prev|p) prev ;;
  dump_metadata) get_metadata ;;
  get_label) get_label ;;
  get_play_state) get_play_state ;;
  notify) notify ;;
  *) echo "Learn how to use shit before you use them" ;;
esac