Samuel Shuert | 3f82866 | 2024-02-10 20:45:50 -0500 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # scripts by adi1090x |
| 3 | |
| 4 | ## Get data |
| 5 | STATUS="$(mpc status)" |
| 6 | COVER="/tmp/.music_cover.png" |
| 7 | MUSIC_DIR="$HOME/Music" |
| 8 | |
| 9 | ## Get status |
| 10 | get_status() { |
| 11 | if [[ $STATUS == *"[playing]"* ]]; then |
| 12 | echo "" |
| 13 | else |
| 14 | echo "奈" |
| 15 | fi |
| 16 | } |
| 17 | |
| 18 | ## Get song |
| 19 | get_song() { |
| 20 | song=`mpc -f %title% current` |
| 21 | if [[ -z "$song" ]]; then |
| 22 | echo "Offline" |
| 23 | else |
| 24 | echo "$song" |
| 25 | fi |
| 26 | } |
| 27 | |
| 28 | ## Get artist |
| 29 | get_artist() { |
| 30 | artist=`mpc -f %artist% current` |
| 31 | if [[ -z "$artist" ]]; then |
| 32 | echo "" |
| 33 | else |
| 34 | echo "$artist" |
| 35 | fi |
| 36 | } |
| 37 | |
| 38 | ## Get time |
| 39 | get_time() { |
| 40 | time=`mpc status | grep "%)" | awk '{print $4}' | tr -d '(%)'` |
| 41 | if [[ -z "$time" ]]; then |
| 42 | echo "0" |
| 43 | else |
| 44 | echo "$time" |
| 45 | fi |
| 46 | } |
| 47 | get_ctime() { |
| 48 | ctime=`mpc status | grep "#" | awk '{print $3}' | sed 's|/.*||g'` |
| 49 | if [[ -z "$ctime" ]]; then |
| 50 | echo "0:00" |
| 51 | else |
| 52 | echo "$ctime" |
| 53 | fi |
| 54 | } |
| 55 | get_ttime() { |
| 56 | ttime=`mpc -f %time% current` |
| 57 | if [[ -z "$ttime" ]]; then |
| 58 | echo "0:00" |
| 59 | else |
| 60 | echo "$ttime" |
| 61 | fi |
| 62 | } |
| 63 | |
| 64 | ## Get cover |
| 65 | get_cover() { |
| 66 | ffmpeg -i "${MUSIC_DIR}/$(mpc current -f %file%)" "${COVER}" -y &> /dev/null |
| 67 | STATUS=$? |
| 68 | |
| 69 | # Check if the file has a embbeded album art |
| 70 | if [ "$STATUS" -eq 0 ];then |
| 71 | echo "$COVER" |
| 72 | else |
| 73 | echo "images/music.png" |
| 74 | fi |
| 75 | } |
| 76 | |
| 77 | ## Execute accordingly |
| 78 | if [[ "$1" == "--song" ]]; then |
| 79 | get_song |
| 80 | elif [[ "$1" == "--artist" ]]; then |
| 81 | get_artist |
| 82 | elif [[ "$1" == "--status" ]]; then |
| 83 | get_status |
| 84 | elif [[ "$1" == "--time" ]]; then |
| 85 | get_time |
| 86 | elif [[ "$1" == "--ctime" ]]; then |
| 87 | get_ctime |
| 88 | elif [[ "$1" == "--ttime" ]]; then |
| 89 | get_ttime |
| 90 | elif [[ "$1" == "--cover" ]]; then |
| 91 | get_cover |
| 92 | elif [[ "$1" == "--toggle" ]]; then |
| 93 | mpc -q toggle |
| 94 | elif [[ "$1" == "--next" ]]; then |
| 95 | { mpc -q next; get_cover; } |
| 96 | elif [[ "$1" == "--prev" ]]; then |
| 97 | { mpc -q prev; get_cover; } |
| 98 | fi |