Skip to content

Commit 5c72697

Browse files
committed
spotify_nowplaying.py 0.1.2: fix mixed spaces and tabs for indentation
1 parent e363d80 commit 5c72697

File tree

1 file changed

+58
-54
lines changed

1 file changed

+58
-54
lines changed

python/spotify_nowplaying.py

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
# (this script requires Spotify for Mac v0.5.1.98 or newer)
2020
#
2121
# History:
22+
#
23+
# 2022-01-25, Sébastien Helleu <[email protected]>
24+
# version 0.1.2: fix mixed spaces and tabs for indentation
25+
#
2226
# 2011-06-12, agreeabledragon <[email protected]>
2327
# version 0.1.1: rewrote it to use weechat.hook_process() to prevent it from blocking weechat as requested by Sébastien
2428
#
@@ -30,7 +34,7 @@
3034

3135
SCRIPT_NAME = "spotify_nowplaying"
3236
SCRIPT_AUTHOR = "agreeabledragon <[email protected]>"
33-
SCRIPT_VERSION = "0.1.1"
37+
SCRIPT_VERSION = "0.1.2"
3438
SCRIPT_LICENSE = "GPL3"
3539
SCRIPT_DESC = "Current song script for Spotify (v0.5.1.98 or newer) on OS X"
3640
SCRIPT_COMMAND = "spotify"
@@ -48,60 +52,60 @@
4852
"spotify_exec",
4953
"")
5054
else:
51-
w.prnt("", "WARNING: This now playing script for Spotify only works on OS X with Spotify version 0.5.1.98 (or newer)")
55+
w.prnt("", "WARNING: This now playing script for Spotify only works on OS X with Spotify version 0.5.1.98 (or newer)")
5256

5357
def spotify_process(data, command, rc, stdout, stderr):
54-
global SCRIPT_BUFFER, SCRIPT_PROCESS
55-
if stderr:
56-
w.prnt("", "There was an error executing the script - make sure you meet the requirements (OS X with Spotify v0.5.1.98 or newer)")
57-
SCRIPT_BUFFER = False
58-
SCRIPT_PROCESS = False
59-
return w.WEECHAT_RC_ERROR
60-
else:
61-
w.command(SCRIPT_BUFFER, stdout)
62-
SCRIPT_BUFFER = False
63-
SCRIPT_PROCESS = False
64-
return w.WEECHAT_RC_OK
58+
global SCRIPT_BUFFER, SCRIPT_PROCESS
59+
if stderr:
60+
w.prnt("", "There was an error executing the script - make sure you meet the requirements (OS X with Spotify v0.5.1.98 or newer)")
61+
SCRIPT_BUFFER = False
62+
SCRIPT_PROCESS = False
63+
return w.WEECHAT_RC_ERROR
64+
else:
65+
w.command(SCRIPT_BUFFER, stdout)
66+
SCRIPT_BUFFER = False
67+
SCRIPT_PROCESS = False
68+
return w.WEECHAT_RC_OK
6569

6670
def spotify_exec(data, buffer, args):
67-
global SCRIPT_TIMEOUT, SCRIPT_BUFFER, SCRIPT_PROCESS
68-
if SCRIPT_PROCESS:
69-
w.prnt("", "Please wait for the other command to finish")
70-
return w.WEECHAT_RC_ERROR
71-
else:
72-
script = """set AppleScript's text item delimiters to ASCII character 10
73-
set spotify_active to false
74-
set theString to \\"/me is not currently running Spotify.\\"
75-
76-
tell application \\"Finder\\"
77-
if (get name of every process) contains \\"Spotify\\" then set spotify_active to true
78-
end tell
79-
80-
if spotify_active then
81-
set got_track to false
82-
83-
tell application \\"Spotify\\"
84-
if player state is playing then
85-
set theTrack to name of the current track
86-
set theArtist to artist of the current track
87-
set theAlbum to album of the current track
88-
set isStarred to starred of the current track
89-
set got_track to true
90-
end if
91-
end tell
92-
93-
set theString to \\"/me is not playing anything in Spotify.\\"
94-
95-
if got_track then
96-
if isStarred then
97-
set theString to \\"/me is listening to one of my favorite tracks \\\\\\"\\" & theTrack & \\"\\\\\\" by \\" & theArtist & \\" (Album: \\" & theAlbum & \\")\\"
98-
else
99-
set theString to \\"/me is listening to \\\\\\"\\" & theTrack & \\"\\\\\\" by \\" & theArtist & \\" (Album: \\" & theAlbum & \\")\\"
100-
end if
101-
end if
102-
end if
103-
104-
return theString"""
105-
SCRIPT_BUFFER = buffer;
106-
SCRIPT_PROCESS = w.hook_process('arch -i386 osascript -e "' + script + '"', SCRIPT_TIMEOUT, "spotify_process", "")
107-
return w.WEECHAT_RC_OK
71+
global SCRIPT_TIMEOUT, SCRIPT_BUFFER, SCRIPT_PROCESS
72+
if SCRIPT_PROCESS:
73+
w.prnt("", "Please wait for the other command to finish")
74+
return w.WEECHAT_RC_ERROR
75+
else:
76+
script = """set AppleScript's text item delimiters to ASCII character 10
77+
set spotify_active to false
78+
set theString to \\"/me is not currently running Spotify.\\"
79+
80+
tell application \\"Finder\\"
81+
if (get name of every process) contains \\"Spotify\\" then set spotify_active to true
82+
end tell
83+
84+
if spotify_active then
85+
set got_track to false
86+
87+
tell application \\"Spotify\\"
88+
if player state is playing then
89+
set theTrack to name of the current track
90+
set theArtist to artist of the current track
91+
set theAlbum to album of the current track
92+
set isStarred to starred of the current track
93+
set got_track to true
94+
end if
95+
end tell
96+
97+
set theString to \\"/me is not playing anything in Spotify.\\"
98+
99+
if got_track then
100+
if isStarred then
101+
set theString to \\"/me is listening to one of my favorite tracks \\\\\\"\\" & theTrack & \\"\\\\\\" by \\" & theArtist & \\" (Album: \\" & theAlbum & \\")\\"
102+
else
103+
set theString to \\"/me is listening to \\\\\\"\\" & theTrack & \\"\\\\\\" by \\" & theArtist & \\" (Album: \\" & theAlbum & \\")\\"
104+
end if
105+
end if
106+
end if
107+
108+
return theString"""
109+
SCRIPT_BUFFER = buffer
110+
SCRIPT_PROCESS = w.hook_process('arch -i386 osascript -e "' + script + '"', SCRIPT_TIMEOUT, "spotify_process", "")
111+
return w.WEECHAT_RC_OK

0 commit comments

Comments
 (0)