[ZLM], 25 de Novembro de 2004: One of the main events of 2004 for me was the discovery of KEXP, a Seatlle based non-profit radio that broadcasts live on the Internet at kexp.org. I now listen to a lot of new music that I probably wouldn't know about otherwise. I listen to it mainly at work, with my headphones to keep off the background noise of my open space. The station has a live playlist that I check whenever something nice is playing that I don't recognize. I wrote this script to avoid having to launch Opera and checking the web page so may times. At first I thougt about displaying the song information on Winamp itself, but I took a look at the Winamp SDK and thought "pois.. talvez isto não seja grande idéia, Zé...". Anyway I never have Winamp visible, not even in the System Tray, so why bother? So this simply uses Winico to display an icon in the System Tray (a nice yellow tea mug in my case) that shows the song information on the associated text whenever I pass the mouse pointer over it. Clicking the icon updates the song information, double-clicking toggles auto-updating on/off and right clicking exits. For the moment that's all the UI I need. I am using some procs plundered here on the wiki: wsplit [http://mini.net/tcl/split] by [ Salvatore Sanfilippo], every [http://mini.net/tcl/after] by [Richard Suchenwirth], and toggle [http://mini.net/tcl/4517] by [Keith Vetter]. I use wsplit all the time, I wish something like it was part of the core Tcl. wm withdraw . package require Winico #I need to configure http to use a proxy... package require http ; http::config -proxyhost 172.29.149.142 -proxyport 8080 set target_page "http://www.kexp.org/playlist/playlist.asp" set autoupdate 0 set ico [winico createfrom c:/cup.ico] winico taskbar add $ico -text "Bom dia!" -callback "actualizar %m" proc actualizar {mensagem} { if {$mensagem == "WM_LBUTTONDBLCLK"} { toggle ::autoupdate } if {$mensagem == "WM_LBUTTONDOWN"} { updateNow } if {$mensagem == "WM_RBUTTONDOWN"} { exit } } proc updateNow {} { winico taskbar modify $::ico -text [scrapText] } proc scrapText {} { if { [catch {set html [http::data [http::geturl $::target_page]]} errohttp] } { return "Erro! $errohttp" } else { set linha "[between "class=\"programtime\">" and "" in $html]" set songinfo [wsplit $linha "" ] set artista [string trim [between " " and "" in [lindex $songinfo 2]]] #I know I should do something better about replacing html entities... set titulo [string map { ")" ")" "(" "(" "'" "'" } [string trim [string map {"" ""} [lindex $songinfo 4]]] ] set album [string trim [string map {"" ""} [lindex $songinfo 6]]] return "$artista - $titulo" } } proc between { start "and" end "in" text} { set string_start [string first $start $text] set string_end [string first $end $text $string_start] set start_removed [string replace [string range $text $string_start $string_end] 0 [expr [string length $start ]-1] ] return [string replace $start_removed end end ] } proc wsplit {string sep} { set first [string first $sep $string] if {$first == -1} { return [list $string] } else { set l [string length $sep] set left [string range $string 0 [expr {$first-1}]] set right [string range $string [expr {$first+$l}] end] return [concat [list $left] [wsplit $right $sep]] } } proc toggle varName { upvar 1 $varName var set var [expr {$var ? 0 : 1}] } proc every {ms body} {eval $body; after $ms [info level 0]} every 120000 {if {$::autoupdate} { updateNow } }