-
Notifications
You must be signed in to change notification settings - Fork 0
/
audd-notif
executable file
·78 lines (66 loc) · 2.6 KB
/
audd-notif
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
71
72
73
74
75
76
77
78
#!/bin/sh
# Small script to run audd, with notifications.
# Requires audd, jq, notify-send, dunstify (optional).
err_msg_exit() {
# Print an error to stderr and exit.
printf "%s\n" "$*" >&2
exit 1
}
type audd >/dev/null || err_msg_exit "'audd' not found."
type jq >/dev/null || err_msg_exit "'jq' not found."
TMP_DIR="/tmp/audd"
ARTWORK_FILE="$TMP_DIR/artwork.jpeg"
# set the source to the monitor of the current output sink
SOURCE="$(ffmpeg -sinks pulse 2>/dev/null | grep '\*' | cut -d' ' -f2).monitor"
if ! ffmpeg -sources pulse 2>/dev/null | grep -q "$SOURCE"; then
# exit if doesn't exist
echo "Source monitor \"$SOURCE\" not found." >&2
exit 1
fi
notify-send -i "audio-input-microphone" -t 5000 "AudD" "Recording audio for 5s."
RESPONSE="$(audd -t 5 \
-r "apple_music,spotify" \
-s "$SOURCE")"
if [ "$(echo "$RESPONSE" | jq -r ".status")" = "error" ]; then
notify-send -i "dialog-error" "AudD - API error" "$(echo "$RESPONSE" | jq -r ".error.error_message")"
exit 2
fi
if [ "$(echo "$RESPONSE" | jq -r ".status")" = "success" ] \
&& [ "$(echo "$RESPONSE" | jq -r ".result")" = "null" ]; then
notify-send -i "music" "AudD" "Failed to identify song."
exit
fi
ARTIST="$(echo "$RESPONSE" | jq -r ".result.artist")"
TITLE="$(echo "$RESPONSE" | jq -r ".result.title")"
# ALBUM="$(echo "$RESPONSE" | jq -r ".result.album")"
# apple music artwork
# ARTWORK_WIDTH="$(echo "$RESPONSE" | jq -r ".result.apple_music.artwork.width")"
# ARTWORK_HEIGHT="$(echo "$RESPONSE" | jq -r ".result.apple_music.artwork.height")"
# LINK_ARTWORK="$(echo "$RESPONSE" | jq -r ".result.apple_music.artwork.url")"
# LINK_ARTWORK="${LINK_ARTWORK/\{w\}/$ARTWORK_WIDTH}"
# LINK_ARTWORK="${LINK_ARTWORK/\{h\}/$ARTWORK_HEIGHT}"
# spotify artwork
LINK_ARTWORK="$(echo "$RESPONSE" | jq -r ".result.spotify.album.images[0].url")"
curl --silent "$LINK_ARTWORK" -o "$ARTWORK_FILE" >/dev/null 2>&1
if type dunstify >/dev/null; then
case "$(dunstify -i "$ARTWORK_FILE" \
--action="listn,listn" \
--action="apple music,apple music" \
--action="spotify,spotify" \
"$ARTIST" "$TITLE")" in
"apple music")
AM_LINK="$(echo "$RESPONSE" | jq -r ".result.apple_music.url")"
xdg-open "$AM_LINK"
;;
"spotify")
SPOT_LINK="$(echo "$RESPONSE" | jq -r ".result.spotify.external_urls.spotify")"
xdg-open "$SPOT_LINK"
;;
"listn")
LISTN_LINK="$(echo "$RESPONSE" | jq -r ".result.song_link")"
xdg-open "$LISTN_LINK"
;;
esac
else
notify-send -i "$ARTWORK_FILE" "$ARTIST" "$TITLE"
fi