diff contrib/xchat-audacious.py @ 2773:cd9311fed796 trunk

[svn] A few more xchat-audacious.py corrections: - Oops. "return None" --> "return xchat.EAT_ALL" - Compacted the code a bit more.
author deitarion
date Wed, 16 May 2007 00:24:43 -0700
parents 3c2786bbcf36
children 57363f3ded79
line wrap: on
line diff
--- a/contrib/xchat-audacious.py	Tue May 15 23:53:07 2007 -0700
+++ b/contrib/xchat-audacious.py	Wed May 16 00:24:43 2007 -0700
@@ -6,7 +6,7 @@
 #   - support org.freedesktop.MediaPlayer (MPRIS)?
 #
 # This script is in the public domain.
-#   $Id: xchat-audacious.py 4570 2007-05-16 06:53:07Z deitarion $
+#   $Id: xchat-audacious.py 4572 2007-05-16 07:24:43Z deitarion $
 #
 
 __module_name__ = "xchat-audacious"
@@ -29,13 +29,10 @@
 def command_np(word, word_eol, userdata):
 	aud = get_aud()
 	if not aud:
-		return None
+		return xchat.EAT_ALL
 
-	# this seems to be best, probably isn't!
-	length = "stream"
-	if aud.SongLength(aud.Position()) > 0:
-		length = "%d:%02d" % (aud.SongLength(aud.Position()) / 60,
-				      aud.SongLength(aud.Position()) % 60)
+	length = aud.SongLength(aud.Position())
+	length = (length > 0) and ("%d:%02d" % (length / 60, length % 60)) or "stream"
 
 	xchat.command("SAY [%s | %d:%02d/%s]" % (
 		aud.SongTitle(aud.Position()).encode("utf8"),
@@ -46,10 +43,7 @@
 
 def makeVoidCommand(cmd):
 	def callback(word, word_eol, userdata):
-		aud = get_aud()
-		if not aud:
-			return None
-		getattr(aud, cmd)()
+		getattr(get_aud(), cmd, lambda: None)()
 		return xchat.EAT_ALL
 	return callback
 
@@ -66,7 +60,7 @@
 
 	aud = get_aud()
 	if not aud:
-		return None
+		return xchat.EAT_ALL
 
 	xchat.command('DCC SEND %s "%s"' % (word[1], aud.SongFilename(aud.Position()).encode("utf8")))
 	return xchat.EAT_ALL
@@ -79,4 +73,4 @@
 xchat.hook_command("PLAY", command_play, help="Begins playback.")
 xchat.hook_command("SENDTRACK", command_send, help="Sends the currently playing track to a user.")
 
-print "xchat-audacious $Id: xchat-audacious.py 4570 2007-05-16 06:53:07Z deitarion $ loaded"
+print "xchat-audacious $Id: xchat-audacious.py 4572 2007-05-16 07:24:43Z deitarion $ loaded"