Tcl html无线电公告
我想从翻译和歌曲公告在irc的实时更改歌曲时,一个新的公告 我已经测试过了,但不幸的是我没有问题Tcl html无线电公告,tcl,radio,Tcl,Radio,我想从翻译和歌曲公告在irc的实时更改歌曲时,一个新的公告 我已经测试过了,但不幸的是我没有问题 set radio_url "http://player.radiopilatus.ch" bind pub - !radio radio_get proc radio_get { nick uhost handle channel text } { global radio_url set file [open "|lynx -source $radio_url" r]
set radio_url "http://player.radiopilatus.ch"
bind pub - !radio radio_get
proc radio_get { nick uhost handle channel text } {
global radio_url
set file [open "|lynx -source $radio_url" r]
set html "[gets $file]"
regsub -all "<br>" $html " " html
regsub -all "<\[^b]{0,1}b{0,1}>" $html "" html
regsub "text1=" $html "" html
regsub "NOW PLAYING:" $html "Now on http://player.radiopilatus.ch playing \002" html
putnow "PRIVMSG $channel :$html";
}
set radio\u url”http://player.radiopilatus.ch"
绑定酒吧-!收音机
proc radio_get{nick uhost handle channel text}{
全球电台网址
设置文件[open“| lynx-source$radio_url”r]
设置html“[获取$file]”
regsub-all“
“$html”html
regsub-所有“$html”html
regsub“text1=“$html”html
regsub“正在播放:$html”正在播放http://player.radiopilatus.ch 正在播放\002“html
putnow“PRIVMSG$channel:$html”;
}
最后,我想说:
!song Interpret Song Unixtimestamp
!song MARLON_ROUDETTE NEW_AGE 1483293195
!歌曲解释歌曲Unixtimestamp
!宋马龙·鲁代特新时代1483293195
通常,您需要经常询问网站当前状态(即当前歌曲),并在看到更改时报告。你问得越频繁,结果就越准确,但网站的负载就越大(许多人反对让别人的代码攻击他们的网站)。让我们每10秒进行一次投票,也就是10000毫秒 我们还需要将当前值存储在全局变量中,以便检测何时发生了更改。当更改发生时,我们更新全局。如果我们将代码分解成几个过程,每个过程都有自己的简单工作,那么它就会变得更简单
proc get_current_song {} {
global radio_url
set file [open "|lynx -source $radio_url" r]
set html [gets $file]
# IMPORTANT! Close the channel once we're done with it...
close $file
regsub -all "<br>" $html " " html
regsub -all "<\[^b]{0,1}b{0,1}>" $html "" html
regsub "text1=" $html "" html
regsub "NOW PLAYING:" $html "" song
return $song
}
set current_song ""
proc get_current_song_if_changed {} {
global current_song
set song [get_current_song]
if {$song ne $current_song} {
set current_song $song
return $song
}
# No change, so the empty string
return ""
}
set running 0
proc poll_and_report_song_changes {channel} {
# Allow us to stop the loop
global running
if {!$running} {
return
}
# Schedule the next call of this procedure
after 10000 poll_and_report_song_changes $channel
set song [get_current_song_if_changed]
if {$song ne ""} {
putnow "PRIVMSG $channel :Now on http://player.radiopilatus.ch playing \002$song"
}
}
bind pub - !radio radio_control
proc radio_control { nick uhost handle channel text } {
global running
if {$running} {
set running 0
putnow "PRIVMSG $channel :Will stop reporting song changes"
} else {
set running 1
putnow "PRIVMSG $channel :Will start reporting song changes"
poll_and_report_song_changes $channel
}
}
proc获取当前歌曲{}{
全球电台网址
设置文件[open“| lynx-source$radio_url”r]
设置html[获取$file]
#重要!一旦我们结束频道就关闭它。。。
关闭$file
regsub-all“
“$html”html
regsub-所有“$html”html
regsub“text1=“$html”html
regsub“正在播放:$html”歌曲
返回$song
}
设置当前歌曲“”
proc get_current_song_如果_更改{}{
全球流行歌曲
设置歌曲[获取当前歌曲]
如果{$song ne$current_song}{
设置当前歌曲$song
返回$song
}
#没有改变,所以空字符串
返回“”
}
设置运行0
proc poll_和报告_song_更改{channel}{
#让我们停止循环
全球运行
如果{!$running}{
返回
}
#安排此过程的下一次调用
10000次民意调查和报告后,宋更改$channel
设置歌曲[如果更改,则获取当前歌曲]
如果{$song ne”“}{
putnow“PRIVMSG$频道:立即打开http://player.radiopilatus.ch 正在播放\002$song“
}
}
绑定酒吧-!无线电控制
proc无线电控制{nick uhost handle channel text}{
全球运行
如果{$running}{
设置运行0
putnow“PRIVMSG$channel:将停止报告歌曲更改”
}否则{
设置运行1
putnow“PRIVMSG$channel:将开始报告歌曲更改”
民意测验和报告歌曲改变$channel
}
}
请注意,现在有4个过程
get_current_song
与网站对话,获取当前歌曲并返回该歌曲。它没有别的作用如果歌曲更改,则获取当前歌曲
基于此检测歌曲更改poll_和_report_song_更改
基于此定期轮询,如果检测到更改,请在频道上报告radio\u control
是实际绑定到操作的控件,用于打开和关闭轮询