[Tkabber-dev] r51 - in trunk/plugins/now_playing: . contrib/quodlibet

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Sep 22 16:40:50 MSD 2007


Author: kostix
Date: 2007-09-22 16:40:49 +0400 (Sat, 22 Sep 2007)
New Revision: 51

Modified:
   trunk/plugins/now_playing/contrib/quodlibet/np_simple.py
   trunk/plugins/now_playing/now_playing.tcl
Log:
now_playing/contrib/quodlibet/np_simple.py: Now writes UTF-8 in the output file.
 
now_playing/now_playing.tcl: Created helper proc [read_utf8] to read data from
  UTF-8 files while being BOM-agnostic. Misc fixes.



Modified: trunk/plugins/now_playing/contrib/quodlibet/np_simple.py
===================================================================
--- trunk/plugins/now_playing/contrib/quodlibet/np_simple.py	2007-09-21 18:09:14 UTC (rev 50)
+++ trunk/plugins/now_playing/contrib/quodlibet/np_simple.py	2007-09-22 12:40:49 UTC (rev 51)
@@ -7,9 +7,8 @@
 # Inspired by JEP118 plugin.
 
 # TODO
-# * Dump all available info.
-# * Probably dump song info also on "paused" state.
-# What's with Unicode/UTF-8? Ideally we need UTF-8 file.
+# ? Dump all available info.
+# ? Dump song info also on "paused" state.
 
 import os
 import util
@@ -27,32 +26,31 @@
 ~#length=%d
 """
 
-def report_inactive(state):
+def write_out(what):
 	try:
 		f = file(outfile, 'w')
-		f.write("status=%s\n" % state)
+		f.write(what.encode('utf-8'))
 	except EnvironmentError: pass
 	else: f.close()
 
+def report_inactive(state):
+	write_out("status=%s\n" % state)
+
 class np_simple(EventPlugin):
-	PLUGIN_ID = 'np_simple'
-	PLUGIN_NAME = 'Now Playing Simple'
-	PLUGIN_DESC = 'Outputs simple now playing info to a text file'
-	PLUGIN_ICON = 'gtk-save'
-	PLUGIN_VERSION = '0.2'
+	PLUGIN_ID      = 'np_simple'
+	PLUGIN_NAME    = 'Now Playing Simple'
+	PLUGIN_DESC    = 'Outputs simple now playing info to a text file'
+	PLUGIN_ICON    = 'gtk-save'
+	PLUGIN_VERSION = '0.3'
 
 	def report_song_info(self, song):
-		try:
-			f = file(outfile, 'w')
-			f.write(format % (
+		write_out(format % (
 				'playing',
-				util.escape(song.comma('artist')),
-				util.escape(song.comma('title')),
-				util.escape(song.comma('album')),
+				song.comma('artist'),
+				song.comma('title'),
+				song.comma('album'),
 				song('tracknumber'),
 				song('~#length')))
-		except EnvironmentError: pass
-		else: f.close()
 
 	def plugin_on_song_started(self, song):
 		if song:

Modified: trunk/plugins/now_playing/now_playing.tcl
===================================================================
--- trunk/plugins/now_playing/now_playing.tcl	2007-09-21 18:09:14 UTC (rev 50)
+++ trunk/plugins/now_playing/now_playing.tcl	2007-09-22 12:40:49 UTC (rev 51)
@@ -19,6 +19,8 @@
 		lset args 0 [uplevel 1 namespace current]::[lindex $args 0]
 	}
 
+	proc K {x y} { set x }
+
 	custom::defgroup "User Tune" \
 		[::msgcat::mc "Plugins for automatic gathering of\
 			information for User Tune personal eventing facility."] \
@@ -105,9 +107,6 @@
 			expr {$monitoring && $val]}
 		}
 		set {
-			variable options
-			variable repollid
-
 			if {$val && !$monitoring} {
 				set monitoring on
 				method_start_[method]
@@ -213,9 +212,12 @@
 	variable lastmethod
 	variable connections
 
-	if {![string equal $lastmethod [method]]} {
+	set method [method]
+
+	if {![string equal $lastmethod $method]} {
 		method_stop_$lastmethod
 	}
+	set lastmethod $method
 
 	monitoring set [expr {[enabled] && [llength $connections] > 0}]
 }
@@ -291,6 +293,12 @@
 	polling_cancel
 }
 
+proc now_playing::read_utf8 fname {
+	set fd [open $fname]
+	fconfigure $fd -encoding utf-8
+	K [string trimleft [read $fd] \uFEFF] [close $fd]
+}
+
 proc now_playing::file_poll {} {
 	variable options
 	variable repollid
@@ -337,13 +345,8 @@
 
 	debugmsg tune [info level 0]
 
-	set fd [open $fname]
-	fconfigure $fd -encoding utf-8
-	set data [read $fd]
-	close $fd
+	foobar_parse [read_utf8 $fname] info
 
-	foobar_parse $data info
-
 	switch -- $info(status) {
 		STOPPED {
 			foreach connid $connections {
@@ -422,13 +425,8 @@
 proc now_playing::quodlibet_yield fname {
 	variable connections
 
-	set fd [open $fname]
-	fconfigure $fd -encoding utf-8
-	set data [read $fd]
-	close $fd
+	quodlibet_parse [read_utf8 $fname] info
 
-	quodlibet_parse $data info
-
 	switch -- $info(status) {
 		paused -
 		inactive {



More information about the Tkabber-dev mailing list