[Tkabber-dev] r44 - trunk/plugins/np_file

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Sep 19 20:40:18 MSD 2007


Author: kostix
Date: 2007-09-19 20:40:17 +0400 (Wed, 19 Sep 2007)
New Revision: 44

Modified:
   trunk/plugins/np_file/README
   trunk/plugins/np_file/np_file.tcl
Log:
np_file/np_file.tcl: fixed support for Foobar2000 that was broken when
  adding support for Quod Libet. Introduced [warn] procedure for dealing
  with non-critical errors; it has "throttling" mechanism to not
  flood stderr with repeatable warnings.
np_file/README: misc whitespace fixes.


Modified: trunk/plugins/np_file/README
===================================================================
--- trunk/plugins/np_file/README	2007-09-19 00:45:52 UTC (rev 43)
+++ trunk/plugins/np_file/README	2007-09-19 16:40:17 UTC (rev 44)
@@ -12,10 +12,10 @@
 
 Windows:
 
-* Foobar2000 [1] via its "foobar_np_simple" plugin [2].
+* Foobar2000 [1] via its "foo_np_simple" plugin [2].
 
 
-III. Confuguration of "foobar_np_simple".
+III. Confuguration of "foo_np_simple".
 
 1. "Filename":
 
@@ -34,7 +34,7 @@
 3. "Formatting string":
 
 $if($and(%isplaying%,$not(%ispaused%)),
-PLAYING $crlf()
+PLAYING$crlf()
 ARTIST$tab()%artist%$crlf()
 LENGTH$tab()%length_seconds%$crlf()
 SOURCE$tab()%album%$crlf()
@@ -53,9 +53,11 @@
 
 ...
 
+
 V. References:
 
 1. http://foobar2000.org/
 2. http://www.skipyrich.com/
 
+
 vim:et:ts=4:sw=4:tw=64

Modified: trunk/plugins/np_file/np_file.tcl
===================================================================
--- trunk/plugins/np_file/np_file.tcl	2007-09-19 00:45:52 UTC (rev 43)
+++ trunk/plugins/np_file/np_file.tcl	2007-09-19 16:40:17 UTC (rev 44)
@@ -12,6 +12,7 @@
 	variable lasttime 0
 	variable connections [list]
 	variable monitoring off
+	variable nwarns
 
 	proc mycmd args {
 		lset args 0 [uplevel 1 namespace current]::[lindex $args 0]
@@ -69,8 +70,23 @@
 		[mycmd on_new_connection]
 	hook::add disconnected_hook \
 		[mycmd on_connection_gone]
+
+	# How many warnings of each topic to report:
+	set options(throttle_warns_after) 3
 }
 
+proc np_file::warn {topic msg} {
+	variable options
+	variable nwarns
+
+	if {![info exists nwarns($topic)]} {
+		set nwarns($topic) 0
+	} elseif {$nwarns($topic) >= $options(throttle_warns_after)} return
+
+	puts stderr "np_file: $msg"
+	incr nwarns($topic)
+}
+
 proc np_file::enabled {} {
 	variable options
 
@@ -184,7 +200,7 @@
 	variable connections
 
 	if {![file exists $options(file)]} {
-		puts stderr "np_file: file \"$options(file)\" doesn't exist"
+		warn missing "file \"$options(file)\" doesn't exist"
 		return
 	}
 
@@ -197,7 +213,7 @@
 	if {$failed} {
 		global errorInfo
 		set monitoring false
-		puts stderr "np_file: parser script for player \"$options(name,$tag)\"\
+		warn parsing "parser script for player \"$options(name,$tag)\"\
 			failed: $errorInfo"
 	}
 }
@@ -220,6 +236,8 @@
 #### Foobar2000:
 
 proc np_file::foobar_yield fname {
+	variable connections
+
 	debugmsg tune [info level 0]
 
 	set fd [open $fname]
@@ -227,27 +245,41 @@
 	set data [read $fd]
 	close $fd
 
-	foobar_parse $data status artist title track length source uri
-	switch -- $status {
+	foobar_parse $data info
+
+	switch -- $info(status) {
 		STOPPED {
-			# TODO implement publishing of "stopped":
 			foreach connid $connections {
-				#::plugins::tune::unpublish $connid
+				::plugins::tune::unpublish $connid
 			}
 		}
 		PLAYING {
+			unset info(status)
+			set args [list]
+			foreach {key val} [array get info] {
+				if {$val == ""} continue
+				lappend args -$key $val
+			}
 			foreach connid $connections {
-				::plugins::tune::publish $connid \
-					$artist $title $track $length $source $uri
+				eval [list ::plugins::tune::publish $connid] $args
 			}
 		}
 	}
 }
 
-proc np_file::foobar_parse {data \
-		&status &artist &title &track &length &source &uri} {
-	uprefs
+proc np_file::foobar_parse {data vinfo} {
+	upvar 1 $vinfo info
 
+	array set info {
+		status ""
+		artist ""
+		title  ""
+		track  ""
+		length ""
+		source ""
+		uri    ""
+	}
+
 	set lines [list]
 	foreach line [split $data \n] {
 		lappend lines [string trim $line]
@@ -267,28 +299,21 @@
 		}
 	}
 
-	set artist ""
-	set title  ""
-	set track  ""
-	set length ""
-	set source ""
-	set uri    ""
-
 	foreach line [lrange $lines 1 end] {
 		if {[regexp -nocase \
 				{^(artist|title|track|length|source|uri)\s+(.*)$} \
 				$line -> tag value]} {
 			set tag [string tolower $tag]
-			set $tag $value
+			set info($tag) $value
 		} else {
-			puts stderr "np_file: skipped junk line \"$line\""
+			warn junk "skipped junk line \"$line\""
 		}
 	}
 
-	if {![string equal $length ""]} {
-		set length [string trimleft $length 0]
+	if {![string equal $info(length) ""]} {
+		set length [string trimleft $info(length) 0]
 		if {![string is integer $length] || $length < 0} {
-			puts stderr "np_file: bad length \"$length\":\
+			warn format "bad length \"$length\":\
 				must be non-negative short integer"
 			set length ""
 		}
@@ -326,7 +351,7 @@
 			}
 		}
 		default {
-			puts stderr "np_file: unknown or missing playing status, ignored"
+			warn format "unknown or missing playing status, ignored"
 		}
 	}
 }
@@ -359,7 +384,7 @@
 			title       { set info(title)  $val }
 			tracknumber { set info(track)  $val }
 			default     {
-				puts stderr "np_file: unknown key: \"$key\", ignored"
+				warn format "unknown key: \"$key\", ignored"
 			}
 		}
 	}



More information about the Tkabber-dev mailing list