[Tkabber-dev] r60 - trunk/plugins/now_playing

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Oct 1 02:07:41 MSD 2007


Author: kostix
Date: 2007-10-01 02:07:41 +0400 (Mon, 01 Oct 2007)
New Revision: 60

Modified:
   trunk/plugins/now_playing/mpd.tcl
Log:
now_playing/mpd.tcl:
 * Fixed two bugs in [mpd_cleanup].
 * [mpd_getval] redone to allow extracting of arbitrary key/value pair from MPD output.
 * Parsing of MPD responses greatly simplified by using new [mpd_getval] implementation.


Modified: trunk/plugins/now_playing/mpd.tcl
===================================================================
--- trunk/plugins/now_playing/mpd.tcl	2007-09-30 15:27:58 UTC (rev 59)
+++ trunk/plugins/now_playing/mpd.tcl	2007-09-30 22:07:41 UTC (rev 60)
@@ -218,7 +218,7 @@
 
 	if {[array exists mpd]} {
 		close $mpd(sock)
-		interp alias [mycmd $mpd(sock] {}
+		interp alias {} [mycmd $mpd(sock)] {}
 		unset mpd
 	}
 }
@@ -335,16 +335,10 @@
 	}
 
 	switch -glob -- $line {
-		state:*    {
-			lappend status state    [mpd_getval $line state]
-			$sock [mycmd mpd_yield_status $sock $status]
-		}
-		playlist:* {
-			lappend status playlist [mpd_getval $line playlist]
-			$sock [mycmd mpd_yield_status $sock $status]
-		}
+		state:*    -
+		playlist:* -
 		songid:*   {
-			lappend status songid   [mpd_getval $line songid]
+			mpd_getval $line status
 			$sock [mycmd mpd_yield_status $sock $status]
 		}
 		ACK*       {
@@ -428,24 +422,12 @@
 	}
 
 	switch -glob -- $line {
-		Artist:* {
-			lappend info artist [mpd_getval $line Artist]
-			$sock [mycmd mpd_yield_songinfo $sock $info]
-		}
-		Title:*  {
-			lappend info title  [mpd_getval $line Title]
-			$sock [mycmd mpd_yield_songinfo $sock $info]
-		}
-		Track:*  {
-			lappend info track  [mpd_getval $line Track]
-			$sock [mycmd mpd_yield_songinfo $sock $info]
-		}
-		Time:*   {
-			lappend info length [mpd_getval $line Time]
-			$sock [mycmd mpd_yield_songinfo $sock $info]
-		}
+		Artist:* -
+		Title:*  -
+		Track:*  -
+		Time:*   -
 		Album:*  {
-			lappend info source [mpd_getval $line Album]
+			mpd_getval $line info
 			$sock [mycmd mpd_yield_songinfo $sock $info]
 		}
 		ACK*     {
@@ -478,12 +460,27 @@
 	mpd_schedule_next_yield $sock
 }
 
-proc now_playing::mpd_getval {s key} {
-	set val [string trim [string range $s [string length $key:] end]]
-	puts "[info level 0] -> $val"
-	set val
+proc now_playing::split_at {s delim} {
+	set ix [string first $delim $s]
+	if {$ix < 0} {
+		list $s
+	} else {
+		list \
+			[string range $s 0 [expr {$ix - 1}]] \
+			[string range $s [expr {$ix + [string length $delim]}] end]
+	}
 }
 
+proc now_playing::mpd_getval {from toName} {
+	debugmsg tune [info level 0]
+
+	upvar 1 $toName to
+
+	foreach {key val} [split_at $from ": "] {
+		lappend to [string tolower $key] $val
+	}
+}
+
 #### Action:
 
 now_playing::mpd_connect



More information about the Tkabber-dev mailing list