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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Sep 15 21:29:15 MSD 2007


Author: kostix
Date: 2007-09-15 21:29:14 +0400 (Sat, 15 Sep 2007)
New Revision: 37

Added:
   trunk/plugins/np_file/np_file.tcl
Removed:
   trunk/plugins/np_file/np_foobar.tcl
Modified:
   trunk/plugins/np_file/INSTALL
   trunk/plugins/np_file/README
   trunk/plugins/np_file/TODO
Log:
np_file/np_file.tcl:
  Renamed from np_file/np_foobar.tcl.
  Implemented support for multiple players.
np_file/: TODO, INSTALL, README
  Updated.


Modified: trunk/plugins/np_file/INSTALL
===================================================================
--- trunk/plugins/np_file/INSTALL	2007-09-15 13:45:06 UTC (rev 36)
+++ trunk/plugins/np_file/INSTALL	2007-09-15 17:29:14 UTC (rev 37)
@@ -9,11 +9,11 @@
 As usually, copy this directory under the ~/.tkabber/plugins directory
 so that you get a hierarchy like this:
   ~/.tkabber/plugins
-  ~/.tkabber/plugins/np_foobar/
-  ~/.tkabber/plugins/np_foobar/np_foobar.tcl
+  ~/.tkabber/plugins/np_file/
+  ~/.tkabber/plugins/np_file/np_file.tcl
 
 Restart Tkabber, to get the plugin loaded.
-Visit the "Customize->Plugins->User Tune->Foobar2000"
+Visit the "Customize->Plugins->User Tune->Now Playing (File)"
 block of settings and adjust them to match your setup.
 
 Consult the README file for the details about using this plugin.

Modified: trunk/plugins/np_file/README
===================================================================
--- trunk/plugins/np_file/README	2007-09-15 13:45:06 UTC (rev 36)
+++ trunk/plugins/np_file/README	2007-09-15 17:29:14 UTC (rev 37)
@@ -1,10 +1,20 @@
-"Foobar2000 Now Playing" plugin for Tkabber.
+"Now Playing File" plugin for Tkabber.
 $Id$
 
 I. The idea.
 
 ...
 
+
+II. Supported media players.
+
+Currently these media players are supported:
+
+Windows:
+
+* Foobar2000 [1] via its "foobar_np_simple" plugin [2].
+
+
 III. Confuguration of "foobar_np_simple".
 
 1. "Filename":

Modified: trunk/plugins/np_file/TODO
===================================================================
--- trunk/plugins/np_file/TODO	2007-09-15 13:45:06 UTC (rev 36)
+++ trunk/plugins/np_file/TODO	2007-09-15 17:29:14 UTC (rev 37)
@@ -2,10 +2,13 @@
 
 HIGH:
 
+* Double-check timings. Probably [yield] is triggered each second
+  on non-existing files.
+
 * Implement publishing of "stopped" playing status in Tkabber
   then implement handling of the "stopped" state in this plugin.
 
-* Fix regexp to allow empty data in some tags.
+* Fix regexp to allow empty data in some tags for foobar_np_simple.
 
 * For some reason updates to the node wasn't propagated
   from jabbus.org to 007spb.ru during tests.

Copied: trunk/plugins/np_file/np_file.tcl (from rev 36, trunk/plugins/np_file/np_foobar.tcl)
===================================================================
--- trunk/plugins/np_file/np_file.tcl	                        (rev 0)
+++ trunk/plugins/np_file/np_file.tcl	2007-09-15 17:29:14 UTC (rev 37)
@@ -0,0 +1,290 @@
+# $Id$
+# "Now Playing File" -- User Tune plugin for Tkabber.
+# Queries a file with "now playing" information updated by
+# one of the supported media players and posts the information
+# aquired to the user's "User Tune" PEP nodes.
+# Written by Konstantin Khomoutov <flatworm at users.sourceforge.net>
+# See license.terms for details about distribution.
+# See README for details about usage.
+
+namespace eval np_file {
+	variable options
+	variable lasttime 0
+	variable connections [list]
+	variable monitoring off
+
+	proc mycmd args {
+		lset args 0 [uplevel 1 namespace current]::[lindex $args 0]
+	}
+
+	custom::defgroup "User Tune" \
+		[::msgcat::mc "Plugins for automatic gathering of\
+			information for User Tune personal eventing facility."] \
+		-group Plugins
+
+	custom::defgroup NowPlayingFile \
+		[::msgcat::mc "Support for files with \"now playing\" information\
+			managed by various media players."] \
+		-group "User Tune"
+
+	custom::defvar options(media_player) "" \
+		[::msgcat::mc "Media player that manages the now playing file.\
+			Please note that some media players and/or their \"now playing\"\
+			plugins require additional configuration to work with this plugin.\
+			Please consult the README file of this plugin for configuration\
+			instructions. Select \"None\" to disable this plugin."] \
+		-type options \
+		-values [list] \
+		-command [mycmd on_media_player_changed] \
+		-group NowPlayingFile
+
+	custom::defvar options(file) [file join $::configdir np.txt] \
+		[::msgcat::mc "Pathname of the now playing file."] \
+		-type file \
+		-group NowPlayingFile
+
+	custom::defvar options(check_timeout) 1 \
+		[::msgcat::mc "Timeout (in seconds) between checks\
+			for modification of the now-playing file."] \
+		-type integer \
+		-group NowPlayingFile
+
+	custom::defvar options(mtime_threshold) 30 \
+		[::msgcat::mc "Minimal amount of time (in seconds) that must tick\
+			between adjacent now-playing file modifications\
+			for its contents to be used."] \
+		-type integer \
+		-command on_mtime_thresh_changed \
+		-group NowPlayingFile
+
+	hook::add connected_hook \
+		[mycmd on_new_connection]
+	hook::add disconnected_hook \
+		[mycmd on_connection_gone]
+}
+
+proc np_file::enabled {} {
+	variable options
+
+	expr {$options(media_player) != ""}
+}
+
+# Calling of this procedure does only have sense when done from
+# a np_file_enumerate_media_players hook.
+proc np_file::add_media_player args {
+	variable options
+	variable players
+
+	foreach {opt val} $args {
+		switch -- $opt {
+			-tag    { set tag $val }
+			-name   { set name $val }
+			-parser { set parser $val }
+			default {
+				return -code error "Bad option \"$opt\":\
+					must be one of -tag, -name or -parser"
+			}
+		}
+	}
+
+	foreach v {tag name parser} {
+		if {![info exists $v]} {
+			return -code error "Required option missing: -$v"
+		}
+	}
+
+	if {$tag == ""} {
+		return -code error "Empty tag is reserved and cannot be used"
+	}
+
+	set options(name,$tag) $name
+	set options(parser,$tag) $parser
+
+	lappend players $tag $name
+}
+
+proc np_file::enumerate_media_players args {
+	variable options
+	variable players
+
+	foreach {tag name parser} [list \
+		foobar     "Foobar2000"   [mycmd foobar_yield] \
+		QL         "Quod Libet"   [mycmd quodlibet_yield]  \
+	] {
+		add_media_player -tag $tag -name $name -parser $parser
+	}
+
+	hook::run np_file_enumerate_media_players
+
+	custom::configvar [namespace current]::options(media_player) \
+		-values [concat [list "" [::msgcat::mc "None"]] $players]
+
+	unset players
+}
+
+proc np_file::on_new_connection connid {
+	variable connections
+
+	set connections [lsort -unique [lappend connections $connid]]
+
+	monitoring [expr {[enabled] && [llength $connections] > 0}]
+}
+
+proc np_file::on_connection_gone connid {
+	variable connections
+
+	set ix [lsearch -sorted $connections $connid]
+	if {$ix >= 0} {
+		set connections [lreplace $connections $ix $ix]
+	}
+
+	monitoring [expr {[enabled] && [llength $connections] > 0}]
+}
+
+proc np_file::monitoring activate {
+	variable options
+	variable monitoring
+	variable repollid
+
+	if {$activate && !$monitoring} {
+		set monitoring on
+		[mycmd poll] ;# must be fully qualified
+	} elseif {$monitoring && !$activate} {
+		set monitoring off
+		if {[info exists repollid]} {
+			after cancel $repollid
+		}
+	}
+}
+
+proc np_file::poll {} {
+	variable options
+	variable repollid
+
+	upvar 0 options(media_player) tag
+	set failed [catch $options(parser,$tag) err]
+	if {$failed} {
+		puts stderr "Parser scrit for player \"$options(name,$tag)\"\
+			failed: $err"
+	}
+
+	if {$options(check_timeout) > 0} {
+		set repollid [after \
+			[expr {$options(check_timeout) * 1000}] [info level 0]]
+	}
+}
+
+proc np_file::on_media_player_changed args {
+	variable connections
+
+	monitoring [expr {[enabled] && [llength $connections] > 0}]
+}
+
+proc np_file::on_mtime_thresh_changed args {
+	variable options
+
+	# Prevent modification time threshold to be lower than 10 sec:
+	if {$options(mtime_threshold) < 10} {
+		set options(mtime_threshold) 10
+	}
+}
+
+#### Foobar2000:
+
+proc np_file::foobar_yield {} {
+	variable options
+	variable lasttime
+	variable monitoring
+	variable connections
+
+	if {![file exists $options(file)]} {
+		puts stderr "np_file: file \"$options(file)\" doesn't exist"
+		return
+	}
+
+	set mtime [file mtime $options(file)]
+	if {$mtime - $lasttime < $options(mtime_threshold)} return
+	set lasttime $mtime
+
+	set fd [open $options(file)]
+	fconfigure $fd -encoding utf-8
+	set data [read $fd]
+	close $fd
+
+	foobar_parse $data status artist title track length source uri
+	switch -- $status {
+		STOPPED {
+			# TODO implement publishing of "stopped":
+			foreach connid $connections {
+				#::plugins::tune::unpublish $connid
+			}
+		}
+		PLAYING {
+			foreach connid $connections {
+				::plugins::tune::publish $connid \
+					$artist $title $track $length $source $uri
+			}
+		}
+	}
+}
+
+proc np_file::parse_foobar {data \
+		vstatus vartist vtitle vtrack vlength vsource vuri} {
+	upvar 1 $vstatus status $vartist artist $vtitle title \
+		$vtrack track $vlength length $vsource source $vuri uri
+
+	set lines [list]
+	foreach line [split $data \n] {
+		lappend lines [string trim $line]
+	}
+
+	set status [string toupper [lindex $lines 0]]
+	switch -- $status {
+		STOPPED {
+			return
+		}
+		PLAYING {
+			# processed below
+		}
+		default {
+			return -code error "Bad playing status \"$status\":\
+				must be one of PLAYING or STOPPED"
+		}
+	}
+
+	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
+		} else {
+			puts stderr "np_file: skipped junk line \"$line\""
+		}
+	}
+
+	if {![string equal $length ""]} {
+		set length [string trimleft $length 0]
+		if {![string is integer $length] || $length < 0} {
+			puts stderr "np_file: bad length \"$length\":\
+				must be non-negative short integer"
+			set length ""
+		}
+	}
+}
+
+#### Quod Libit:
+
+proc np_file::quodlibet_yield {} {
+	debugmsg tune [info level 0]
+}
+
+np_file::enumerate_media_players
+

Deleted: trunk/plugins/np_file/np_foobar.tcl
===================================================================
--- trunk/plugins/np_file/np_foobar.tcl	2007-09-15 13:45:06 UTC (rev 36)
+++ trunk/plugins/np_file/np_foobar.tcl	2007-09-15 17:29:14 UTC (rev 37)
@@ -1,210 +0,0 @@
-# $Id$
-# "Foobar2000 Now Playing" -- User Tune plugin for Tkabber.
-# Queries a file with "now playing" information updated by
-# "foobar_np_simple" Foobar2000 plugin and publishes it in the user's
-# "User Tune" PEP node.
-# Written by Konstantin Khomoutov <flatworm at users.sourceforge.net>
-# See license.terms for details about distribution.
-# See README for details about usage.
-
-namespace eval np_foobar {
-	variable options
-	variable lasttime 0
-	variable connections [list]
-	variable monitoring off
-
-	custom::defgroup "User Tune" \
-		[::msgcat::mc "Plugins for automatic gathering of\
-			information for User Tune personal eventing facility."] \
-		-group Plugins
-
-	custom::defgroup Foobar2000 \
-		[::msgcat::mc "Support for \"Now playing simple\" Foobar2000\
-			plugin (http://www.skipyrich.com)."] \
-		-group "User Tune"
-
-	custom::defvar options(enable) 1 \
-		[::msgcat::mc "Enable this plugin."] \
-		-type boolean \
-		-command [namespace current]::on_state_changed \
-		-group Foobar2000
-
-	custom::defvar options(file) [file join $::configdir foobar.txt] \
-		[::msgcat::mc ""] \
-		-type file \
-		-group Foobar2000
-
-	custom::defvar options(check_timeout) 1 \
-		[::msgcat::mc "Timeout (in seconds) between checks\
-			for modification of the now-playing file."] \
-		-type integer \
-		-group Foobar2000
-
-	custom::defvar options(mtime_threshold) 30 \
-		[::msgcat::mc "Minimal amount of time (in seconds) that must tick\
-			between adjacent now-playing file modifications\
-			for its contents to be used."] \
-		-type integer \
-		-command on_mtime_thresh_changed \
-		-group Foobar2000
-
-	hook::add connected_hook \
-		[namespace current]::on_new_connection
-	hook::add disconnected_hook \
-		[namespace current]::on_connection_gone
-}
-
-proc np_foobar::on_new_connection connid {
-	variable options
-	variable connections
-
-	set connections [lsort -unique [lappend connections $connid]]
-
-	monitoring [expr {$options(enable) && [llength $connections] > 0}]
-}
-
-proc np_foobar::on_connection_gone connid {
-	variable options
-	variable connections
-
-	set ix [lsearch -sorted $connections $connid]
-	if {$ix >= 0} {
-		set connections [lreplace $connections $ix $ix]
-	}
-
-	monitoring [expr {$options(enable) && [llength $connections] > 0}]
-}
-
-proc np_foobar::monitoring activate {
-	variable options
-	variable monitoring
-	variable repollid
-
-	if {$activate && !$monitoring} {
-		set monitoring on
-		[namespace current]::poll ;# must be fully qualified
-	} elseif {$monitoring && !$activate} {
-		set monitoring off
-		if {[info exists repollid]} {
-			after cancel $repollid
-		}
-	}
-}
-
-proc np_foobar::poll {} {
-	variable options
-	variable repollid
-
-	yield
-
-	if {$options(check_timeout) > 0} {
-		set repollid [after \
-			[expr {$options(check_timeout) * 1000}] [info level 0]]
-	}
-}
-
-proc np_foobar::yield {} {
-	variable options
-	variable lasttime
-	variable monitoring
-	variable connections
-
-	if {![file exists $options(file)]} {
-		puts stderr "np_foobar: file \"$options(file)\" doesn't exist"
-		return
-	}
-
-	set mtime [file mtime $options(file)]
-	if {$mtime - $lasttime < $options(mtime_threshold)} return
-	set lasttime $mtime
-
-	set fd [open $options(file)]
-	fconfigure $fd -encoding utf-8
-	set data [read $fd]
-	close $fd
-
-	parse $data status artist title track length source uri
-	switch -- $status {
-		STOPPED {
-			# TODO implement publishing of "stopped":
-			foreach connid $connections {
-				#::plugins::tune::unpublish $connid
-			}
-		}
-		PLAYING {
-			foreach connid $connections {
-				::plugins::tune::publish $connid \
-					$artist $title $track $length $source $uri
-			}
-		}
-	}
-}
-
-proc np_foobar::parse {data \
-		vstatus vartist vtitle vtrack vlength vsource vuri} {
-	upvar 1 $vstatus status $vartist artist $vtitle title \
-		$vtrack track $vlength length $vsource source $vuri uri
-
-	set lines [list]
-	foreach line [split $data \n] {
-		lappend lines [string trim $line]
-	}
-
-	set status [string toupper [lindex $lines 0]]
-	switch -- $status {
-		STOPPED {
-			return
-		}
-		PLAYING {
-			# processed below
-		}
-		default {
-			return -code error "Bad playing status \"$status\":\
-				must be one of PLAYING or STOPPED"
-		}
-	}
-
-	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
-		} else {
-			puts stderr "np_foobar: skipped junk line \"$line\""
-		}
-	}
-
-	if {![string equal $length ""]} {
-		set length [string trimleft $length 0]
-		if {![string is integer $length] || $length < 0} {
-			puts stderr "np_foobar: bad length \"$length\":\
-				must be non-negative short integer"
-			set length ""
-		}
-	}
-}
-
-proc np_foobar::on_state_changed args {
-	variable options
-	variable connections
-
-	monitoring [expr {$options(enable) && [llength $connections] > 0}]
-}
-
-proc np_foobar::on_mtime_thresh_changed args {
-	variable options
-
-	# Prevent modification time threshold to be lower than 10 sec:
-	if {$options(mtime_threshold) < 10} {
-		set options(mtime_threshold) 10
-	}
-}
-



More information about the Tkabber-dev mailing list