-
Notifications
You must be signed in to change notification settings - Fork 3
/
spotify-ad
executable file
·80 lines (73 loc) · 3.36 KB
/
spotify-ad
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
79
80
#!/usr/bin/env osascript
-- Show help subroutine
on showMSG()
set msg to "Use the following commands:\n"
set msg to msg & " mute - Mute all Ads\n"
set msg to msg & " swap - Swap ad with your local playlist instead of ads\n"
set msg to msg & " rm - Play your local playlist like there's no ads at all\n"
return msg
end showMSG
on run argv
if count of argv is equal to 0 then
return showMSG()
end if
set state to "Music"
set command to item 1 of argv
using terms from application "Spotify"
repeat while true
repeat 1 times
delay 0.5
if application "Spotify" is not running then exit repeat -- simulate continue
-- Set LastVolume
set lastVolume to 100
tell application "Spotify" to if sound volume is not 0 then set lastVolume to sound volume
-- Mute Mode
if command is equal to "mute" then
tell application "Spotify"
if ":ad:" is in spotify url of current track then
set sound volume to 0
else
set sound volume to lastVolume
end if
end tell
-- Swap Mode
else if command is equal to "swap" then -- TODO fix pausing issue
tell application "Spotify"
if ":ad:" is in spotify url of current track then
set sound volume to 0
Tell application "Music" to play
else
Tell application "Music" to pause
set sound volume to lastVolume
end if
end tell
-- Remove Mode
else if command is equal to "rm" then -- TODO do somthing here :)
tell application "Spotify"
if ":ad:" is in spotify url of current track and state is equal to "Music" then
set state to "Ad"
set sound volume to 0
Tell application "Music" to play
Tell application "Spotify" to play
else if state is equal to "Ad"
Tell application "Music"
if get finish of current track - player position is less than 1
set state to "Music"
Tell application "Spotify" to set sound volume to lastVolume
Tell application "Spotify" to play
Tell application "Music" to next track
Tell application "Music" to pause
else
Tell application "Spotify" to if ":ad:" is not in spotify url of current track then pause
end if
end Tell
end if
end tell
-- Show Help
else
return showMSG()
end if
end repeat
end repeat
end using terms from
end run