Skip to content

Commit 07f20bc

Browse files
committed
clemenshow.py 1.1: make script compatible with Python 3
1 parent f7faf04 commit 07f20bc

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

python/clemenshow.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"""
99
SCRIPT_NAME = "clemenshow"
1010
SCRIPT_AUTHOR = "Leigh MacDonald <[email protected]>"
11-
SCRIPT_VERSION = "1.0"
11+
SCRIPT_VERSION = "1.1"
1212
SCRIPT_LICENSE = "GPL3"
1313
SCRIPT_DESC = "Clementine now playing script"
1414
SCRIPT_COMMAND = "np"
@@ -18,22 +18,24 @@
1818

1919
try:
2020
import weechat
21+
IMPORT_OK = True
2122
except ImportError:
22-
print "This script must be run under WeeChat 3.4 or better."
23-
print "Get WeeChat now at: http://www.weechat.org/"
24-
sys.exit()
23+
print("This script must be run under WeeChat 3.4 or better.")
24+
print("Get WeeChat now at: https://weechat.org/")
25+
IMPORT_OK = False
26+
2527
try:
2628
from dbus import Bus, DBusException
2729
except ImportError:
28-
print "Please install python-dbus"
29-
sys.exit()
30+
print("Please install python-dbus")
31+
IMPORT_OK = False
3032

31-
bus = Bus(Bus.TYPE_SESSION)
3233

3334
def get_type(path):
3435
p = path.split(".")
3536
return p[len(p)-1].upper()
3637

38+
3739
#@DebugArgs
3840
def np_command(data, buffer, args):
3941
try:
@@ -46,11 +48,14 @@ def np_command(data, buffer, args):
4648
int(f['audio-samplerate'])))
4749
except DBusException:
4850
weechat.prnt(buffer, "Doesnt look like clementine is running, if it is make sure dbus is running")
49-
except Exception, err:
51+
except Exception as err:
5052
weechat.prnt(buffer, err)
5153
finally:
5254
return weechat.WEECHAT_RC_OK
5355

54-
weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "on_shutdown", "")
55-
weechat.hook_command(SCRIPT_COMMAND, SCRIPT_DESC, "", "", "", "np_command", "")
56-
weechat.prnt("", "%s | %s" % (SCRIPT_NAME, SCRIPT_AUTHOR))
56+
57+
if __name__ == "__main__" and IMPORT_OK:
58+
weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", "")
59+
weechat.hook_command(SCRIPT_COMMAND, SCRIPT_DESC, "", "", "", "np_command", "")
60+
weechat.prnt("", "%s | %s" % (SCRIPT_NAME, SCRIPT_AUTHOR))
61+
bus = Bus(Bus.TYPE_SESSION)

0 commit comments

Comments
 (0)