-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspafly
executable file
·70 lines (60 loc) · 1.69 KB
/
spafly
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
#!/bin/bash
osascript -e "tell application \"Spotify\" to activate";
sleep 2
if [[ $(osascript -e 'get volume settings') =~ volume:([0-9]*), ]]; then
ORIGINAL_VOL="$((${BASH_REMATCH[1]} / 10))"
fi
osascript -e "set Volume 1";
osascript -e "tell application \"Spotify\" to set sound volume to 80";
while [[ $# -gt 1 ]]; do
if [[ $1 = "-s" ]]; then
flag="true"
shift
elif [[ $1 = "-m" ]]; then
shift
osascript -e "tell application \"Spotify\" to set sound volume to $1";
shift
fi
done
# echo "$1 $flag";
SPOTIFY_PLAY_URI="";
if [[ "$1" =~ "http" ]]; then
if [[ "$1" =~ album/([a-zA-Z0-9]*) ]]; then
SPOTIFY_PLAY_URI=$( \
echo "spotify:album:${BASH_REMATCH[1]}" \
)
elif [[ "$1" =~ artist/([a-zA-Z0-9]*) ]]; then
SPOTIFY_PLAY_URI=$( \
echo "spotify:artist:${BASH_REMATCH[1]}" \
)
elif [[ "$1" =~ user/([a-zA-Z0-9]*)/playlist/([a-zA-Z0-9]*) ]]; then
SPOTIFY_PLAY_URI=$( \
echo "spotify:user:${BASH_REMATCH[1]}:playlist:${BASH_REMATCH[2]}" \
)
fi
else
if [[ "$1" =~ spotify:(album|user|artist) ]]; then
SPOTIFY_PLAY_URI=$1;
fi
fi
# echo $SPOTIFY_PLAY_URI;
if [ "$SPOTIFY_PLAY_URI" != "" ]; then
osascript -e "tell application \"Spotify\" to play track \"$SPOTIFY_PLAY_URI\"";
if [[ "$flag" = "true" ]]; then
# echo "1"
for (( i = 1; i < 10; i++ )); do
osascript -e "set Volume $i"
sleep 3
#statements
done
else
# echo "2"
osascript -e "set Volume 100"
fi
else
osascript -e "set Volume $ORIGINAL_VOL"
echo "Error: Please enter Spotift URL";
fi
# spotify:user:spotifytaiwan:playlist:47baPUxFPZOL3WtwD5iFJz
# spotify:album:7GG1AS1p66PcKMIK3uNQqg
# https://open.spotify.com/album/7GG1AS1p66PcKMIK3uNQqg