[Tkabber-dev] r30 - trunk/plugins/np_foobar

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Aug 24 05:06:54 MSD 2007


Author: kostix
Date: 2007-08-24 05:06:54 +0400 (Fri, 24 Aug 2007)
New Revision: 30

Added:
   trunk/plugins/np_foobar/AUTHORS
   trunk/plugins/np_foobar/INSTALL
   trunk/plugins/np_foobar/README
   trunk/plugins/np_foobar/TODO
   trunk/plugins/np_foobar/license.terms
   trunk/plugins/np_foobar/np_foobar.tcl
Log:
Initial import of "np_foobar" project files.


Added: trunk/plugins/np_foobar/AUTHORS
===================================================================
--- trunk/plugins/np_foobar/AUTHORS	                        (rev 0)
+++ trunk/plugins/np_foobar/AUTHORS	2007-08-24 01:06:54 UTC (rev 30)
@@ -0,0 +1 @@
+Konstantin Khomoutov <flatworm at users.sourceforge.com>


Property changes on: trunk/plugins/np_foobar/AUTHORS
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/np_foobar/INSTALL
===================================================================
--- trunk/plugins/np_foobar/INSTALL	                        (rev 0)
+++ trunk/plugins/np_foobar/INSTALL	2007-08-24 01:06:54 UTC (rev 30)
@@ -0,0 +1,19 @@
+In order to use this plugin you must have:
+* A working Foobar2000 installation.
+* "foobar_np_simple" Foobar2000 plugin installed and tuned
+  as explained in the README file.
+
+Note that since Foobar2000 is only available for Windows systems
+there's no sense to use this plugin on other platforms.
+
+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
+
+Restart Tkabber, to get the plugin loaded.
+Visit the "Customize->Plugins->User Tune->Foobar2000"
+block of settings and adjust them to match your setup.
+
+Consult the README file for the details about using this plugin.


Property changes on: trunk/plugins/np_foobar/INSTALL
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/np_foobar/README
===================================================================
--- trunk/plugins/np_foobar/README	                        (rev 0)
+++ trunk/plugins/np_foobar/README	2007-08-24 01:06:54 UTC (rev 30)
@@ -0,0 +1,51 @@
+"Foobar2000 Now Playing" plugin for Tkabber.
+$Id$
+
+I. The idea.
+
+...
+
+III. Confuguration of "foobar_np_simple".
+
+1. "Filename":
+
+Pick some convenient filename for the now-playing file.
+This must be a full pathname and it must match the value
+specified in the corresponding configuration option of
+Tkabber (see below).
+
+"foobar.txt" in the Tkabber's configuration directory
+is probably a good bet.
+
+2. "Encoding":
+
+UTF-8
+
+3. "Formatting string":
+
+$if($and(%isplaying%,$not(%ispaused%)),
+PLAYING $crlf()
+ARTIST$tab()%artist%$crlf()
+LENGTH$tab()%length_seconds%$crlf()
+SOURCE$tab()%album%$crlf()
+TITLE$tab()%title%$crlf()
+TRACK$tab()%track%$crlf()
+URI$tab()$crlf()
+,
+STOPPED
+)
+
+4. "On exit":
+
+STOPPED
+
+IV. Configuration of Tkabber.
+
+...
+
+V. References:
+
+1. http://foobar2000.org/
+2. http://www.skipyrich.com/
+
+vim:et:ts=4:sw=4:tw=64


Property changes on: trunk/plugins/np_foobar/README
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/plugins/np_foobar/TODO
===================================================================
--- trunk/plugins/np_foobar/TODO	                        (rev 0)
+++ trunk/plugins/np_foobar/TODO	2007-08-24 01:06:54 UTC (rev 30)
@@ -0,0 +1,25 @@
+$Id$
+
+HIGH:
+
+* 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.
+
+* For some reason updates to the node wasn't propagated
+  from jabbus.org to 007spb.ru during tests.
+  Need to check.
+
+* Implement some means for banning certain connections from
+  publishing. This should be a user-supplied regexp probably.
+
+* Improve README.
+
+LOW:
+
+* Study if it's possible to open a named pipe using Tcl
+  and specify it as NP file in foobar_np_simple.
+  Will this at all work?
+  If it is, it would eliminate polling of NP file.
+


Property changes on: trunk/plugins/np_foobar/TODO
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: trunk/plugins/np_foobar/license.terms
===================================================================
--- trunk/plugins/np_foobar/license.terms	                        (rev 0)
+++ trunk/plugins/np_foobar/license.terms	2007-08-24 01:06:54 UTC (rev 30)
@@ -0,0 +1,19 @@
+Copyright (c) 2007 Konstantin Khomoutov <flatworm at users.sourceforge.net>
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.


Property changes on: trunk/plugins/np_foobar/license.terms
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/plugins/np_foobar/np_foobar.tcl
===================================================================
--- trunk/plugins/np_foobar/np_foobar.tcl	                        (rev 0)
+++ trunk/plugins/np_foobar/np_foobar.tcl	2007-08-24 01:06:54 UTC (rev 30)
@@ -0,0 +1,212 @@
+# $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 {
+			puts 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
+			puts "$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) < 10000} {
+		set options(mtime_threshold) 10000
+	}
+}
+


Property changes on: trunk/plugins/np_foobar/np_foobar.tcl
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native



More information about the Tkabber-dev mailing list