Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 22.15 KB | None | 0 0
  1. /*
  2. Version: 1.11
  3. Date: 16/06/2011
  4. */
  5. alias rlv { return $gettok($read($script,2),2,32) }
  6. alias -l rl {
  7.   if ($regex($1,/Wessie|Skye`Rackloy|Suou/i)) { return 1 }
  8.   else { return 0 }
  9. }
  10.  
  11. on *:LOAD: {
  12.   if (!$hget(r-a-dio)) {
  13.     hmake r-a-dio
  14.     if ($exists(r-a-dio.hsh)) {
  15.       hload r-a-dio r-a-dio.hsh
  16.     }
  17.     else {
  18.       hadd r-a-dio logfile r-a-dio_log.txt
  19.     }
  20.   }
  21. }
  22. on *:EXIT: { hsave radio radio.hsh | hsave tags tags.bin }
  23. on *:UNLOAD: {
  24.   sockclose stream_
  25.   hsave radio radio.hsh
  26.   if (!%update_radio) {
  27.     hfree radio
  28.     .timerstream off
  29.     .timerLPhash off
  30.     unset %radio.*
  31.   }
  32. }
  33.  
  34. /*
  35. # Module: stream_socket
  36. # Commands: [/] radiostream, [/] radiocheck, [/] showerror
  37. # Usage: /radiostream, /radiocheck, /showerror error_message
  38. # Info: Main Module of the script, don't disable.
  39. */
  40. #stream_socket on
  41. alias radiostream {
  42.   if ($hget(stream_)) { hfree stream_ }
  43.   hadd -m stream_ address shoutcast1.rootnode.net
  44.   hadd stream_ state first
  45.   hadd stream_ status trying
  46.   sockopen stream_ shoutcast1.rootnode.net 1130
  47.   if (!$timer(stream)) { .timerstream -o 0 20 radiocheck }
  48.   echo -a Opening socket to stream.
  49. }
  50. alias radiocheck {
  51.   if (!$sock(stream_)) {
  52.     radiostream
  53.   }
  54. }
  55. on *:sockopen:stream*:{
  56.   var %id = $sockname
  57.   echo -a $hget(%id,address)
  58.   if (!$sockerr) {
  59.     sockwrite -n $sockname GET / HTTP/1.1
  60.     sockwrite -n $sockname Host: $hget(%id,address)
  61.     sockwrite -n $sockname icy-metadata:1
  62.     sockwrite $sockname $crlf
  63.     echo -a Write to socket complete.
  64.   }
  65.   else { showerror Could not connect to stream! }
  66. }
  67. on *:sockclose:stream*: { radiostream | .timerweb_send off }
  68. on *:sockread:stream*:{
  69.   var %id = $sockname, %state = $hget(%id,state), %read
  70.   if (!$timer(web_send)) { .timerweb_send 0 50 radio.listeners web_send }
  71.   if (%state == data) {
  72.     var %meta = $hget(%id,icy-metaint)
  73.     if (%meta) {
  74.       var %read $hget(%id,read)
  75.       sockread %read &data
  76.       if ($sockbr == %read) { hadd %id state meta }
  77.       else { hadd %id read $calc(%read - $sockbr) }
  78.     }
  79.   }
  80.   elseif (%state == meta) {
  81.     var %metalen $hget(%id,metalen)
  82.     if (!%metalen) {
  83.       sockread 1 &byte
  84.       var %metalen = $calc($bvar(&byte,1,1) * 16)
  85.       if (%metalen == 0) {
  86.         hadd %id state data
  87.         hadd %id read $hget(%id,icy-metaint)
  88.       }
  89.       else { hadd %id metalen %metalen }
  90.     }
  91.     else {
  92.       sockread %metalen &read
  93.       if ($bvar(&read,0) >= 750) { sockclose stream_ | radiostream | echo -a LOL'D | halt }
  94.       var %read $+($hget(%id,metadata),$bvar(&read,1,$bvar(&read,0)).text)
  95.       if (%metalen == $sockbr) {
  96.         var %p = $calc($regex(%read,/[\W_]/g) / $len(%read))
  97.         if (%p > 0.75) { showerror Bugged stream detected - stream closed }
  98.         noop $regex(tags, %read,/.*Streamtitle='(.*)';StreamUrl='(.*)';/i)
  99.         hadd %id StreamUrl $regml(2)
  100.         ;echo -s Hello: $+(',$unescapehtml($regml(tags, 1)),') * $hget(%id,StreamTitle)
  101.         if ($+(',$unescapehtml($regml(tags, 1)),') != $hget(%id,StreamTitle)) { hadd %id OldStreamTitle $hget(%id,StreamTitle) }
  102.         hadd %id StreamTitle $+(',$unescapehtml($regml(tags, 1)),')
  103.         hadd %id read $hget(%id,icy-metaint)
  104.         hadd %id metalen $null
  105.         hadd %id state data
  106.         if ($+(',$regml(tags, 1),') != $hget(%id,OldStreamTitle)) { radio.next %read }
  107.       }
  108.       else {
  109.         hadd %id metadata %read
  110.         hadd %id metalen $calc(%metalen - $sockbr)
  111.       }
  112.     }
  113.   }
  114.   elseif (%state == header) {
  115.     sockread %read
  116.     if ($len(%read) == 0) {
  117.       var %content = $hget(%id,content-type),%ext
  118.       if (%content == audio/aacp) { %ext = .aac }
  119.       elseif (%content == audio/mpeg) { %ext = .mp3 }
  120.       elseif (%content == video/nsv) { %ext = .nsv }
  121.       else { %ext = .dat }
  122.       hadd %id ext %ext
  123.       if ($hget(%id,icy-metaint)) { hadd %id read $v1 }
  124.       else {
  125.         var %f = $+($options().output,$filter($hget(%id,icy-name)),%ext)
  126.         hadd %id file $qt(%f)
  127.       }
  128.       hadd %id state data
  129.       hadd %id status streaming
  130.     }
  131.     else {
  132.       var %param = $gettok(%read,1,58),%value = $gettok(%read,2-,58)
  133.       if ($istok(icy-name|icy-genre|icy-url|icy-metaint|icy-br|content-type,%param,124)) { hadd %id %param %value }
  134.     }
  135.   }
  136.   elseif (%state == first) {
  137.     sockread %read
  138.     var %code = $gettok(%read,2,32),%info = $gettok(%read,3-,32)
  139.     if (%code != 200) {
  140.       showerror $iif(%info,Could not connect to stream: %info,Could not connect: Unexpected server response)
  141.       sockclose stream_
  142.     }
  143.     else { hadd %id state header | echo -a Socket connected to stream. }
  144.   }
  145. }
  146. alias -l showerror { echo $color(info) -ag Streamer: $$1- }
  147. #stream_socket end
  148.  
  149.  
  150. /*
  151. # [OLD]
  152. # Module: radio.next
  153. # Commands: [/] radio.next, [/] radio.lp, [/] radio.add
  154. # Usage: /radio.next, /radio.lp last_song, /radio.add duration_of_song title_of_song
  155. # Info: Handler of starting songs and creator of announce event, don't disable.
  156. */
  157. #radio.next on
  158. alias radio.next {
  159.   ; Update listener count
  160.   ;radio.listeners
  161.   ; Increase 'now starting' announce variable
  162.   inc %radio.announce
  163.   ; Record ending time of last song
  164.   set %radio.end $ctime
  165.   ; Print out debugging information
  166.   echo -s Saved: $hget(stream_,OldStreamTitle) $duration($calc(%radio.end - %radio.start)) $sha1($hget(stream_,OldStreamTitle))
  167.   ; Call .lp to save last song in database
  168.   radio.lp $hget(stream_,OldStreamTitle)
  169.   web_send_data lp $hget(stream_,OldStreamTitle)
  170.   web_send_data np %radio.listeners %radio.kbps $hget(stream_,StreamTitle)
  171.   .timerweb_send 0 40 radio.listeners web_send
  172.   ; Call .add to save duration of last song in database
  173.   radio.add $calc(%radio.end - %radio.start) $hget(stream_,OldStreamTitle)
  174.   ; Record starting time for next song
  175.   set %radio.start $ctime
  176.   ; Call _stream_tags to check for updated tags
  177.   radio_stream_tags
  178.   if (%radio.announce >= $a_active) && (%radio.active) {
  179.     if ($hget(radio,$sha1($hget(stream_,StreamTitle)))) { var %radio.total = $gettok($ifmatch,1,59), %radio.last = $gettok($ifmatch,2,59) }
  180.     else { var %radio.total = ?, %radio.last = ? }
  181.     var %radio.now $calc($ctime - %radio.start)
  182.     write radiostarting.txt Now starting:04 $hget(stream_,StreamTitle) $+([,$format(%radio.now,2),/,$format(%radio.total,2),]) $+($chr(40),%radio.listeners,/,%radio.max,$chr(41)) 04LP: $lpmessage(%radio.last)
  183.     msg #r/a/dio Now starting:04 $hget(stream_,StreamTitle) $+([,$format(%radio.now,2),/,$format(%radio.total,2),]) $+($chr(40),%radio.listeners,/,%radio.max,$chr(41)) 04LP: $lpmessage(%radio.last)
  184.     unset %radio.announce
  185.   }
  186. }
  187. alias -l radio.lp {
  188.   set %radio.lp5 %radio.lp4
  189.   set %radio.lp4 %radio.lp3
  190.   set %radio.lp3 %radio.lp2
  191.   set %radio.lp2 %radio.lp1
  192.   set %radio.lp1 $ctime $1-
  193. }
  194. alias radio.add {
  195.   if (!$hget(radio)) {
  196.     hmake radio 100
  197.     if ($exists(radio.hsh)) { hload radio radio.hsh }
  198.   }
  199.   hadd radio $sha1($2-) $+($1,;,$ctime)
  200. }
  201. #radio.next end
  202.  
  203.  
  204. /*
  205. # Module: last_played
  206. # Command: [$] hc
  207. # Info: Last played event handler.
  208. */
  209. #last_played on
  210. alias -l hc { return $+($chr(40),$1,$2,$chr(41)) }
  211. on $*:TEXT:/^[!.@]lp/i:#r/a/dio: {
  212.   if (%radio.active) {
  213.     var %t1 = $hc($round($calc(($ctime - $gettok(%radio.lp1,1,32)) / 60),0),min) $+(04,$gettok(%radio.lp1,2-,32)) $+(03,|)
  214.     var %t2 = $hc($round($calc(($ctime - $gettok(%radio.lp2,1,32)) / 60),0),min) $+(04,$gettok(%radio.lp2,2-,32)) $+(03,|)
  215.     var %t3 = $hc($round($calc(($ctime - $gettok(%radio.lp3,1,32)) / 60),0),min) $+(04,$gettok(%radio.lp3,2-,32)) $+(03,|)
  216.     var %t4 = $hc($round($calc(($ctime - $gettok(%radio.lp4,1,32)) / 60),0),min) $+(04,$gettok(%radio.lp4,2-,32)) $+(03,|)
  217.     var %t5 = $hc($round($calc(($ctime - $gettok(%radio.lp5,1,32)) / 60),0),min) $+(04,$gettok(%radio.lp5,2-,32))
  218.  
  219.     msg $chan Last played: %t1 %t2 %t3 %t4 %t5
  220.   }
  221. }
  222. #last_played end
  223.  
  224.  
  225. /*
  226. # Module: now_playing
  227. # Commands: None
  228. # Info: Now playing event handler. Don't disable, instead use build-in commands.
  229. */
  230. #now_playing on
  231. on $*:TEXT:/^[!.@]np/i:#r/a/dio: {
  232.   if (!$timer(LPhash)) || (!$timer(tags)) { .timerLPhash 0 1800 hsave radio radio.hsh | .timerTAGS 0 1800 hsave tags tags.bin }
  233.  
  234.   var %md5 = $iif($2 == $md5($ip),1,$iif($2 == $me,1,0))
  235.   if (%md5) && ($rl($nick)) && ($3) {
  236.     if ($3 == set) && ($4 isnum) { set %radio.announce.wait $4 | .msg $chan Set announce to every %radio.announce.wait song(s). }
  237.     elseif ($3 == option) && ($regex($4,/(enable|disable)/i)) { set %radio.active $iif($4 == enable,1,0) | .msg $chan $iif(%radio.active,Enabled,Disabled) now playing trigger. }
  238.     elseif ($3 == restart) {
  239.       sockclose stream_
  240.       radiostream
  241.       .notice $nick The stream on client $md5($ip) has restarted.
  242.     }
  243.     elseif ($3 == shutdown) {
  244.       sockclose stream_
  245.       if ($hget(radio)) {
  246.         hsave radio radio.hsh
  247.         hfree radio
  248.       }
  249.       set %radio.online 0
  250.       .timerstream off
  251.       .notice $nick Stream connection shutdown confirmed.
  252.     }
  253.     elseif ($3 == start) {
  254.       radiostream
  255.       if (!$hget(radio)) {
  256.         hmake radio 100
  257.         if ($exists(radio.hsh)) { hload radio radio.hsh }
  258.       }
  259.       set %radio.online 1
  260.       .notice $nick Stream connection is being estabilished.
  261.     }
  262.     elseif ($3 == status) {
  263.       .notice $nick Status report: $iif($sock(stream_),03,04) Connected | $iif(%radio.active,03,04) Trigger | $iif(%radio.online,03,04) Connect attempt
  264.     }
  265.   }  
  266.   elseif ($2 == version) { .notice $nick Using version $rlv of RadioStream }
  267.   elseif ($sock(stream_)) {
  268.     if (%md5) {
  269.       radio.listeners
  270.       if ($hget(radio,$sha1($hget(stream_,StreamTitle)))) { var %radio.total = $gettok($ifmatch,1,59), %radio.last = $gettok($ifmatch,2,59) }
  271.       else { var %radio.total = ?, %radio.last = ? }    
  272.       var %radio.now $calc($ctime - %radio.start)
  273.       msg $chan Now playing:04 $hget(stream_,StreamTitle) $+([,$format(%radio.now,2),/,$format(%radio.total,2),]) $+($chr(40),%radio.listeners,/,%radio.max,$chr(41)) 04LP: $lpmessage(%radio.last)
  274.     }
  275.     elseif ($2 == debug) { msg #r/a/dio Debug: %radio.announce - $a_active }
  276.     elseif ($2 == hash) && ($rl($nick)) { .notice $nick Hash for this client is: $md5($ip) }
  277.     elseif (%radio.active) && (!$2) {
  278.       radio.listeners
  279.       if ($hget(radio,$sha1($hget(stream_,StreamTitle)))) { var %radio.total = $gettok($ifmatch,1,59), %radio.last = $gettok($ifmatch,2,59) }
  280.       else { var %radio.total = ?, %radio.last = ? }    
  281.       var %radio.now $calc($ctime - %radio.start)
  282.       msg $chan Now playing:04 $hget(stream_,StreamTitle) $+([,$format(%radio.now,2),/,$format(%radio.total,2),]) $+($chr(40),%radio.listeners,/,%radio.max,$chr(41)) 04LP: $lpmessage(%radio.last)
  283.     }
  284.   }
  285.   elseif (%radio.online) {
  286.     msg $chan Stream connection is down, trying to reconnect.
  287.     set %radio.announce %radio.announce.wait
  288.     radiostream
  289.   }
  290. }
  291. alias lpmessage {
  292.   if ($1 == ?) { return Never played before. }
  293.   else { return $replacex($duration($calc($ctime - $1)),wks,w,wk,w,days,d,day,d,hrs,h,hr,h,mins,m,min,m,secs,s,sec,s) ago. }
  294. }
  295. #now_playing end
  296.  
  297.  
  298. /*
  299. # [OLD]
  300. # Module: radio.listeners
  301. # Commands: [/] radio.listeners
  302. # Usage: /radio.listeners
  303. # Info: Updates the listener count used by the now_playing component.
  304. */
  305. #radio.listeners on
  306. alias radio.listeners {
  307.   if ($1 == web_send) { set %radio_listeners_do web_send }
  308.   if (!$sock(radio.listeners)) { sockopen radio.listeners shoutcast1.rootnode.net 1130 }
  309. }
  310. on *:SOCKOPEN:radio.listeners: {
  311.   sockwrite -nt $sockname GET /7.html HTTP/1.0
  312.   sockwrite -nt $sockname User-Agent: Mozilla
  313.   sockwrite -nt $sockname Host: shoutcast1.rootnode.net:1130
  314.   sockwrite -nt $sockname $crlf
  315. }
  316. on *:SOCKREAD:radio.listeners: {
  317.   sockread &radio.t
  318.   var %bg = $xbfind(&radio.t,4,>).end, %ng = $xbfind(&radio.t,$calc($xbfind(&radio.t,0,<) - 1),<), %radio.lrg = $bvar(&radio.t,%bg,$calc(%ng - %bg)).text
  319.   set %radio.listeners $gettok(%radio.lrg,1,44)
  320.   set %radio.max $gettok(%radio.lrg,4,44)
  321.   set %radio.kbps $gettok(%radio.lrg,6,44)
  322. }
  323. on *:SOCKCLOSE:radio.listeners: {
  324.   if (%radio_listeners_do == web_send) {
  325.     web_send_data np %radio.listeners %radio.kbps
  326.     unset %radio_listeners_do
  327.   }
  328. }
  329. alias -l xbfind {
  330.   if ($3 isalpha) { bset -t &xbfindtemp 1 $3 }
  331.   elseif ($prop == .text) { bset -t &xbfindtemp 1 $3 }
  332.   elseif ($prop == .textend) { bset -t &xbfindtemp 1 $3 }
  333.   else { bset &xbfindtemp 1 $3 }
  334.   var %xb.m $bvar(&xbfindtemp,1,$bvar(&xbfindtemp,0))
  335.   if ($2 == 0) {
  336.     if ($bvar($1,0)) {
  337.       var %xb.t = 0, %xb.p = 1
  338.       while ($bfind($1, %xb.p, %xb.m)) {
  339.         var %xb.p $ifmatch
  340.         inc %xb.p
  341.         inc %xb.t
  342.       }
  343.       return %xb.t
  344.     }
  345.   }
  346.   else {
  347.     if ($bvar($1,0)) {
  348.       var %xb.t = 0, %xb.p = 1, %xb.r
  349.       while ($bfind($1, %xb.p, %xb.m)) {
  350.         var %xb.p $ifmatch
  351.         inc %xb.t
  352.         if (%xb.t == $2) { var %xb.r %xb.p | break }
  353.         inc %xb.p
  354.       }
  355.       if ($prop == end) { return $calc(%xb.r + $numtok(%xb.m,32)) }
  356.       if ($prop == textend) { return $calc(%xb.r + $numtok(%xb.m,32)) }
  357.       return %xb.r
  358.     }
  359.   }
  360. }
  361. #radio.listeners end
  362.  
  363.  
  364. /*
  365. # Module: html_free
  366. # Commands: [$] html_free
  367. # Usage: $html_free(text_to_free_from_html)
  368. # Info: Removes any html tags and anything inbetween tags.
  369. */
  370. #html_free on
  371. alias html_free {
  372.   var %x, %i = $regsub($1-,/(^[^<]*>|<[^>]*>|<[^>]*$)/g,$null,%x), %x = $remove(%x, )
  373.   return %x
  374. }
  375. #html_free end
  376.  
  377.  
  378. /*
  379. # Module: format
  380. # Commands: [$] format
  381. # Usage: $format(number_to_format)
  382. # Info: Returns number_to_format in a human readable time format.
  383. */
  384. #format on
  385. alias format {
  386.   if ($1 isnum) {
  387.     var %t $1
  388.     var %h $int($calc(%t / 3600))
  389.     if (!%h) { var %h 00 }
  390.     dec %t $calc(%h * 3600)
  391.     var %n $int($calc(%t / 60))
  392.     if (!%n) { var %n 00 }
  393.     dec %t $calc(%n * 60)
  394.     if (!%t) { var %t 00 }
  395.     return $iif($2 != 2,$iif(%h,$iif(%h < 10,$+(0,%h),%h),00) $+ :) $+ $iif(%n,$iif(%n < 10,$+(0,%n),%n),00) $+ : $+ $iif(%t,$iif(%t < 10,$+(0,%t),%t),00)
  396.   }
  397.   else { return $1 }
  398. }
  399. #format end
  400.  
  401. /*
  402. # Module: tags_extension
  403. # Usage: None
  404. # Info: Users with access can change tags of the stream, these will be saved
  405. for next time the same tags come up. ([!tags help] for Users)
  406. */
  407. #tags_extension on
  408. alias tagaccess {
  409.   if (!%tagaccess) { set %tagaccess Wessie Skye`Rackloy }
  410.   if ($nick isin %tagaccess) { return 1 }
  411.   else { return 0 }
  412. }
  413. on $*:TEXT:/^[!.@^]tags/i:#r/a/dio: {
  414.   var %tagCommand = $2
  415.   if ($tagaccess($nick)) {
  416.     if (%tagCommand == Help) {
  417.       .notice $nick Help available at "PASTEBIN LINK TROLOLO".
  418.     }
  419.     elseif ($regex(%tagCommand,/(SET|ADD)/i)) {
  420.       var %tagHash = $3, %tagMeta = $4-
  421.       var %tagRegex = /[a-f0-9]{40}/
  422.       if ($regex(%tagHash,%tagRegex)) {
  423.         if (%tagMeta) {
  424.           tags_add %tagHash %tagMeta
  425.           .notice $nick Added: $hget(stream_,StreamTitle) -> %tagMeta
  426.         }
  427.       }
  428.       elseif (%tagHash == Current) {
  429.         if (%tagMeta) {
  430.           var %tagHash = $sha1($hget(stream_,StreamTitle))
  431.           tags_add %tagHash %tagMeta
  432.           .notice $nick Added: $hget(stream_,StreamTitle) -> %tagMeta
  433.           radio_stream_tags
  434.         }
  435.       }
  436.       else {
  437.         .notice $nick Invalid hash, not a valid sha1 hash. Use "!tag hash <originaltag>" to get the sha1 hash.
  438.       }
  439.     }
  440.     elseif ($regex(%tagCommand,/(DEL|REMOVE)/i)) {
  441.       var %tagHash = $3
  442.       var %tagRegex = /[a-f0-9]{40}/
  443.       if ($regex(%tagHash,%tagRegex)) {
  444.         tags_del %taghash
  445.         .notice $nick Deleted %taghash
  446.       }
  447.       elseif ($regex(%tagHash,/(CURRENT)/i)) {
  448.         tags_del %tags_current
  449.         .notice $nick Deleted %tags_current
  450.       }
  451.     }
  452.     elseif ($regex(%tagCommand,/(HASH)/i)) {
  453.       var %tagMeta = $3-
  454.       .notice $nick Hash: %tagMeta -> $sha1(%tagMeta)
  455.     }
  456.     elseif (%tagCommand == User) && ($3 == add) {
  457.       if ($nick == Wessie) {
  458.         set %tagaccess %tagaccess $4
  459.       }
  460.     }
  461.     elseif (%tagCommand == change) && ($nick == Wessie) {
  462.       streamTags $3-
  463.       .notice $nick Taggie
  464.     }
  465.     else {
  466.       .notice $nick Well that isn't a command now is it.
  467.     }
  468.   }
  469. }
  470. alias tags_del {
  471.   var %tagHash = $1
  472.   if ($hget(tags,%taghash)) {
  473.     hdel tags %taghash
  474.   }
  475. }
  476. alias tags_add {
  477.   var %tagHash = $1, %tagMeta = $2-
  478.   if (!$hget(tags)) {
  479.     hmake tags 600
  480.     if ($exists(tags.bin)) {
  481.       hload tags tags.bin
  482.     }
  483.   }
  484.   hadd tags %tagHash %tagMeta
  485. }
  486. alias streamTags {
  487.   if ($sock(Tags_stream)) { sockclose Tags_stream }
  488.   set %tags_meta $url_Encode($1-)
  489.   sockopen Tags_stream shoutcast1.rootnode.net 1130
  490. }
  491. on *:SOCKOPEN:Tags_stream: {
  492.   sockwrite -nt $sockname GET /admin.cgi?mode=updinfo&charset=UTF-8&song= $+ %tags_meta HTTP/1.1
  493.   sockwrite -nt $sockname Host: shoutcast1.rootnode.net
  494.   sockwrite -nt $sockname User-Agent: Mozilla/5.0
  495.   sockwrite -nt $sockname Authorization: Basic %tags_auth
  496.   sockwrite -nt $sockname $crlf
  497. }
  498. on *:SOCKREAD:Tags_stream: {
  499.   sockclose $sockname
  500. }
  501. alias radio_stream_tags {
  502.   var %tags_sha1 = $sha1($hget(stream_,StreamTitle))
  503.   var %tags_tags = $hget(tags,%tags_sha1)
  504.   if (%tags_tags) {
  505.     echo -s Tags: Old -> %tags_tags
  506.     set %tags_current %tags_sha1
  507.     hadd stream_ StreamTitle %tags_tags
  508.     streamTags %tags_tags
  509.   }
  510. }
  511. #tags_extension end
  512.  
  513.  
  514. /*
  515. # Module: [$] url_encode
  516. # Usage: $url_encode(text_to_encode)
  517. # Info: Returns html encoded text_to_encode.
  518. */
  519. #url_encode on
  520. alias -l Url_Encode { return $regsubex($1-,/([^\d\w])/g,$+(%,$base($asc(\t),10,16))) }
  521. #url_encode end
  522.  
  523.  
  524. /*
  525. # Module: [$] a
  526. # Usage: $a
  527. # Info: Returns int that remembles the amount of song
  528. that should be played before announcing again.
  529. */
  530. #activity_tracker on
  531. on $*:TEXT:/^.{5}/:#r/a/dio: {
  532.   a_count
  533.   noop $regsubex($1-,/[\w\d]/g,$a_count)
  534.   var %a_char = $a_count(1)
  535.   if (!$hget(a_table)) { hmake a_table 5 }
  536.   hadd -u300 a_table $a(char) $+(%a_char,;,$nick)
  537.   if (!$timer(a_activity)) { .timera_activity 0 300 hadd a_table a_lines 1 }
  538.   hinc a_table a_lines
  539. }
  540. alias -l a {
  541.   if (!$2) { return $+($1,$hget(a_table,a_lines)) }
  542.   else { return $hget(a_table,$+($1,$2)) }
  543. }
  544. alias -l a_count {
  545.   if ($isid) {
  546.     if (!$1) { inc %a_count 1 }
  547.     return %a_count
  548.   }
  549.   else { unset %a_count }
  550. }
  551. alias -l a_active {
  552.   var %a_t = 1
  553.   while ($a(char,%a_t)) {
  554.     var %a_c = $gettok($ifmatch,1,59), %a_p = $gettok($ifmatch,2,59)
  555.     var %a_persons = $addtok(%a_persons,%a_p,59)
  556.     var %a_characters = $calc(%a_characters + %a_c)
  557.     inc %a_t
  558.   }
  559.   var %a_lines = %a_t - 1
  560.   var %a_persons = $numtok(%a_persons,59)
  561.   return $a_formula(%a_characters,%a_lines,%a_persons)
  562. }
  563. alias a_formula {
  564.   /*
  565.   1 = Characters
  566.   2 = Lines
  567.   3 = Persons
  568.   */
  569.   ;return $calc(($1 / $2) / $3)
  570.   return $iif($round($calc(($1 / $2) / $3),0) == 0,10,$ifmatch)
  571. }
  572. #activity_tracker end
  573.  
  574.  
  575. /*
  576. # Module: [$] unescapehtml
  577. # Usage: $unescapehtml(text_to_unescape)
  578. # Info: Unescapes html encoded characters.
  579. */
  580. #unescapehtml on
  581. alias unescapehtml {
  582.   var %commonchars = lt|gt|amp|quot
  583.   var %commoncharcodes = 60|62|38|34|39
  584.   var %i = $regex($1, /(&(?:#\d+| $+ %commonchars $+ );)/gi), %chr, %after, %retval
  585.   if (!%i) { return $1 }
  586.   set -n %retval $1
  587.   while (%i) {
  588.     %chr = $mid($regml(%i), 2, -1)
  589.     if ($findtok(%commonchars, %chr, 1, 124)) { %chr = $gettok(%commoncharcodes, $ifmatch, 124) }
  590.     else {
  591.       %chr = $mid(%chr, 2)
  592.       if (%chr > 255) { %chr = 63 }
  593.     }
  594.     set -n %after $mid(%retval, $calc($regml(%i).pos + $len($regml(%i))))
  595.     set -n %retval $+($left(%retval, $calc($regml(%i).pos - 1)), $chr(%chr), %after)
  596.     dec %i
  597.   }
  598.   return %retval
  599. }
  600. #unescapehtml end
  601.  
  602.  
  603. /*
  604. # Module: [/] web_send
  605. # Usage: /web_send song_tags
  606. # Info: Sends $song_tags to r-a-dio website server.
  607. */
  608. #web_send on
  609. alias noqt2 { return $left($right($1-,-1),-1) }
  610. alias web_send_data {
  611.   var %sock = $+(web_send_,$1,$r(0,10000))
  612.   sockopen %sock r-a-dio.com 80
  613.   ;lp = web_send_data lp lastsong
  614.   ;np = web_send_data np listeners bitrate np
  615.   if ($1 == lp) {
  616.     set $+(%,%sock,_data) $+(/x_data/updlp.php?user=Saki&pass=niceone&djid=,%radio.djid,&lp,=,$url_encode($noqt2($2-)))
  617.   }
  618.   elseif ($1 == np) && (!$4) {
  619.     set $+(%,%sock,_data) $+(/x_data/updstrstat.php?user=Saki&pass=niceone&djid=,%radio.djid,&listeners=,$2,&bitrate=,$3)
  620.     ;,&np=,$url_encode($noqt2($hget(stream_,StreamTitle))))
  621.   }
  622.   elseif ($1 == np) {
  623.     set $+(%,%sock,_data) $+(/x_data/updstrstat.php?user=Saki&pass=niceone&djid=,%radio.djid,&listeners=,$2,&bitrate=,$3,&np=,$url_encode($noqt2($4-)))
  624.   }
  625.   .timerclearweb_send 0 600 unset %web_send_*
  626. }
  627. on *:SOCKOPEN:web_send_*: {
  628.   sockwrite -nt $sockname GET $($+(%,$sockname,_data),2) HTTP/1.1
  629.   sockwrite -nt $sockname Host: r-a-dio.com
  630.   sockwrite -nt $sockname $crlf
  631. }
  632. on *:SOCKREAD:web_send_*: {
  633.   var %v
  634.   sockread %v
  635.   if ($regex(%v,/Error_code: (\n+)/i)) {
  636.     var %error_code = $regml(1)
  637.     if (%error_code != 0) {
  638.       echo -s (R/a/dio) [web_send]: Failed to upload song title $+([,Data=,$($+(%,$sockname,_data),2),])
  639.       if (%error_code == 1) {
  640.         echo -a web_send ERROR 'Missing username or password'
  641.       }
  642.       elseif (%error_code == 2) {
  643.         echo -a web_send ERROR 'Incorrect username or password'
  644.       }
  645.       elseif (%error_code == 3) {
  646.         echo -a web_send ERROR 'Incorrect privileges'
  647.       }
  648.       elseif (%error_code == 4) {
  649.         echo -a web_send ERROR 'Invalid/Missing parameters'
  650.       }
  651.       else {
  652.         echo -a web_send ERROR 'Unknown error $+([,%error_code,]) $+ '
  653.       }
  654.     }
  655.   }
  656. }
  657. on *:SOCKCLOSE:web_send_*: {
  658.   unset $+(%,$sockname,_data)
  659. }
  660. alias get_dat_dj {
  661.   set %radio.dj_get $1
  662.   echo -a G: $1
  663.   if (%radio.dj_get == 0) {
  664.     set %radio.djid 0
  665.   }
  666.   else {
  667.     sockopen get_dj r-a-dio.com 80
  668.   }
  669. }
  670. on *:SOCKOPEN:get_dj: {
  671.   sockwrite -nt $sockname GET /x_data/getdjid.php?user=saki&pass=niceone&dj= $+ %radio.dj_get HTTP/1.1
  672.   sockwrite -nt $sockname Host: r-a-dio.com
  673.   sockwrite -nt $sockname $crlf
  674. }
  675. on *:SOCKREAD:get_dj: {
  676.   var %t
  677.   sockread %t
  678.   if (error_code: isin %t) {
  679.     var %error_code = $gettok(%t,2,32)
  680.     if (%error_code != 0) {
  681.       echo -s [GET DJ] Yep its an error -> %t
  682.     }
  683.   }
  684.   elseif ($regex(%t,/^[0-9][0-9]?$/i)) {
  685.     if (%t) && (!%d) { var %d = 1 | set %radio.djid %t }
  686.  
  687.   }
  688. }
  689. #web_send end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement