This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Domsen update to Shoutcast 2.4.7.256

Support & discussion of released scripts, and announcements of new releases.
User avatar
flink
Halfop
Posts: 70
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

this is the json code

Code: Select all

 
namespace eval radio {
	
	variable streamurl "https://playradio.nombredelaradio.com/api/nombredelaradio/nowplaying/montaje"
	variable radiochan "#yourchan"
	
	package require http
	package require tls

	
	variable cursong ""                                                                          
	
	bind pub - !direct ::radio::pub:getstream
	bind pub -|n !mute ::radio::mute
	bind pub -|n !unmute ::radio::unmute
	
	proc mute {nick uhost handle chan text} {
		unbind cron - "* * * * *" ::radio::getstream
	}
	
	proc unmute {nick uhost handle chan text} {
		bind cron - "* * * * *" ::radio::getstream
	}
	
	proc pub:getstream {nick uhost handle chan text} {
		if {[::string tolower $chan] ne $::radio::radiochan } {
			return
		}
		::radio::getstream 0 0 0 0 0
	}
	
	proc getstream {mi ho da mo wd} {
		::http::register https 443 ::tls::socket
		set tok [::http::geturl $::radio::streamurl]
		set source [::radio::json2dict [::http::data $tok]]
		::http::cleanup $tok
		::http::unregister https
		set title [dict get $source title]
		set artist [dict get $source artist]
		if {$::radio::cursong ne $title} {
			set ::radio::cursong $title
			set artist [encoding convertfrom utf-8 [string map {"&" "&"} $artist]]
			set title [encoding convertfrom utf-8 [string map {"&" "&"} $title]]
			putserv "PRIVMSG $::radio::radiochan :Now streaming : \002\00303$title\003\002 by \002\00307$artist\003\002"
		}
	}
	
	proc json2dict {JSONtext} {
		string range [string trim [string trimleft [string map {\t {} \n {} \r {} , { } : { } \[ \{ \] \}} $JSONtext] {\uFEFF}]] 1 end-1
	}
}


this is the code of the shoutcast script that does the function of sending the songs, if the Dj is live or in Dj autoplay the link and etc.

Code: Select all

proc isonline { nick uhost hand chan arg } {
   global radiochans announce tellusers tellsongs tellbitrate urltopic dj
   global offlinetext offlinetopic onlinetext onlinetopic
   global streamip streampass streamport dj
   global doalertadmin alertadmin

   if {$announce == 1 || $tellsongs == 1 || $tellusers == 1 || $tellbitrate == 1} {
      set isonlinefile "isonline.txt"
      set oldisonline "isonline: 0"
      set oldcurlist "curlist: 0"
      set oldcurhigh "curhigh: 0"
      set oldsong "cursong: 0"
      set oldbitrate "bitrate: 0"
      if {[file exists $isonlinefile]} {
         putlog "shoutcast: checking if stream is online"
         set temp [open "isonline.txt" r]
         while {[eof $temp] != 1} {
            set zeile [gets $temp]
            if {[string first "isonline:" $zeile] != -1 } { set oldisonline $zeile }
            if {[string first "curlist:" $zeile] != -1 } { set oldcurlist $zeile }
            if {[string first "curhigh:" $zeile] != -1 } { set oldcurhigh $zeile }
            if {[string first "cursong:" $zeile] != -1 } { set oldsong $zeile }
            if {[string first "bitrate:" $zeile] != -1 } { set oldbitrate $zeile }
         }
         close $temp
      }
      if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
         putlog "error: $sockerror"
         return 0} else {
         puts $sock "GET /admin.cgi?sid=1&pass=$streampass&mode=viewxml&page=0 HTTP/1.1"
         puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
         puts $sock "Host: $streamip"
         puts $sock "Connection: close"
         puts $sock ""
         flush $sock
         while {[eof $sock] != 1} {
            set bl [gets $sock]
            if { [string first "standalone" $bl] != -1 } {
               set streamstatus "isonline: [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]"
               set repl "curlist: [string range $bl [shrink + 19 "<UNIQUELISTENERS>" 0 $bl] [shrink - 1 "</UNIQUELISTENERS>" 0 $bl]]"
               set curhigh "curhigh: [string range $bl [shrink + 15 "<PEAKLISTENERS>" 0 $bl] [shrink - 1 "</PEAKLISTENERS>" 0 $bl]]"
               set currentl [string range $bl [shrink + 18 "<CURRENTLISTENERS>" 0 $bl] [shrink - 1 "</CURRENTLISTENERS>" 0 $bl]]
               set surl "serverurl: [string range $bl [shrink + 11 "<SERVERURL>" 0 $bl] [shrink - 1 "</SERVERURL>" 0 $bl]]"
               set cursong "cursong: [string range $bl [shrink + 11 "<SONGTITLE" 0 $bl] [shrink - 1 "</SONGTITLE>" 0 $bl]]"
               set songurl [string range $bl [shrink + 9 "<SONGURL>" 0 $bl] [shrink - 1 "</SONGURL>" 0 $bl]]
               set bitrate "bitrate: [string range $bl [shrink + 9 "<BITRATE>" 0 $bl] [shrink - 1 "</BITRATE>" 0 $bl]]"
               set stitle "stitle: [string range $bl [shrink + 13 "<SERVERTITLE>" 0 $bl] [shrink - 1 "</SERVERTITLE>" 0 $bl]]"
               set sgenre "sgenre: [string range $bl [shrink + 13 "<SERVERGENRE>" 0 $bl] [shrink - 1 "</SERVERGENRE>" 0 $bl]]"
            }
         }
         close $sock
      }
      set temp [open "isonline.txt" w+]
      puts $temp "$streamstatus\n$repl\n$curhigh\n$cursong\n$bitrate\n$stitle\n$sgenre\n$surl"
      close $temp
      if {$announce == 1 } {
         if {![info exists streamstatus]} { poststuff privmsg $offlinetext }
         if {$streamstatus == "isonline: 0" && $oldisonline == "isonline: 1"} {
            poststuff privmsg $offlinetext
            if {$doalertadmin == "1"} { sendnote domsen $alertadmin "radio is now offline" }
            if {$urltopic == 1} { poststuff topic $offlinetopic }
         }
         if {$streamstatus == "isonline: 1" && $oldisonline == "isonline: 0" } {
            if {$sgenre != ""} {
               set sgenre " ([lrange $sgenre 1 [llength $sgenre]] )"
            }
            poststuff privmsg "$onlinetext"
            if {$urltopic == 1} { poststuff topic "$onlinetopic" }
         }
      }
      if {($tellusers == 1) && ($streamstatus == "isonline: 1") && ($oldcurhigh != "curhigh: 0") } {
         if {$oldcurhigh != $curhigh} {
            poststuff privmsg "new listener peak: [lindex $curhigh 1]"
         }
         if {$oldcurlist != $repl} {
            poststuff privmsg "there are currently [lindex $repl 1] ($currentl) people listening"
         }
      }
      if {($tellsongs == 1) && ($oldsong != $cursong) && ($streamstatus == "isonline: 1") } {
         if {$songurl != ""} { set songurl " ($songurl)"}
         regsub -all "<" $cursong "<" cursong
         regsub -all ">" $cursong ">" cursong
         regsub -all "&" $cursong "+" cursong
         regsub -all """ $cursong "\"" cursong
         regsub -all "'" $cursong "'" cursong
         regsub -all "ÿ" $cursong "" cursong
         regsub -all "´" $cursong "´" cursong
         regsub -all "&#x96;" $cursong "-" cursong
         regsub -all "ö" $cursong "ö" cursong
         regsub -all "ä" $cursong "ä" cursong
         regsub -all "ü" $cursong "ü" cursong
         regsub -all "Ö" $cursong "Ö" cursong
         regsub -all "Ä" $cursong "Ä" cursong
         regsub -all "Ü" $cursong "Ü" cursong
         regsub -all "ß" $cursong "ß" cursong
         regsub -all "&apos;" $cursong "'" cursong
         putlog $cursong
         poststuff privmsg "\007Now Playing\007: [lrange $cursong 1 [llength $cursong]]$songurl"
      }

      if {($tellbitrate == 1) && ($oldbitrate != $bitrate) && ($streamstatus == "isonline: 1") && ($oldbitrate != "bitrate: 0")} {
         poststuff privmsg "bitrate switched to [lindex $bitrate 1]kbps"
      }
   }
}

putlog "*** shoutcast.tcl v1.03XXX by Domsen updated by RickTee76 <domsen@domsen.org> succesfully loaded. turn it up baby."


I wonder if there is a way to insert the json into the shoutcast script and have it perform the same function as this part of the original script. thanks a lot.
thanks to the people who help and contribute to see if it is solved.
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

The thing we need is what your shoutcast server (not the script, the shoutcat server) send or can send when you go to https://your.shoutcast.server/admin.cgi ... de=viewxml

And to know if you can have another output than xml, probably by changing the mode value in the url.
User avatar
flink
Halfop
Posts: 70
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

thanks CrazyCat for replying where can I get that info my server is zeno.fm free account would be in the control panel which I have the data of the radio,
Shoutcast Stream Encoder Configuration
ip
port
DJ / User ID
password
Sid
if this is what you need let me know and I will pass it to you via private message, thank you very much.

I leave the web of where I guessed api with which you made me the json
if you get the data that you ask me I do not know how to get them thank you again
https://zeno.fm/angelescaidos/
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
CrazyCat
Revered One
Posts: 1216
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Sorry, but you have to ask your radio provider, I can help with the tcl part but I can't do anything else.
User avatar
flink
Halfop
Posts: 70
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

ok CrazyCat thank you, I will talk to the server staff to see if they can reveal this information to me and I will pass it on to you so that you can help me, thank you very much for taking another step to solve the problem, as soon as I know something I will comment here, again thank you very much.
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
flink
Halfop
Posts: 70
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

well at the end I am trying with a centova panel and it goes great with shoutcast v1 and well but I have a problem to see if they help me to solve it in the titles of the songs when they carry accent does not read them and releases in the room a lot of strange signs to see if you have a solution and tell me how to fix it thank you very much as always

this would be the originals : Víctor Manuelle - Si Tú Me besas
Gloria Trevi & Alejandra Guzmán - Más Buena
No Doubt - Don't Speak
Lola Indigo, TINI, Belinda - Niña de la Escuela

these the ones that it throws : Víctor Manuelle - Si Tú Me Besas
Gloria Trevi {&} Alejandra Guzmán - Más Buena
No Doubt - {Don&apos;t} Speak
Lola Indigo, TINI, Belinda - Niña de la Escuela

as it is seen when the words have accents or ñ does not read them.
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
flink
Halfop
Posts: 70
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

no one has responded, can anyone help?
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
play4free2
Voice
Posts: 34
Joined: Sat Nov 23, 2013 1:42 am
Contact:

Post by play4free2 »

flink wrote:no one has responded, can anyone help?
Replace this part of the code

Code: Select all

         regsub -all "<" $cursong "<" cursong
         regsub -all ">" $cursong ">" cursong
         regsub -all "&" $cursong "+" cursong
         regsub -all """ $cursong """ cursong
         regsub -all "'" $cursong "'" cursong
         regsub -all "ÿ" $cursong "" cursong
         regsub -all "´" $cursong "´" cursong
         regsub -all "&#x96;" $cursong "-" cursong
         regsub -all "ö" $cursong "ö" cursong
         regsub -all "ä" $cursong "ä" cursong
         regsub -all "ü" $cursong "ü" cursong
         regsub -all "Ö" $cursong "Ö" cursong
         regsub -all "Ä" $cursong "Ä" cursong
         regsub -all "Ü" $cursong "Ü" cursong
         regsub -all "ß" $cursong "ß" cursong
         regsub -all "&apos;" $cursong "'" cursong
         putlog $cursong
         poststuff privmsg "\007Now Playing\007: [lrange $cursong 1 [llength $cursong]]$songurl"
}
With this code

Code: Select all

      regsub -all "<" $cursong "<" cursong
      regsub -all ">" $cursong ">" cursong
      regsub -all "&" $cursong "\&" cursong
      regsub -all """ $cursong """ cursong
      regsub -all "'" $cursong "'" cursong
      regsub -all "ÿ" $cursong "" cursong
      regsub -all "´" $cursong "´" cursong
      regsub -all "&#x96;" $cursong "-" cursong
      regsub -all "ö" $cursong "ö" cursong
      regsub -all "ä" $cursong "ä" cursong
      regsub -all "ü" $cursong "ü" cursong
      regsub -all "Ö" $cursong "Ö" cursong
      regsub -all "Ä" $cursong "Ä" cursong
      regsub -all "Ü" $cursong "Ü" cursong
      regsub -all "ß" $cursong "ß" cursong
      regsub -all "é" $cursong "é" cursong
      regsub -all "á" $cursong "á" cursong
      regsub -all "ë" $cursong "ë" cursong
      regsub -all "ñ" $cursong "ñ" cursong
      regsub -all "{" $cursong "" cursong
      regsub -all "}" $cursong "" cursong 
      putlog $cursong
      poststuff privmsg "\007Now Playing\007: [lrange $cursong 1 [llength $cursong]]$songurl"
}
That should fix a few of your errors, it did mine.
You can also look here: https://www.utf8-chartable.de/unicode-u ... inhtml=hex for more Unicode Hex Characters if you need them.

Like the ñ etc.
Image
420-HIGHTIMES IRC Network
O
ORATEGOD
Voice
Posts: 39
Joined: Mon Jun 08, 2020 5:50 pm

Post by ORATEGOD »

flink wrote:thanks CrazyCat for replying where can I get that info my server is zeno.fm free account would be in the control panel which I have the data of the radio,
Shoutcast Stream Encoder Configuration
ip
port
DJ / User ID
password
Sid
if this is what you need let me know and I will pass it to you via private message, thank you very much.

I leave the web of where I guessed api with which you made me the json
if you get the data that you ask me I do not know how to get them thank you again
https://zeno.fm/angelescaidos/
Saludos amigo .... consulta!! ... pudiste correr el tcl en zeno ¡¡??
User avatar
flink
Halfop
Posts: 70
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

thanks for the answer, play4free2 but it has not corrected the error. i also looked at the link you left and everything is ok but it keeps giving me the same errors as soon as they come up &,",',',`.

Tainy, Bad Bunny, Julieta Venegas - Lo Siento BB
Tainy · Bad Bunny · Julieta Venegas - Lo Siento BB


Helen Reddy - You're My World
Helen Reddy - {You&apos;re} My World
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
flink
Halfop
Posts: 70
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

ORATEGOD wrote:
flink wrote:thanks CrazyCat for replying where can I get that info my server is zeno.fm free account would be in the control panel which I have the data of the radio,
Shoutcast Stream Encoder Configuration
ip
port
DJ / User ID
password
Sid
if this is what you need let me know and I will pass it to you via private message, thank you very much.

I leave the web of where I guessed api with which you made me the json
if you get the data that you ask me I do not know how to get them thank you again
https://zeno.fm/angelescaidos/
Saludos amigo .... consulta!! ... pudiste correr el tcl en zeno ¡¡??
Saludos ORATEGOD ... Nada pille un panel centova y ahora si hace lo que necesitaba, gracias
Mi ingles: no es el mejor, Manda el traductor... :)
User avatar
play4free2
Voice
Posts: 34
Joined: Sat Nov 23, 2013 1:42 am
Contact:

Post by play4free2 »

flink wrote:thanks for the answer, play4free2 but it has not corrected the error. i also looked at the link you left and everything is ok but it keeps giving me the same errors as soon as they come up &,",',',`.

Tainy, Bad Bunny, Julieta Venegas - Lo Siento BB
Tainy · Bad Bunny · Julieta Venegas - Lo Siento BB


Helen Reddy - You're My World
Helen Reddy - {You&apos;re} My World
This is the complete code I am currently using for my Shoutcast Server v2.6.0.753 Eggdrop v1.8.4 and Anope 1.8.9

It will work with Anope 2.0.x if you change this line:

Code: Select all

if {$advertiseglobal == "1" && $advertiseonlyifonline == "0"} { putserv "PRIVMSG OperServ :GLOBAL $globaltext" }
To this:

Code: Select all

if {$advertiseglobal == "1" && $advertiseonlyifonline == "0"} { putserv "PRIVMSG GLOBAL :GLOBAL $globaltext" }

Code: Select all

###############################################################################################################
#
# shoutcast.tcl v2.00
# copyleft (c) 2o21 - play4free2 & cards
#
# Based on the original shoutcast.tcl v1.03 by domsen <domsen@domsen.org> (c)2oo5
# Also some parts are based on shoutcast.tcl by Sm0ke0ut
#
# This displays the current song, bitrate, and stream title plus
# listen link(s), page link(s) and website link into the public channel(s)
# It also sends all request to the radio's staff channel.
#
# Also this script will have the bot kick the source from the shoutcast radio server,
# from the Radio's staff channel and requires Ops in the channel for it to work.
# It also displays listerners, peak listeners, the shoutcast server status and 
# the admin login link to the radio's staff channel.
#
# Last but not least it auto announces the current song and link(s) into public channel(s)
#
# To enable in your channel(s) Type: .chanset <channel> +radio +shoutgreet +shoutauto +shoutadmin
#
# Public Commands: !radio !song !link !dj !request !website and !page
# Staff Channel Commands: !kickdj !listeners !peak !server !admin
#
# Channel Setup Fill in: Radio Station URL or IP and Port, DJ Staff Channel,
# Listen link(s), Radio Station Page(s), Radio Station Website and Admin login link.
# Also fill in: streamip streamport streampass
# You will need these even if you don't use the auto announce for !kickdj to work.
#
# Auto Announce Setup:
# streamip - the ip of your radio
# streamport - the port of your radio
# streampass - the admin pass of your radio
#
# alertadmin - the userhandle of the user who will get a msg if the server goes down
# doalertadmin - 1 if you want to get a msg if the server goes offline, 0 if you
#                dont. this is done through the bots notes system because its
#                more comfortable and persistent this way.
#
# announce - shall the bot announce any stuff? 1 for yes, 0 for no
# urltopic - shall the bot change the topic everytime the radio goes on or off?
# NOTE: If enable urltopic and have +radio set to multipal channels it will change the topic in all of them.
#
# tellsongs - shall the bot post the songtitle to the channels everytime a new song starts?
# tellusers - shall the bot post the number of current users to the channel 
#             everytime it changes or a new user maximum is reached?
# tellbitrate - shall the bot announce bitrate changes?
#
# offlinetext - the reason the bot says when the radio goes offline
# offlinetopic - the topic which is set when the radio goes offline
#
# onlinetext - the reason the bot says when the radio goes online
# onlinetopic - the topic which is set when the radio goes online
#
# advertise1 - shall the bot advertise the advertisetext1?
# advertise2 - shall the bot advertise the advertisetext2?
#
# advertiseglobal - shall the bot advertise the globaltext? 
# NOTE: The bot must have access to OperServ Global command.
#
# advertiseonlyifonline - 1 if the bot only should advertise the radio and to globals if the stream
#                         is up and running, 0 for all-the-time advertisement
#
# globaltext - the global message the bot sends to all channels every hour on the full.
#
# advertisetext1 - the first line of text the bot will post 3 times an hour on the full 20th. and 40th. min.
# advertisetext2 - the second line of text the bot will post 3 times an hour on the 10th. 30th. and 50th. min.
#
# how do I put veriables in the different texts and topics?
###############################################################################################################
#
# the script knows the following variables which can be used in the offlinetext,
# offlinetopic, onlinetext, onlinetopic, streamtext and advertisetext:
#
# /dj/ - the djnickname
# /sgenre/ - the servers music genre
# /stitle/ - the streamtitle
# /surl/ - the servers url
# /bitrate/ - the current streaming bitrate
# /curlist/ - current listeners
# /curhigh/ - current listener peak
# /cursong/ - the current song
# $streamip - the streams ip
# $streamport - the streams port
#
###############################################################################################################
#Begin Setup
set streamip "your.radio.station.com"
set streamport "8000"
set streampass "Admin Password"
set streamid "1"

set alertadmin "0"
set doalertadmin "0"

set announce "1"

#See NOTE
set urltopic "0"

set tellsongs "1"
set tellusers "0"
set tellbitrate "0"

set advertise1 "1"
set advertise2 "1"

#See NOTE
set advertiseglobal "1"

set advertiseonlyifonline "1"

set offlinetext "\00304Your Radio Station is offline now \00303:'(\003"
set offlinetopic "Set your offline topic here"

set onlinetext "\00304Your Radio Station is now online at \00303(/surl/)\003"
set onlinetopic "/dj/@/stitle/ @ /surl/ streaming at /bitrate/kbps"

set advertisetext1 "\00304Winamp \00303(http://your.radio.station/listen.pls) \00304Request Link \00303(https://www.your.radio.station.com/#Playlist)\003"
set advertisetext2 "\00304Windows Media Player \00303(https//:your.radio.station.m3u) \00304RealPlayer \00303(https://your.radio.station.com/listen.ram)\003"

#Global message the bot will post:
#See NOTE
set globaltext "\00304Tune in to Your Radio Station! It's the \00303'Official' \00304Radio station on irc.your.radio.station.com - Winamp \00303http://your.radio.station.com/listen.pls \00304Windows Media Player \00303https://your.radio.station.com/listen.m3u \00304RealPlayer \00303https://your.radio.station.com/listen.ram \00304Join #YourRadioStationChannel for music - Thx for listening!\003"

#Radio Station URL or IP and Port:
set url "http://your.radio.station.com:8000"

#DJ Staff Channel:
set radiostaff "#RadioStaffChannel"

#Listen links:
set linktext1 "\00304Winamp \00303(http://your.radio.station.com/listen.pls) \00304Request Link \00303(https://your.radio.station.com/#Playlist)\003"
set linktext2 "\00304Windows Media Player \00303(https://your.radio.station.com/listen.m3u) \00304RealPlayer \00303(https://your.radio.station.com/listen.ram)\003"

#Radio Station Pages:
set pagetext "\00304Facebook \00303(https://www.facebook.com/your.station.com) \00304Twitter \00303(https://twitter.com/your.station.com)\003"

#Radio Station Website:
set webtext "\00304Station's Website \00303(https://www.your.radio.station.com)\003"

#Admin login link:
set admintext "\00304\002Admin login\002: \00303(http://your.radio.station.com/admin.cgi)\003"
#End Setup
#########################################################
#DO NOT EDIT BELOW HERE UNLESS YOU KNOW HOW TO WRITE .tcl
#########################################################
bind cron - {* * * * *} isonline

bind cron - {0 */1 * * *} advertise1
bind cron - {20 */1 * * *} advertise1
bind cron - {40 */1 * * *} advertise1

bind cron - {10 */1 * * *} advertise2
bind cron - {30 */1 * * *} advertise2
bind cron - {50 */1 * * *} advertise2

bind cron - {0 */1 * * *} advertiseglobal

set dj ""
set surl ""
set bitrate ""
set stitle ""

proc shrink { calc number string start bl } {
  return [expr [string first "$string" $bl $start] $calc $number]
}

proc status { } {
  global streamip streamport streampass streamid
  if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
    putlog "error: $sockerror"
    return 0
  } else {
    puts $sock "GET /stats?sid=&$streamid&pass=$streampass HTTP/1.0"
    puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
    puts $sock "Host: $streamip"
    puts $sock "Connection: close"
    puts $sock ""
    flush $sock
    while {[eof $sock] != 1} {
      set bl [gets $sock]
      if { [string first "standalone" $bl] != -1 } {
        set streamstatus [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]
      }
    }
    close $sock
  }
  if { $streamstatus == "1" } { return 1 } else { return 0 }
}

proc poststuffb { chand mode text } {
  global radiochans dj
  set curlist "0"
  set curhigh "0"
  set surl ""
  set cursong ""
  set sgenre ""
  set bitrate "0"
  set stitle ""
  set temp [open "isonline" r]
  while {[eof $temp] != 1} {
    set zeile [gets $temp]
    if {[string first "curlist:" $zeile] != -1 } { set curlist $zeile }
    if {[string first "curhigh:" $zeile] != -1 } { set curhigh $zeile }
    if {[string first "cursong:" $zeile] != -1 } { set cursong [lrange $zeile 1 [llength $zeile]] }
    if {[string first "sgenre:" $zeile] != -1 } { set sgenre [lrange $zeile 1 [llength $zeile]]}
    if {[string first "serverurl:" $zeile] != -1 } { set surl [lindex $zeile 1] }
    if {[string first "bitrate:" $zeile] != -1 } { set bitrate [lindex $zeile 1] }
    if {[string first "stitle:" $zeile] != -1 } { set stitle [lrange $zeile 1 [llength $zeile]] }
    if {[string first "dj:" $zeile] != -1 } { set dj [lrange $zeile 1 [llength $zeile]] }
  }
  close $temp
  set stitle [string map {& \\&} $stitle]
  set cursong [string map {& \\&} $cursong]
  regsub -all "/stitle/" $text "$stitle" text
  regsub -all "/curlist/" $text "$curlist" text
  regsub -all "/curhigh/" $text "$curhigh" text
  regsub -all "/cursong/" $text "$cursong" text
  regsub -all "/sgenre/" $text "$sgenre" text
  regsub -all "/surl/" $text "$surl" text
  regsub -all "/bitrate/" $text "$bitrate" text
  regsub -all "/dj/" $text "$dj" text
  regsub -all "{" $text "" text
  regsub -all "}" $text "" text
  regsub -all {\\} $text "" text
  putserv "$mode $chand :$text"
  putlog $text
}

proc poststuff { mode text } {
  global radiochans dj streamid
  set curlist "0"
  set curhigh "0"
  set surl ""
  set cursong ""
  set sgenre ""
  set bitrate "0"
  set stitle ""
  set temp [open "isonline" r]
  while {[eof $temp] != 1} {
    set zeile [gets $temp]
    if {[string first "curlist:" $zeile] != -1 } { set curlist $zeile }
    if {[string first "curhigh:" $zeile] != -1 } { set curhigh $zeile }
    if {[string first "cursong:" $zeile] != -1 } { set cursong [lrange $zeile 1 [llength $zeile]] }
    if {[string first "sgenre:" $zeile] != -1 } { set sgenre [lrange $zeile 1 [llength $zeile]] }
    if {[string first "serverurl:" $zeile] != -1 } { set surl [lindex $zeile 1] }
    if {[string first "bitrate:" $zeile] != -1 } { set bitrate [lindex $zeile 1] }
    if {[string first "stitle:" $zeile] != -1 } { set stitle [lrange $zeile 1 [llength $zeile]] }
    if {[string first "dj:" $zeile] != -1 } { set dj [lrange $zeile 1 [llength $zeile]] }
  }
  close $temp
  set stitle [string map {& \\&} $stitle]
  set cursong [string map {& \\&} $cursong]
  regsub -all "/stitle/" $text "$stitle" text
  regsub -all "/curlist/" $text "$curlist" text
  regsub -all "/curhigh/" $text "$curhigh" text
  regsub -all "/cursong/" $text "$cursong" text
  regsub -all "/sgenre/" $text "$sgenre" text
  regsub -all "/surl/" $text "$surl" text
  regsub -all "/bitrate/" $text "$bitrate" text
  regsub -all "/dj/" $text "$dj" text
  regsub -all "{" $text "" text
  regsub -all "}" $text "" text
  regsub -all {\\} $text "" text
  foreach chan [channels] {
    if {[lsearch -exact [channel info $chan] +shoutauto] != -1} {putserv "$mode $chan :$text"}
  }
  putlog $text
}

proc advertise1 { nick uhost hand chan arg } {
  global advertisetext1 advertise1 advertiseonlyifonline streamid
  if {$advertise1 == "1" && $advertiseonlyifonline == "0"} { poststuff privmsg "$advertisetext1" }
  if {$advertise1 == "1" && $advertiseonlyifonline == "1" && [status] == 1} { poststuff privmsg "$advertisetext1" }
}

proc advertise2 { nick uhost hand chan arg } {
  global advertisetext2 advertise2 advertiseonlyifonline streamid
  if {$advertise2 == "1" && $advertiseonlyifonline == "0"} { poststuff privmsg "$advertisetext2" }
  if {$advertise2 == "1" && $advertiseonlyifonline == "1" && [status] == 1} { poststuff privmsg "$advertisetext2" }
}

proc advertiseglobal { minute hour day month year } {
  global globaltext advertiseglobal advertiseonlyifonline streamid
  if {$advertiseglobal == "1" && $advertiseonlyifonline == "0"} { putserv "PRIVMSG OperServ :GLOBAL $globaltext" }
  if {$advertiseglobal == "1" && $advertiseonlyifonline == "1" && [status] == 1} { putserv "PRIVMSG OperServ :GLOBAL $globaltext" }
}

proc isonline { nick uhost hand chan arg } {
  global radiochans announce tellusers tellsongs tellbitrate urltopic dj
  global offlinetext offlinetopic onlinetext onlinetopic
  global streamip streampass streamport dj streamid
  global doalertadmin alertadmin
  # if we cannot determine status this will assume it is offline
  # keeps tcl errors from lacking required streamstatus variable.
  set streamstatus "isonline: 0"

  if {$announce == 1 || $tellsongs == 1 || $tellusers == 1 || $tellbitrate == 1} {
    set isonlinefile "isonline"
    set oldisonline "isonline: 0"
    set oldcurlist "curlist: 0"
    set oldcurhigh "curhigh: 0"
    set oldsong "cursong: 0"
    set oldbitrate "bitrate: 0"
    if {[file exists $isonlinefile]} {
      set temp [open "isonline" r]
      while {[eof $temp] != 1} {
        set zeile [gets $temp]
        if {[string first "isonline:" $zeile] != -1 } { set oldisonline $zeile }
        if {[string first "curlist:" $zeile] != -1 } { set oldcurlist $zeile }
        if {[string first "curhigh:" $zeile] != -1 } { set oldcurhigh $zeile }
        if {[string first "cursong:" $zeile] != -1 } { set oldsong $zeile }
        if {[string first "bitrate:" $zeile] != -1 } { set oldbitrate $zeile }
	 }
      close $temp
    }
    if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
      putlog "error: $sockerror"
      return 0
    } else {
      puts $sock "GET /stats?sid=$streamid&pass=$streampass HTTP/1.0"
      puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
      puts $sock "Host: $streamip"
      puts $sock "Connection: close"
      puts $sock ""
      flush $sock
      while {[eof $sock] != 1} {
        set bl [gets $sock]
        if { [string first "standalone" $bl] != -1 } {
          set streamstatus "isonline: [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]"
          set repl "curlist: [string range $bl [shrink + 17 "<UNIQUELISTENERS>" 0 $bl] [shrink - 1 "</UNIQUELISTENERS>" 0 $bl]]"
          set curhigh "curhigh: [string range $bl [shrink + 15 "<PEAKLISTENERS>" 0 $bl] [shrink - 1 "</PEAKLISTENERS>" 0 $bl]]"
          set currentl [string range $bl [shrink + 18 "<CURRENTLISTENERS>" 0 $bl] [shrink - 1 "</CURRENTLISTENERS>" 0 $bl]]
          set surl "serverurl: [string range $bl [shrink + 11 "<SERVERURL>" 0 $bl] [shrink - 1 "</SERVERURL>" 0 $bl]]"
          set cursong "cursong: [string range $bl [shrink + 11 "<SONGTITLE" 0 $bl] [shrink - 1 "</SONGTITLE>" 0 $bl]]"
          set songurl "surl: [string range $bl [shrink + 9 "<SONGURL>" 0 $bl] [shrink - 1 "</SONGURL>" 0 $bl]]"
          set bitrate "bitrate: [string range $bl [shrink + 9 "<BITRATE>" 0 $bl] [shrink - 1 "</BITRATE>" 0 $bl]]"
          set stitle "stitle: [string range $bl [shrink + 13 "<SERVERTITLE>" 0 $bl] [shrink - 1 "</SERVERTITLE>" 0 $bl]]"
          set sgenre "sgenre: [string range $bl [shrink + 13 "<SERVERGENRE>" 0 $bl] [shrink - 1 "</SERVERGENRE>" 0 $bl]]"
	  set dj "dj: [string range $bl [shrink + 4 "<DJ>" 0 $bl] [shrink - 1 "</DJ>" 0 $bl]]"
        }
      }
      close $sock
#      putlog $cursong
      set cursong [string map {[ \\[} $cursong]
      set cursong [string map {& \\&} $cursong]
      set cursong [string map {$ \\$} $cursong]
      #regsub -all "&" $cursong "\&" cursong
      #set cursong [string map {& \\&} $cursong]
      regsub -all -nocase "&" $cursong "\\&" cursong
      regsub -all "<" $cursong "<" cursong
      regsub -all ">" $cursong ">" cursong
      regsub -all "&" $cursong "\&" cursong
      regsub -all """ $cursong """ cursong
      regsub -all "'" $cursong "'" cursong
      regsub -all "ÿ" $cursong "" cursong
      regsub -all "´" $cursong "´" cursong
      regsub -all "&#x96;" $cursong "-" cursong
      regsub -all "ö" $cursong "ö" cursong
      regsub -all "ä" $cursong "ä" cursong
      regsub -all "ü" $cursong "ü" cursong
      regsub -all "Ö" $cursong "Ö" cursong
      regsub -all "Ä" $cursong "Ä" cursong
      regsub -all "Ü" $cursong "Ü" cursong
      regsub -all "ß" $cursong "ß" cursong
      regsub -all "é" $cursong "é" cursong
      regsub -all "á" $cursong "á" cursong
      regsub -all "ë" $cursong "ë" cursong
      regsub -all "ñ" $cursong "ñ" cursong
      regsub -all "&apos;" $cursong "'" cursong
      regsub -all "{" $cursong "" cursong
      regsub -all "}" $cursong "" cursong
 #     putlog $cursong

      set temp [open "isonline" w+]
      puts $temp "$streamstatus\n$repl\n$curhigh\n$cursong\n$bitrate\n$stitle\n$sgenre\n$surl\n$dj"
      close $temp
      if {$announce == 1 } {
        if {$streamstatus == "isonline: 0" && $oldisonline == "isonline: 1"} {
          poststuff privmsg $offlinetext
          if {$doalertadmin == 1} { $alertadmin "radio is now offline" }
          if {$urltopic == 1} { poststuff topic $offlinetopic }
        }
        if {$streamstatus == "isonline: 1" && $oldisonline == "isonline: 0" } {
          if {$sgenre != ""} {
            set sgenre " ([lrange $sgenre 1 [llength $sgenre]] )"
          }
          poststuff privmsg "$onlinetext"
          if {$urltopic == 1} { poststuff topic "$onlinetopic" }
        }
      }
    }
    if {$tellusers == 1 && $streamstatus == "isonline: 1" && $oldcurhigh != "curhigh: 0" } {
      if {$oldcurhigh != $curhigh} {
        poststuff privmsg "\00304New listener peak:\00303 [lindex $curhigh 1]\003"
      }
      if {$oldcurlist != $repl} {
        poststuff privmsg "\00304There are currently\00303 [lindex $repl 1] \($currentl\ unique) people listening\003"
      }
    }
    if {$tellsongs == 1 && $oldsong != $cursong && $streamstatus == "isonline: 1" } {
      if {$songurl != ""} { set songurl " ($songurl)"}
      putlog $cursong
      poststuff privmsg "\00304Now Playing @ [lindex $bitrate 1] kbps \00303[lrange $cursong 1 [llength $cursong]] ([lrange $stitle 1 [llength $stitle]])\003"
    }
    if {$tellbitrate == 1 && $oldbitrate != $bitrate && $streamstatus == "isonline: 1" && $oldbitrate != "bitrate: 0"} {
      poststuff privmsg "\00304Bitrate switched to\00303 [lindex $bitrate 1]kbps\003"
    }
  }
}
#--------------- Begin Public Commands ---------------
bind pub -|- !song shoutcast_song
proc shoutcast_song {nick uhost hand chan text} {
  poststuffb $chan privmsg "\00304Now Playing @ /bitrate/ kbps \00303/cursong/ (/stitle/)\003"
}
bind pub -|- !dj shoutcast_dj
proc shoutcast_dj {nick uhost hand chan text} {
  if {[channel get $chan radio]} {
  poststuffb $chan privmsg "\00304DJ \00303/dj/\00304 is currently on \00303/stitle/\003"
  }
}  
bind pub -|- !request shoutcast_request
proc shoutcast_request {nick uhost hand chan arg} {
  global radiostaff
  if {[channel get $chan radio]} {
    set cmd [string tolower [lindex $arg 0]]
    if {$cmd == ""} {
      putserv "NOTICE $nick Please use: !request Artist - Song Title"
      return 0
      } else {
      putserv "PRIVMSG $radiostaff :\00304\002Request from\002: \00303$nick \00304\002for\002: \00303$arg\003"
      putserv "NOTICE $nick :Your request for \002'$arg'\002 has been succesfully sent to the station's staff."
    }
  }
}
bind pub -|- !link shoutcast_link
proc shoutcast_link {nick uhost hand chan text} {
  global linktext1 linktext2
  if {[channel get $chan radio]} {
    putserv "PRIVMSG $chan :$linktext1"
    putserv "PRIVMSG $chan :$linktext2"
  }
}
bind pub -|- !page shoutcast_page
proc shoutcast_page {nick uhost hand chan text} {
  global pagetext
  if {[channel get $chan radio]} {
    putserv "PRIVMSG $chan :$pagetext"
  }
}
bind pub -|- !website shoutcast_website
proc shoutcast_website {nick uhost hand chan text} {
  global webtext
  if {[channel get $chan radio]} {
    putserv "PRIVMSG $chan :$webtext"
  }
}
bind pub -|- !radio shoutcast_help
proc shoutcast_help {nick uhost hand chan text} {
  if {[channel get $chan radio]} {
    putserv "NOTICE $nick :The following commands are available:"
    putserv "NOTICE $nick :!song !link !dj !page !website and !request"
  }
}
#----------------- End Public Commands ----------------
#--------------- Begin Main Channel Greet -------------
catch {bind join - * rchangreet:wjoin}
proc rchangreet:wjoin {nick uhost hand chan} {
  if {[channel get $chan shoutgreet]} {
    if {![isbotnick $nick]} {
      putserv "NOTICE $nick :\00303Welcome to \00304$chan \00303$nick, where we bring you music 24/7\003"
      putserv "NOTICE $nick :\00303Type: \00304!radio \00303to see a list of bot commands :)\003"
    }
  }
}
#---------------- End Main Channel Greet --------------
#------------- Begin Staff Channel Commands -----------
package require http
bind pub - !kickdj radio_kickdj
proc radio_kickdj {nick uhost hand chan arg} {
  global streamip streamport streampass streamid
  if {[channel get $chan shoutadmin]} {
    if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
    putlog "error: $sockerror"
    return 0
    } else {
    if {[isop $nick $chan] == 1} {
      puts $sock "GET /admin.cgi?sid=$streamid&pass=$streampass&mode=kicksrc HTTP/1.1"
      puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
      puts $sock "Host: $streamip"
      puts $sock "Connection: close"
      puts $sock ""
      flush $sock
      close $sock
        putserv "PRIVMSG $chan :\00304\002Current DJ\002: \00303Was successfully kicked.\003"
        } else {
        putserv "NOTICE $nick :You lack sufficient access to use the command: !kickdj"
      }
    }
  }
}
bind pub -|- !status shoutcast_status
proc shoutcast_status {nick uhost hand chan arg} {
  global url streamid
  if {[channel get $chan shoutadmin]} {
    ::http::config -useragent "Mozilla/5.0; Shoutinfo"
    set http_req [::http::geturl $url/index.html?sid=$streamid -timeout 2000]
    if {[::http::status $http_req] != "ok"} {
      putserv "PRIVMSG $chan :\00304Stream is unavailable.\003";
    }
    set data [::http::data $http_req]
    ::http::cleanup $http_req
    if {[regexp {Listing Status: </td><td><b>([^<]+)</b>} $data x server]} {
      putserv "PRIVMSG $chan :\00304\002Server Status\002: \00303$server\003"
      } else {
      putserv "PRIVMSG $chan :\00304Couldn't contact the server, please check the configuration and/or streaming server.\003"
    }
  }
}
bind pub -|- !peak shoutcast_peak
proc shoutcast_peak {nick uhost hand chan arg} {
  global url streamid
  if {[channel get $chan shoutadmin]} {
    ::http::config -useragent "Mozilla/5.0; Shoutinfo"
    set http_req [::http::geturl $url/index.html?sid=$streamid -timeout 2000]
    if {[::http::status $http_req] != "ok"} {
      putserv "PRIVMSG $chan :\00304Stream is unavailable.\003";
    }
    set data [::http::data $http_req]
    ::http::cleanup $http_req
    if {[regexp {Listener Peak: </td><td><b>([^<]+)</b>} $data x peak]} {
      putserv "PRIVMSG $chan :\00304\002Listener Peak\002: \00303$peak\003"
      } else {
      putserv "PRIVMSG $chan :\00304Couldn't receive any information, checking server status...\003"
      shoutcast_status $nick $uhost $hand $chan $arg
    }
  }
}
bind pub -|- !listeners shoutcast_listeners
proc shoutcast_listeners {nick uhost hand chan arg} {
  global url streamid
  if {[channel get $chan shoutadmin]} {
    ::http::config -useragent "Mozilla/5.0; Shoutinfo"
    set http_req [::http::geturl $url/index.html?sid=$streamid -timeout 2000]
    if {[::http::status $http_req] != "ok"} {
      putserv "PRIVMSG $chan :\00304Stream is unavailable.\003";
    }
    set data [::http::data $http_req]
    ::http::cleanup $http_req
    if {[regexp {([0-9]+) of} $data x listeners]} {
      regexp { of ([^<]+) listeners} $data x maxlisteners
      regexp {listeners ([^<]+)} $data x unique
      regexp {@ ([^<]+),} $data x bitrate
      putserv "PRIVMSG $chan :\00304\002Stream Status\002: \00303Stream is up at $bitrate with $listeners of $maxlisteners listeners $unique\003"
      } else {
      putserv "PRIVMSG $chan :\00304Couldn't receive any information, checking server status...\003"
      shoutcast_status $nick $uhost $hand $chan $arg
    }
  }
}
bind pub -|- !admin shoutcast_admin
proc shoutcast_admin {nick uhost hand chan text} {
  global admintext
  if {[channel get $chan shoutadmin]} {
    putserv "PRIVMSG $chan :$admintext"
  }
}
bind pub -|- !cmds shoutcast_adminhelp
proc shoutcast_adminhelp {nick uhost hand chan text} {
  if {[channel get $chan shoutadmin]} {
    putserv "NOTICE $nick :The following commands are available:"
    putserv "NOTICE $nick :!kickdj !listeners !peak !status !admin"
    putserv "NOTICE $nick :!song !link !dj !page and !website"
  }
}
#-------------- End Staff Channel Commands ------------
setudef flag radio
setudef flag shoutauto
setudef flag shoutadmin
setudef flag shoutgreet
putlog "Shoutcast shoutcast.tcl v2.20 by: play4free2 & cards irc.420-hightimes.com #HighTimes-Lounge & #snoopdogg loaded! Type .chanset <channel> +radio +shoutgreet +shoutauto +shoutadmin to enable in your channel(s)"
Sorry about the custom colours but I was to lazy to take them out :P
I have removed and added a few things from the original... This was just writen a month ago for my shoutcast.v2, it suits my needs fine, and I didn't feel like changing it all.
Image
420-HIGHTIMES IRC Network
User avatar
flink
Halfop
Posts: 70
Joined: Sun Feb 21, 2021 9:27 am
Location: Canarias

Post by flink »

CrazyCat wrote:The thing we need is what your shoutcast server (not the script, the shoutcat server) send or can send when you go to https://your.shoutcast.server/admin.cgi ... de=viewxml

And to know if you can have another output than xml, probably by changing the mode value in the url.
Happy New Year
CrazyCat returning to the subject of the errors of ñ, commas, and rare symbols, etc.
I paste the tcl that I use for shoutcast that I can't find the solution

Code: Select all

set radiochans "##sala1 #sala2"
set otrachan "#sala2"
set otrachans "##sala1"
set adminchans "#sala3"
set adminchans1 "#sala3"
set streamip "123.456.789.11"
set streamport "1234"
set streampass "pass"
set scstatstrigger "!estado"
set scstreamtrigger "!radio"
set scplayingtrigger "!tema"
set sclistenertrigger "!oyentes"
set scdjtrigger "!dj"
set scsetdjtrigger "!emito"
set scunsetdjtrigger "!auto"
set scwishtrigger "!peticion"
set scgreettrigger "!saludos"
set sclastsongstrigger "!ultimas"
set schelptrigger "!comandos"

set alertadmin ""
set doalertadmin "1"

set announce "1"

set urltopic "0"
set ctodjc "1"
set tellsongs "1"
set tellusers "1"
set tellbitrate "1"

set advertise "1"
#si el bot solo debe anunciar la radio si la transmisión  está en funcionamiento, 0 para publicidad permanente 1
set advertiseonlyifonline "0"
##el texto que el bot publicará solo una vez cuando no emitas en directo server on.
set offlinetext "10A2ctualmente 10e2stá 2S10onando 10E2n 12Automatico: 12Pon en tu navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
#set offlinetopic ""
#
set onlinetext "11A1ctualmente está 10S1onando on 12L1ine: 12Pon en tu navegador 4: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
#set onlinetext ""

#set onlinetext ""

#set onlinetopic ""

#set streamtext ""
#set streamtext ""

#el texto que el bot publicará cuando no emitas en directo server on.
#set advertisetext ""
#set advertisetext1 "10E2scuchanos 10e2n: 12----> 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 12 11 13 10L2a 10R2adio 10Q2ue 10T2e 10A2compaña 13 11 12 ,10G2racias 10P2or 10Escuch2arnos "
#set advertisetext "10E2stamos 10A2ctualmente 10e2n: 12----> 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 12 11 13 10L2a 10R2adio 10Q2ue 10T2e 10A2compaña 13 11 12 ,10G2racias 10P2or 10Escuch2arnos "

# end of config #####################

#!estado
bind pub n $scstatstrigger  pub_scstat
bind msg n $scstatstrigger  msg_scstat

#!enlace
bind pub - $scplayingtrigger  pub_playing
bind msg - $scplayingtrigger  msg_playing

#!dj
bind pub - $scdjtrigger  pub_dj
bind msg - $scdjtrigger  msg_dj

#!emito
bind pub D $scsetdjtrigger  pub_setdj
bind msg D $scsetdjtrigger  msg_setdj

#!auto
bind pub D $scunsetdjtrigger  pub_unsetdj
bind msg D $scunsetdjtrigger  msg_unsetdj

#!peticion
bind pub - $scwishtrigger  pub_wish
bind msg - $scwishtrigger  msg_wish

#!saludos
bind pub - $scgreettrigger  pub_greet
bind msg - $scgreettrigger  msg_greet

#!radio
bind pub - $scstreamtrigger pub_stream
bind msg - $scstreamtrigger msg_stream

#!ultimas
bind pub n $sclastsongstrigger pub_lastsongs
bind msg n $sclastsongstrigger msg_lastsongs

#!oyentes
bind pub n $sclistenertrigger pub_listener
bind msg n $sclistenertrigger msg_listener

#!comandos
bind pub - $schelptrigger pub_help
bind msg - $schelptrigger msg_help

#bind time - "* * * * *" isonline
bind time - "*15 * * * *" isonline
#bind time - "*12 * * * *" isonline
bind time - "95 * * * *" advertise
bind nick - * djnickchange

#bind pub n !facebook pub_facebook
bind pub n !xiialive pub_xiialive
#bind pub - !tunein pub_tunein
#bind pub - !winamp pub_winamp
#bind pub n !reproductor pub_reproductor
bind pub D !abre pub_abrepeticiones
bind pub D !cierra pub_cierrapeticiones
bind pub D !status.peticiones pub_statuspeticiones
bind pub n !adminchan proc_adminchan
bind pub n !adminchandj proc_adminchandj
bind pub - !canales proc_canales

set dj ""
set surl ""
set bitrate ""
set stitle ""
set djciudad ""

if {[file exists dj]} {
set temp [open "dj" r]
set dj [gets $temp]
close $temp
}

####prueba

proc cl_chanlist { } {
global botnick
set chanlist ""
       foreach chan [channels] {
               append chanlist "$chan "
       }
return $chanlist
}

proc proc_canales { nick uhost hand chan arg } {
global radiochans
putserv "privmsg $chan : Los canales son $radiochans "
}
proc proc_adminchan { nick uhost hand chan arg } {
global adminchans
putserv "privmsg $chan : El canal es $adminchans "
}
proc proc_adminchandj { nick uhost hand chan arg } {
global adminchans1
putserv "privmsg $chan : El canal es $adminchans1 "
}

proc pub_xiialive { nick uhost hand chan arg } {
putserv "privmsg $chan : 1Fuera de Servicio."
}

#proc pub_facebook { nick uhost hand chan arg } {
#putserv "privmsg $chan :"
#}

#proc pub_tunein { nick uhost hand chan arg } {
#putserv "privmsg $chan : "
#}

#proc pub_winamp { nick uhost hand chan arg } {
#putserv "privmsg $chan : "
#}

#proc pub_reproductor { nick uhost hand chan arg } {
#putserv "privmsg $chan : "
#}

proc pub_abrepeticiones { nick uhost hand chan arg } {
global adminchans1 radiochans otrachan

       if {([lsearch -exact [string tolower $adminchans1] [string tolower $chan]] != -1) || ($adminchans1 == "")} {
       set temp [open "djnick" r]
               set djnick [gets $temp]
       close $temp
putserv "privmsg $adminchans1 :PETICIONES: Las Peticiones han sido abierta"
putserv "privmsg $radiochans 12 $djnick 10A2ßre 10L2as 10P2eticiones, 10P2ide 10u2n 10T2ema 10C2on 10e2l 10C10omando 12!peticion 10Tema - 2Cantante "
putserv "privmsg $otrachan 2 $djnick 10A2ßre 10L2as 10P2eticiones, 10P2ide 10u2n 10T2ema 10C2on 10e2l 10C10omando 12!peticion 10Tema - 2Cantante "
       set temp [open "peticiones" w+]
       puts $temp "Abiertas"
       close $temp
}
}
proc pub_cierrapeticiones { nick uhost hand chan arg } {
global adminchans1 radiochans otrachans
       if {([lsearch -exact [string tolower $adminchans1] [string tolower $chan]] != -1) || ($adminchans1 == "")} {
       set temp [open "djnick" r]
               set djnick [gets $temp]
       close $temp
putserv "privmsg $adminchans1 :PETICIONES: Las Peticiones han sido cerradas"
putserv "privmsg $radiochans 12 $djnick 10C2ierra 10L2as 10P2eticiones, 10S2igue 10E2scuchandonos "
putserv "privmsg $otrachans 12 $djnick 10C2ierra 10L2as 10P2eticiones, 10S2igue 10E2scuchandonos "
       set temp [open "peticiones" w+]
       puts $temp "Cerradas"
       close $temp
}
}

proc pub_statuspeticiones { nick uhost hand chan arg } {
       set temp [open "peticiones" r]
       set peticiones [gets $temp]
       close $temp
putserv "privmsg $chan :PETICIONES: 10E2STADO De Las Peticiones 12$peticiones "
}

###Modulo para agregar ciudad

bind pub D !ciudad pub_setciudad

proc pub_setciudad { nick uhost hand chan arg } { global adminchans1; if {([lsearch -exact [string tolower $adminchans1] [string tolower $chan]] != -1) || ($adminchans1 == "")} { setciudad $arg }}

proc setciudad { djciudad } {
#putlog "shoutcast: $djciudad "
if {$djciudad == "" } { set djciudad $djciudad }
global streamip streamport streampass dj
#putlog "shoutcast: Nuevo Ciudad agregada para $dj ( $djciudad )"
       set temp [open "ciudad" w+]
       puts $temp $djciudad
       close $temp
rehash
}

### Fin Modulo

bind pub - !siguiente pub_siguiente
proc pub_siguiente { nick uhost hand chan arg } {
exec killall sc_trans_linux -WINCH
#putlog "shoutcast: Cambio de canción pedido por $nick"
}

bind pub - !playlist pub_playlist
proc pub_playlist { nick uhost hand chan arg } {
exec killall sc_trans_linux -USR1
#putlog "shoutcast: $nick pidio recargar el playlist"
}



proc shrink { calc number string start bl} { return [expr [string first "$string" $bl $start] $calc $number] }


proc status { } {
global streamip streamport streampass
if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
putlog "error: $sockerror"
return 0 } else {
puts $sock "GET /admin.cgi?pass=$streampass&sid=1&mode=viewxml&page=0 HTTP/1.1"
puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
puts $sock "Host: $streamip"
puts $sock "Connection: close"
puts $sock ""
flush $sock
while {[eof $sock] != 1} {
set bl [gets $sock]
if { [string first "standalone" $bl] != -1 } {
set streamstatus [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]
}}
close $sock
}
if { $streamstatus == "1" } { return 1 } else { return 0 }
}




proc poststuff { mode text } {
global radiochans dj
set curlist "0"
set curhigh "0"
set surl ""
set cursong ""
set sgenre ""
set bitrate "0"
set stitle ""

set temp [open "isonline" r]
while {[eof $temp] != 1} {
set zeile [gets $temp]
if {[string first "curlist:" $zeile] != -1 } { set curlist $zeile }
if {[string first "curhigh:" $zeile] != -1 } { set curhigh $zeile }
if {[string first "cursong:" $zeile] != -1 } { set cursong [lrange $zeile 1 [llength $zeile]]] }
if {[string first "sgenre:" $zeile] != -1 } { set sgenre [lrange $zeile 1 [llength $zeile]]}
if {[string first "serverurl:" $zeile] != -1 } { set surl [lindex $zeile 1] }
if {[string first "bitrate:" $zeile] != -1 } { set bitrate [lindex $zeile 1] }
if {[string first "stitle:" $zeile] != -1 } { set stitle [lindex $zeile 1] }
}
close $temp

regsub -all "/stitle/" $text "$stitle" text
regsub -all "/curlist/" $text "$curlist" text
regsub -all "/curhigh/" $text "$curhigh" text
regsub -all "/cursong/" $text "$cursong" text
regsub -all "/sgenre/" $text "$sgenre" text
regsub -all "/surl/" $text "$surl" text
regsub -all "/bitrate/" $text "$bitrate" text
regsub -all "/dj/" $text "$dj" text

foreach chan [channels] {
if {$radiochans == "" } { putserv "$mode $chan :$text" }
if {$radiochans != "" } {
if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1)} {putserv "$mode $chan :$text"}
}}}


proc schelp { target chan } {
global scstatstrigger scstreamtrigger scplayingtrigger scdjtrigger sclastsongstrigger scwishtrigger scgreettrigger sclistenertrigger radiochans
putserv "privmsg $chan : 12 $target 10L2os 10C2omandos 10d2e 10l2a 10R2adio: 10!comandos - 2!Enlace - 12!Radio - 10!Dj - 2!Peticion 10Tema 2Cantante - 12!ultimas - 10!saludos   10G2racias 10P2or 10S2intonizar 12Radio"
}

proc pub_help {nick uhost hand chan arg} {
global radiochans
if {$radiochans == "" } { schelp $nick $chan }
if {$radiochans != "" } {
if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1) || ($radiochans == "")} { schelp $nick $chan }
}}

bind pub - !pruebamensaje advertise
proc advertise { nick uhost hand chan arg } {
global otrachans otrachan advertisetext  advertise advertiseonlyifonline dj djciudad ciud peticiones radiochan otrachan
set temp [open "ciudad" r]
set ciud [gets $temp]
close $temp
if {$advertise == "1" && $advertiseonlyifonline == "0"} {
 putserv "privmsg $otrachans 10E2stamos 10A2ctualmente 10e2n: 12----> 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 12 11 13 10L2a 10R2adio 10Q2ue 10T2e 10A2compaña 13 11 12 ,10G2racias 10P2or 10Escuch2arnos " 
 
 putserv "privmsg $otrachan 10E2scuchanos 10e2n: 12----> 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 12 11 13 10L2a 10R2adio 10Q2ue 10T2e 10A2compaña 13 11 12 ,10G2racias 10P2or 10Escuch2arnos " 
 }
if {$advertise == "1" && $advertiseonlyifonline == "1" && [status] == 1} {
       #poststuff privmsg "$advertisetext"
       putserv "privmsg $radiochans 10E02mitiendo: 12 $djnick 2P10ara 12Radio  10S2intonizanos: 12Pon en tu Navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
       putserv "privmsg $otrachan 12 $djnick 10E02mitiendo 2P10ara 12Radio 10S2intonizanos: 12Pon en tu Navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
        }
}


proc setdj {nickname djnickname } {
set acmd [lindex $djnickname 0]
set ciud [lrange $djnickname 1 end]
putlog "prueba $ciud"
if {$djnickname == ""} { set djnickname $ciud }
global radiochans otrachan streamip streamport streampass dj ctodjc 
putserv "privmsg $otrachan 4Aviso!!!: 10E2mite 10a2hora:12 $nickname 10D2esde: 12 $ciud 10e2scuchanos 10e2n: 12Pon en tu Navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "

putserv "privmsg $radiochans 4Atencion!!!: 10E2mite 10a2hora:12 $nickname 10D2esde: 12 $ciud 10e2scuchanos 10e2n: 12Pon en tu Navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
putquick "MODE ##sala1 +o $nickname"
putlog "shoutcast: Nuevo Dj: $djnickname ($nickname)"
set temp [open "dj" w+]
puts $temp $nickname
close $temp
set temp [open "djnick" w+]
puts $temp $nickname
close $temp
set temp [open "ciudad" w+]
puts $temp $nickname
close $temp
rehash
if { [status] == "1" } { poststuff privmsg ""
       if { $ctodjc == "1" } {
               set temp [open "isonline" r]
                       while {[eof $temp] != 1} {
                       set zeile [gets $temp]
                       if {[string first "isonline:" $zeile] != -1 } { set oldisonline $zeile }
                       if {[string first "curlist:" $zeile] != -1 } { set oldcurlist $zeile }
                       if {[string first "curhigh:" $zeile] != -1 } { set oldcurhigh $zeile }
                       if {[string first "cursong:" $zeile] != -1 } { set oldsong $zeile }
                       if {[string first "bitrate:" $zeile] != -1 } { set oldbitrate $zeile }
                       }
               close $temp
       }
} else {
putserv "privmsg $nickname : Comando Invalido Por Motivo de tener Nuestra radio fuera de Línea (APAGADA)" }
}


proc msg_setdj { nick uhost hand arg } { setdj $nick $arg }
proc pub_setdj { nick uhost hand chan arg } { global adminchans1; if {([lsearch -exact [string tolower $adminchans1] [string tolower $chan]] != -1) || ($adminchans1 == "")} { setdj $nick $arg }}

proc unsetdj { nick } {
global radiochans otrachan dj djnick djciudad adminchans1 ciudad peticiones
putquick "MODE ##sala1 -o $dj"
putquick "MODE ##sala1 +v $dj"
putserv "privmsg $radiochans 4Aviso!!!: 10E2mite 10a2hora:12 RadioAuto 10D2esde: 12 Canarias 10c2on 10P2eticiones:12 Cerradas 10e2scuchanos 10e2n: 12Pon en tu Navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
putserv "privmsg $otrachan 4Atencion!!!: 10E2mite 10a2hora:12 RadioAuto 10D2esde: 12 Canarias 10c2on 10P2eticiones:12 Cerradas 10e2scuchanos 10e2n: 12Pon en tu Navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "

set temp [open "dj" w+]
puts $temp "RadioAuto"
close $temp
set temp [open "djnick" w+]
puts $temp "RadioAuto"
close $temp
set temp [open "ciudad" w+]
puts $temp "Canarias"
close $temp
set temp [open "peticiones" w+]
puts $temp "Cerradas"
close $temp
putserv "privmsg $adminchans1 :4Dj Puesto en Automatico .."
rehash
}


proc msg_unsetdj { nick uhost hand arg } { unsetdj $nick }
proc pub_unsetdj { nick uhost hand chan arg } { global adminchans1; if {([lsearch -exact [string tolower $adminchans1] [string tolower $chan]] != -1) || ($adminchans1 == "")} { unsetdj $nick }}


proc listener { target } {
global streamip streamport streampass adminchans
putlog "shoutcast: $target cuenta solicitada del oyente"
if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
putlog "error: $sockerror"
return 0 } else {
puts $sock "GET /admin.cgi?pass=$streampass&sid=1&mode=viewxml&page=0 HTTP/1.0"
puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
puts $sock "Host: $streamip"
puts $sock "Connection: close"
puts $sock ""
flush $sock
while {[eof $sock] != 1} {
set bl [gets $sock]
if { [string first "standalone" $bl] != -1 } {
set repl [string range $bl [shrink + 18 "<CURRENTLISTENERS>" 0 $bl] [shrink - 1 "</CURRENTLISTENERS>" 0 $bl]]
set curhigh [string range $bl [shrink + 15 "<PEAKLISTENERS>" 0 $bl] [shrink - 1 "</PEAKLISTENERS>" 0 $bl]]
set maxl [string range $bl [shrink + 14 "<MAXLISTENERS>" 0 $bl] [shrink - 1 "</MAXLISTENERS>" 0 $bl]]
set avgtime [string range $bl [shrink + 13 "<AVERAGETIME>" 0 $bl] [shrink - 1 "</AVERAGETIME>" 0 $bl]]
}}
close $sock
#putserv "notice $target :Actualmente hay $repl Oyente(s), La Radio Tiene Capacidad para $maxl Oyentes, el número máximo de Oyentes Hasta Ahora es de $curhigh Oyentes, el promedio de escucha es a $avgtime"
#putserv "notice $target :  6$target 14Actualmente hay 6 $repl 14Oyente(s), La Radio Tiene Capacidad para 6 $maxl 14Oyentes, el número máximo de Oyentes Hasta Ahora es de 6 $curhigh 14Oyentes, el promedio de escucha es:6 $avgtime"
}}

proc msg_listener { nick uhost hand arg } { listener $nick }
proc pub_listener { nick uhost hand chan arg } { global adminchans; if {([lsearch -exact [string tolower $adminchans] [string tolower $chan]] != -1) || ($adminchans == "")} { listener $nick  }}

proc wish { nick chan arg } {
global radiochans adminchans1
if {$arg == ""} { putserv "privmsg $chan : 12$nick 10P2or 10F2avor 10E2specifica 10E2l 10T2ema 10Q2ue 10D2eseas 10P2edir 10!peticion 10Tema 2Cantante 10G2racias 10P2or 10S2intonizarnos"; return 0}
if { [status] == "1" } {
set temp [open "djnick" r]
set djnick [gets $temp]
close $temp
#putserv "privmsg $radiochans1 :1PEDIDO MUSICAL: 14$arg 1de Parte de 14$nick"
putserv "privmsg $adminchans1 : 10PETICION 12 $djnick 10E2L 10N2ick 12 $nick 10A 2S10olicitado 12 $arg 10En 2El 10Canal 12 $chan"
putserv "privmsg $djnick : 10PETICION 12 $djnick 10E2L 10N2ick 12 $nick 10A 2S10olicitado 12 $arg 10En 2El 10Canal 12 $chan"
putserv "privmsg $chan :  12$nick 10T2u 10P2eticion 2a 10S2ido 10R2egistrada, 10E2n 10U2n 10M2omento 10D2j 6 $djnick 10T2e 10C2omplacera."
} else {
putserv "privmsg $chan :10L2o 10S2iento 12$nick 10l2a 10R2adio 10E2sta 10E2n 10M2odo: 12Automatico :2(" }
}


proc msg_wish { nick uhost hand arg } { wish $nick $arg }
#proc pub_wish { nick uhost hand chan arg } { global radiochans; if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1) || ($radiochans == "")} { wish $nick $arg }}
proc pub_wish { nick uhost hand chan arg } {
global radiochans
       set temp [open "peticiones" r]
               set peticiones [gets $temp]
       close $temp
       if {$peticiones == "Abiertas"} {
        if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1) || ($radiochans == "") } {
         #wish $nick $arg
         wish $nick $chan $arg
        }
       } else {
putserv "privmsg $chan : 12 $nick 10L2as 10P2eticiones 10E2stan 10C2erradas. 10S2igue 10E2scuchandonos "
 }
}




proc sclastsongs { target } {
global streamip streamport streampass otrachan
putlog "shoutcast: $target Historia solicitada de la canción"
if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
putlog "error: $sockerror"
return 0 } else {
puts $sock "GET /admin.cgi?pass=$streampass&sid=1&mode=viewxml&page=0 HTTP/1.0"
puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
puts $sock "Host: $streamip"
puts $sock "Connection: close"
puts $sock ""
flush $sock
while {[eof $sock] != 1} {
set bl [gets $sock]
if { [string first "standalone" $bl] != -1 } {
set songs [string range $bl [string first "<TITLE>" $bl] [expr [string last "</TITLE>" $bl] + 7]]
regsub -all "," $songs "," songs
regsub -all "<" $songs "<" songs
regsub -all ">" $songs ">" songs
regsub -all "&" $songs "\&" songs
regsub -all """ $songs """ songs
regsub -all "'" $songs "'" songs
regsub -all "ÿ" $songs "ÿ" songs
regsub -all "<TITLE>" $songs "(" songs
regsub -all "</TITLE>" $songs ")" songs
regsub -all "<SONG>" $songs "" songs
regsub -all "</SONG>" $songs " - " songs
regsub -all "<PLAYEDAT>" $songs "" songs
regsub -all "</PLAYEDAT>" $songs "" songs
regsub -all {\d} $songs "" songs

regsub -all "´" $songs "´" songs
regsub -all "&#x96;" $songs "-" songs
regsub -all "i" $songs "i" songs
regsub -all "ö" $songs "ö" songs
regsub -all "ä" $songs "ä" songs
regsub -all "ü" $songs "ü" songs
regsub -all "Ö" $songs "Ö" songs
regsub -all "Ä" $songs "Ä" songs
regsub -all "Ü" $songs "Ü" songs
regsub -all "ß" $songs "ß" songs
regsub -all "é" $songs "é" songs
regsub -all "á" $songs "á" songs
regsub -all "ë" $songs "ë" songs
regsub -all "ñ" $songs "ñ" songs
regsub -all "{" $songs "" songs
regsub -all "}" $songs "" songs



}}
close $sock
putserv "privmsg $target :$songs"
}}


proc msg_lastsongs { nick uhost hand arg } { sclastsongs $nick }
proc pub_lastsongs { nick uhost hand chan arg } { global radiochans; if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1) || ($radiochans == "")} { sclastsongs $nick }}



proc scstream { target } {
global streamip streamport streamtext
putlog "shoutcast: streaminfo requested by $target"
poststuff "privmsg $target : $streamtext"

}

proc msg_stream { nick uhost hand arg } { scstream $nick }
proc pub_stream { nick uhost hand chan arg } { global radiochans; if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1) || ($radiochans == "")} {
#putlog "shoutcast: Enlace de Informacion solicitada por $nick"
putserv "privmsg $chan :  10 $nick 10S2intoniza 10E2n: 12Pon en tu Navegador9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
}
}

proc scgreet { nick arg } {
if {$arg == ""} { putserv "notice $nick : Olvidó de agregar su Saludos Ej:(!saludos <Tus Saludos>)"; return 0}
if { [status] == "1" } {
set temp [open "djnick" r]
set djnick [gets $temp]
close $temp
putserv "privmsg $djnick : Enviar unos Saludos: $arg de Parte de $nick"
} else {
putserv "notice $nick : 10L2o 10S2iento 12 $nick 10l2a 10R2adio 10E2sta 10E2n 10M2odo: 12Automatico :2("}
}


proc msg_greet { nick uhost hand arg } { scgreet $nick $arg }
proc pub_greet { nick uhost hand chan arg } { global radiochans; if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1) || ($radiochans == "")} { scgreet $nick $arg }}



proc djnickchange { oldnick uhost hand chan newnick } {
set temp [open "djnick" r]
set djnick [gets $temp]
close $temp
if {$oldnick == $djnick} {
putlog "shoutcast: Cambio de Nick del Dj de $oldnick a $newnick"
set temp [open "djnick" w+]
puts $temp $newnick
close $temp
}}


proc dj {target chan} {
global streamip streamport streampass dj
putlog "shoutcast: $target pedido La informacion del DJ"
if {[status] == 1} {
if {[file exists dj]} {
set temp [open "dj" r]
set dj [gets $temp]
close $temp
putserv "privmsg $chan :12$target 10E2mitiendo: 12 $dj 2S10intoniza 2E10n: 12Pon en tu Navegador9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
} else { putserv "privmsg $chan :12$target Lo Siento, El Dj Actual No Tiene Un Apodo o Nickname habilitado" }
} else { putserv "privmsg $chan : 10L2o 10S2iento 12$target 10l2a 10R2adio 10E2sta 10E2n 10M2odo: 12Automatico :2(" }
}


proc msg_dj { nick uhost hand arg } { dj $nick"}
proc pub_dj { nick uhost hand chan arg } { global radiochans; if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1) || ($radiochans == "")} { dj $nick $chan }}



proc scstat {chan} {
global streamip streamport streampass
putlog "shoutcast: $chan pedido del Estado del servidor"
if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
putlog "error: $sockerror"
return 0 } else {
puts $sock "GET /admin.cgi?pass=$streampass&sid=1&mode=viewxml&page=0 HTTP/1.0"
puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
puts $sock "Host: $streamip"
puts $sock "Connection: close"
puts $sock ""
flush $sock
while {[eof $sock] != 1} {
set bl [gets $sock]
if { [string first "standalone" $bl] != -1 } {
set streamstatus [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]
set repl [string range $bl [shrink + 18 "<CURRENTLISTENERS>" 0 $bl] [shrink - 1 "</CURRENTLISTENERS>" 0 $bl]]
set curhigh [string range $bl [shrink + 15 "<PEAKLISTENERS>" 0 $bl] [shrink - 1 "</PEAKLISTENERS>" 0 $bl]]
set currentl [string range $bl [shrink + 18 "<CURRENTLISTENERS>" 0 $bl] [shrink - 1 "</CURRENTLISTENERS>" 0 $bl]]
set surl [string range $bl [shrink + 11 "<SERVERURL>" 0 $bl] [shrink - 1 "</SERVERURL>" 0 $bl]]
set maxl [string range $bl [shrink + 14 "<MAXLISTENERS>" 0 $bl] [shrink - 1 "</MAXLISTENERS>" 0 $bl]]
set bitrate [string range $bl [shrink + 9 "<BITRATE>" 0 $bl] [shrink - 1 "</BITRATE>" 0 $bl]]
set stitle [string range $bl [shrink + 13 "<SERVERTITLE>" 0 $bl] [shrink - 1 "</SERVERTITLE>" 0 $bl]]
set sgenre [string range $bl [shrink + 13 "<SERVERGENRE>" 0 $bl] [shrink - 1 "</SERVERGENRE>" 0 $bl]]
if {$sgenre != ""} {set sgenre " ($sgenre)"}
set avgtime [string range $bl [shrink + 13 "<AVERAGETIME>" 0 $bl] [shrink - 1 "</AVERAGETIME>" 0 $bl]]
set irc [string range $bl [shrink + 5 "<IRC>" 0 $bl] [shrink - 1 "</IRC>" 0 $bl]]
set icq [string range $bl [shrink + 5 "<ICQ>" 0 $bl] [shrink - 1 "</ICQ>" 0 $bl]]
if {$icq == 0} { set icq "N/A" }
set aim [string range $bl [shrink + 5 "<AIM>" 0 $bl] [shrink - 1 "</AIM>" 0 $bl]]
set webhits [string range $bl [shrink + 9 "<WEBHITS>" 0 $bl] [shrink - 1 "</WEBHITS>" 0 $bl]]
set streamhits [string range $bl [shrink + 12 "<STREAMHITS>" 0 $bl] [shrink - 1 "</STREAMHITS>" 0 $bl]]
set version [string range $bl [shrink + 9 "<VERSION>" 0 $bl] [shrink - 1 "</VERSION>" 0 $bl]]
if {$streamstatus == 1} {
if {[file exists dj]} {
set temp [open "dj" r]
set dj [gets $temp]
close $temp
} else { set dj "Automático" }
putserv ""
} else {
putserv "privmsg $chan : 12 $stitle$sgenre Actualmente 2ESTA APAGADA." }
#putserv "notice $target :Actualmente hay $repl Oyentes, La Capacidad maxima es $maxl, Total de Oyentes En la Radio fue de $curhigh oyentes."
#putserv "notice $target :El tiempo promedio de escucha es de $avgtime segundos, La Radio tiene $webhits webhits y $streamhits streamhits."
putserv "privmsg $chan : Si Nuestra Radio 2ESTA EN LINEA, Use 12!dj Para ver quien es actualmente el DJ."
}}
close $sock
}}


proc msg_scstat { nick uhost hand arg } { scstat $nick}
proc pub_scstat { nick uhost hand chan arg } { global radiochans; if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1) || ($radiochans == "")} { scstat $nick  }}


proc playing {target chan} {
global streamip streamport streampass dj
putlog "shoutcast: $target pedido la canción actual"
if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
putlog "error: $sockerror"
return 0 } else {
puts $sock "GET /admin.cgi?pass=$streampass&sid=1&mode=viewxml&page=0 HTTP/1.0"
puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
puts $sock "Host: $streamip"
puts $sock "Connection: close"
puts $sock ""
flush $sock
while {[eof $sock] != 1} {
set bl [gets $sock]
if { [string first "standalone" $bl] != -1 } {
set streamstatus [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]
set songtitle [string range $bl [shrink + 11 "<SONGTITLE" 0 $bl] [shrink - 1 "</SONGTITLE>" 0 $bl]]
set songurl [string range $bl [shrink + 9 "<SONGURL>" 0 $bl] [shrink - 1 "</SONGURL>" 0 $bl]]
if {$songurl != ""} { set songurl " ($songurl)"}
regsub -all "," $songtitle "," songtitle
regsub -all "<" $songtitle "<" songtitle
regsub -all ">" $songtitle ">" songtitle
regsub -all "&" $songtitle "\&" songtitle  
regsub -all """ $songtitle """ songtitle
regsub -all "'" $songtitle "'" songtitle
regsub -all "ÿ" $songtitle "ÿ" songtitle
regsub -all "i" $songtitle "i" songtitle
regsub -all "´" $songtitle "´" songtitle
regsub -all "&#x96;" $songtitle "-" songtitle
regsub -all "ö" $songtitle "ö" songtitle
regsub -all "ä" $songtitle "ä" songtitle
regsub -all "ü" $songtitle "ü" songtitle
regsub -all "Ö" $songtitle "Ö" songtitle
regsub -all "Ä" $songtitle "Ä" songtitle
regsub -all "Ü" $songtitle "Ü" songtitle
regsub -all "ß" $songtitle "ß" songtitle
regsub -all "é" $songtitle "é" songtitle
regsub -all "á" $songtitle "á" songtitle
regsub -all "ë" $songtitle "ë" songtitle
regsub -all "ñ" $songtitle "ñ" songtitle
regsub -all "{" $songtitle "" songtitle
regsub -all "}" $songtitle "" songtitle


if {$streamstatus == 1} {
putserv "privmsg $chan : 10E2mitiendo: 12 $dj 2C10ancion: 12 $songtitle 10S2intonizanos: 12Pon en tu Navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
#putserv "notice $target :Canción que suena es: 5$songtitle"
} elseif {$streamstatus == 0} {
putserv "privmsg $chan : 10A2ctualmente 10e2stá 2S10onando 10E2n 12Automatico: 12Pon en tu navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 "
} else {
putserv "privmsg $chan : El servidor es Actualmente Fuera de Línea *4APAGADO*, Lo Siento"
}}}
close $sock
}}

proc msg_playing { nick uhost hand arg } { playing $nick}
proc pub_playing { nick uhost hand chan arg } { global radiochans; if {([lsearch -exact [string tolower $radiochans] [string tolower $chan]] != -1) || ($radiochans == "")} { playing $nick $chan }}



proc isonline { nick uhost hand chan arg } {
global radiochans otrachans otrachan announce tellusers tellsongs tellbitrate urltopic dj
global offlinetext offlinetopic onlinetext onlinetopic
global streamip streampass streamport dj
global doalertadmin alertadmin

if {$announce == 1 || $tellsongs == 1 || $tellusers == 1 || $tellbitrate == 1} {
set isonlinefile "isonline"
set oldisonline "isonline: 0"
set oldcurlist "curlist: 0"
set oldcurhigh "curhigh: 0"
set oldsong "cursong: 0"
set oldbitrate "bitrate: 0"
if {[file exists $isonlinefile]} {
#putlog "shoutcast: Comprobando si El Enlace está en LINEA"
set temp [open "isonline" r]
while {[eof $temp] != 1} {
set zeile [gets $temp]
if {[string first "isonline:" $zeile] != -1 } { set oldisonline $zeile }
if {[string first "curlist:" $zeile] != -1 } { set oldcurlist $zeile }
if {[string first "curhigh:" $zeile] != -1 } { set oldcurhigh $zeile }
if {[string first "cursong:" $zeile] != -1 } { set oldsong $zeile }
if {[string first "bitrate:" $zeile] != -1 } { set oldbitrate $zeile }
}
close $temp
}


if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
putlog "error: $sockerror"
return 0} else {
puts $sock "GET /admin.cgi?pass=$streampass&sid=1&mode=viewxml&page=0 HTTP/1.0"
puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
puts $sock "Host: $streamip"
puts $sock "Connection: close"
puts $sock ""
flush $sock
while {[eof $sock] != 1} {
set bl [gets $sock]
if { [string first "standalone" $bl] != -1 } {
set streamstatus "isonline: [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]"
set repl "curlist: [string range $bl [shrink + 18 "<CURRENTLISTENERS>" 0 $bl] [shrink - 1 "</CURRENTLISTENERS>" 0 $bl]]"
set curhigh "curhigh: [string range $bl [shrink + 15 "<PEAKLISTENERS>" 0 $bl] [shrink - 1 "</PEAKLISTENERS>" 0 $bl]]"
set currentl [string range $bl [shrink + 18 "<CURRENTLISTENERS>" 0 $bl] [shrink - 1 "</CURRENTLISTENERS>" 0 $bl]]
set surl "serverurl: [string range $bl [shrink + 11 "<SERVERURL>" 0 $bl] [shrink - 1 "</SERVERURL>" 0 $bl]]"
set cursong "cursong: [string range $bl [shrink + 11 "<SONGTITLE" 0 $bl] [shrink - 1 "</SONGTITLE>" 0 $bl]]"
set songurl [string range $bl [shrink + 9 "<SONGURL>" 0 $bl] [shrink - 1 "</SONGURL>" 0 $bl]]
set bitrate "bitrate: [string range $bl [shrink + 9 "<BITRATE>" 0 $bl] [shrink - 1 "</BITRATE>" 0 $bl]]"
set stitle "stitle: [string range $bl [shrink + 13 "<SERVERTITLE>" 0 $bl] [shrink - 1 "</SERVERTITLE>" 0 $bl]]"
set sgenre "sgenre: [string range $bl [shrink + 13 "<SERVERGENRE>" 0 $bl] [shrink - 1 "</SERVERGENRE>" 0 $bl]]"
}}
close $sock
}

set temp [open "isonline" w+]
puts $temp "$streamstatus\n$repl\n$curhigh\n$cursong\n$bitrate\n$stitle\n$sgenre\n$surl"
close $temp
if {$announce == 1 } {
if {$streamstatus == "isonline: 0" && $oldisonline == "isonline: 1"} {
       poststuff privmsg $offlinetext
       if {$doalertadmin == "1"} { sendnote domsen $alertadmin "La radio Esta Ahora APAGADA" }
#if {$urltopic == 1} { poststuff topic $offlinetopic }
}
if {$streamstatus == "isonline: 1" && $oldisonline == "isonline: 0" } {
if {$sgenre != ""} {
set sgenre " ([lrange $sgenre 1 [llength $sgenre]] )"
}
poststuff privmsg "$onlinetext"
#if {$urltopic == 1} { poststuff topic "$onlinetopic" }
}}
if {($tellusers == 1) && ($streamstatus == "isonline: 1") && ($oldcurhigh != "curhigh: 0") } {
if {$oldcurhigh != $curhigh} {
poststuff privmsg ""
#poststuff privmsg "Posibles Oyentes: [lindex $curhigh 1]"
}
if {$oldcurlist != $repl} {
poststuff privmsg ""
#poststuff privmsg " Actualmente hay : 4 [lindex $repl 1] ($currentl)  Oyentes"
}}
if {($tellsongs == 1) && ($oldsong != $cursong) && ($streamstatus == "isonline: 1") } {
if {$songurl != ""} { set songurl "($songurl)"}
regsub -all "," $cursong "," cursong
regsub -all "<" $cursong "<" cursong
regsub -all ">" $cursong ">" cursong
regsub -all "&" $cursong "\&" cursong
regsub -all """ $cursong """ cursong
regsub -all "'" $cursong "'" cursong
regsub -all "ÿ" $cursong "ÿ" cursong
regsub -all "´" $cursong "´" cursong
regsub -all "i" $cursong "i" cursong
regsub -all "&#x96;" $cursong "-" cursong
regsub -all "ö" $cursong "ö" cursong
regsub -all "ä" $cursong "ä" cursong
regsub -all "ü" $cursong "ü" cursong
regsub -all "Ö" $cursong "Ö" cursong
regsub -all "Ä" $cursong "Ä" cursong
regsub -all "Ü" $cursong "Ü" cursong
regsub -all "ß" $cursong "ß" cursong
regsub -all "é" $cursong "é" cursong
regsub -all "á" $cursong "á" cursong
regsub -all "ë" $cursong "ë" cursong
regsub -all "ñ" $cursong "ñ" cursong
regsub -all "{" $cursong "" cursong
regsub -all "}" $cursong "" cursong

putlog $cursong
putserv "privmsg $otrachans 12Pon en tu Navegador 9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 10D2j: 12 $dj 10C2ancion 10A2ctual:12 [lrange $cursong 1 [llength $cursong]]"

putserv "privmsg $otrachan 2Emitiendo 10D2j: 12 $dj 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 10C2ancion 10A2ctual:12 [lrange $cursong 1 [llength $cursong]]"

#poststuff privmsg "1Quieres Escuchar La Radio  12Pon en tu Navegador9: 2 http://123.456.789.11:1234/widgets/player/dj/?p=5678 ... La Actual Canción es: 4 [lrange $cursong 1 [llength $cursong]] .. Para Ver Comandos de la Radio Teclea 6!comandos "
}

if {($tellbitrate == 1) && ($oldbitrate != $bitrate) && ($streamstatus == "isonline: 1") && ($oldbitrate != "bitrate: 0")} {
poststuff privmsg "Calidad Sonido a [lindex $bitrate 1]kbps"
}}}

putlog "Cargado shoutcast Correctamente" 
now what my shoutcast panel sends both:
Transmission statistics: XML , JSON , JSON-PAGS
to enter the XML file the link is like this:
http://123.456.789.11:1234/stats?sid=1& ... 5678995124

this is what the XML file returns:

Code: Select all

<SHOUTCASTSERVER>
<CURRENTLISTENERS>0</CURRENTLISTENERS>
<PEAKLISTENERS>5</PEAKLISTENERS>
<MAXLISTENERS>100</MAXLISTENERS>
<UNIQUELISTENERS>0</UNIQUELISTENERS>
<AVERAGETIME>0</AVERAGETIME>
<SERVERGENRE>various</SERVERGENRE>
<SERVERGENRE2/>
<SERVERGENRE3/>
<SERVERGENRE4/>
<SERVERGENRE5/>
<SERVERURL>clientradiourl.com</SERVERURL>
<SERVERTITLE>AutoDJ Stream</SERVERTITLE>
<SONGTITLE>La Sonora Santanera - Amor de Cabaret</SONGTITLE>
<STREAMHITS>52</STREAMHITS>
<STREAMSTATUS>1</STREAMSTATUS>
<BACKUPSTATUS>0</BACKUPSTATUS>
<STREAMLISTED>0</STREAMLISTED>
<STREAMLISTEDERROR>200</STREAMLISTEDERROR>
<STREAMSOURCE>127.0.0.1</STREAMSOURCE>
<STREAMPATH>/stream</STREAMPATH>
<STREAMUPTIME>245357</STREAMUPTIME>
<BITRATE>128</BITRATE>
<SAMPLERATE>44100</SAMPLERATE>
<CONTENT>audio/mpeg</CONTENT>
<VERSION>2.5.5.733 (posix(linux x64))</VERSION>
</SHOUTCASTSERVER> 
to enter the JSON file the link is like this:
http://123.456.789.11:1234/stats?sid=1& ... 124&json=1
this is what the JSON file returns:

Code: Select all

 {"currentlisteners":0,"peaklisteners":5,"maxlisteners":100,"uniquelisteners":0,"averagetime":0,"servergenre":"various","servergenre2":"","servergenre3":"","servergenre4":"","servergenre5":"","serverurl":"clientradiourl.com","servertitle":"AutoDJ Stream","songtitle":"Justin Quiles x Chimbala x Zion y Lennox - Loco","streamhits":52,"streamstatus":1,"backupstatus":0,"streamlisted":0,"streamlistederror":200,"streamsource":"127.0.0.1","streampath":"\/stream","streamuptime":244458,"bitrate":"128","samplerate":"44100","content":"audio\/mpeg","version":"2.5.5.733 (posix(linux x64))"} 
to enter the JSON-PAGS file the link is like this:
http://123.456.789.11:1234/stats?sid=1& ... lback=func
this is what the JSON-PAGS file returns:

Code: Select all

 func({"currentlisteners":0,"peaklisteners":5,"maxlisteners":100,"uniquelisteners":0,"averagetime":0,"servergenre":"various","servergenre2":"","servergenre3":"","servergenre4":"","servergenre5":"","serverurl":"clientradiourl.com","servertitle":"AutoDJ Stream","songtitle":"K-Narias - Ya No Me Acuerdo de Ti","streamhits":52,"streamstatus":1,"backupstatus":0,"streamlisted":0,"streamlistederror":200,"streamsource":"127.0.0.1","streampath":"\/stream","streamuptime":244962,"bitrate":"128","samplerate":"44100","content":"audio\/mpeg","version":"2.5.5.733 (posix(linux x64))"}) 
I would be very grateful if you could help me with the correction of errors with the ñ, symbols and others, thank you very much.
PS: if you need any more information to clarify the problem I will be happy to give it to you.


good
as usual and good ways to contribute so that you can continue to help as those who I am learning, after giving a thousand turns I came up with the solution that I need the messages come out with their accents, the ñ, and other forms, I leave the solution for which you aga lack and thus contribute to this does not decline and thus continue to learn from others
I would like to thank you again very much

in this part of the code

Code: Select all

 proc playing {target chan} {
global streamip streamport streampass dj
putlog "shoutcast: $target pedido la canción actual"
if {[catch {set sock [socket $streamip $streamport] } sockerror]} {
putlog "error: $sockerror"
return 0 } else {
puts $sock "GET /admin.cgi?pass=$streampass&sid=1&mode=viewxml&page=0 HTTP/1.1"
puts $sock "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.9)"
puts $sock "Host: $streamip"
puts $sock "Connection: close"
puts $sock ""
flush $sock
while {[eof $sock] != 1} {
set bl [gets $sock]
if { [string first "standalone" $bl] != -1 } {
set streamstatus [string range $bl [shrink + 14 "<STREAMSTATUS>" 0 $bl] [shrink - 1 "</STREAMSTATUS>" 0 $bl]]
set songtitle [string range $bl [shrink + 11 "<SONGTITLE" 0 $bl] [shrink - 1 "</SONGTITLE>" 0 $bl]]
set songurl [string range $bl [shrink + 9 "<SONGURL>" 0 $bl] [shrink - 1 "</SONGURL>" 0 $bl]]
if {$songurl != ""} { set songurl "($songurl)"} 
as last line add this

Code: Select all

 set songtitle [encoding convertfrom utf-8 [string map {"&" "&"} $songtitle]] 
Mi ingles: no es el mejor, Manda el traductor... :)
Post Reply