Lyrics Search for Winamp

Here is room for additional scripts for Gamers.IRC.

You are highly advised to read the How-To first!
User avatar
Tuxman
Administrator
Posts: 1873
Joined: 24.10.2003 00:13
Status: That guy
Contact:

Lyrics Search for Winamp

Unread postby Tuxman » 05.04.2009 20:44

This Gamers.IRC add-on tries to find and display your currently played song's lyrics.

You'll need Winamp for it, of course. :grin:

Code: Select all

dialog tblLyricsearch {
  title "Lyrics Search"
  size -1 -1 226 176
  option dbu
  edit "", 1, 1 13 182 163, multi read vsbar
  button "close", 2, 185 13 39 12, default flat ok cancel
  button "refresh", 3, 185 26 39 12, flat
  text "playing:", 4, 2 2 20 8
  edit "", 5, 23 1 202 10, read
}

on *:dialog:tblLyricsearch:init:*:{
  updateLyrics
}

on *:dialog:tblLyricsearch:sclick:*:{
  if ($did == 3) {
    updateLyrics
  }
}

alias lyricsearch { dialog $iif($dialog(tblLyricsearch), -x, -md) tblLyricsearch tblLyricsearch }
menu channel,status,query,menubar {
  Lyric Search:lyricsearch
}

alias unicodetomsl {
  var %i = 1, %html = $remove($1-,&#), %b
  var %n = $numtok(%html,59)
  while (%i <= %n) {
    if ($gettok(%html,%i,59) == 32) {
      %b = $+(%b,$chr($gettok(%html,%i,59)),$chr($gettok(%html,$calc(%i + 1),59)))
      inc %i 2
    }
    else {
      %b = $+(%b,$chr($gettok(%html,%i,59)))
      inc %i
    }
  }
  return %b
}

alias -l updateLyrics {
  if ($dll(gIRC.dll) && ($winampstats(running) == $true) && $dialog(tblLyricsearch)) {
    if ($winampstats(running) != $true) {
      did -ra tblLyricsearch 5 Winamp isn't running!
    }
    else {
      did -ra tblLyricsearch 5 Winamp running; looking for lyrics...
      
      if ($sock(scLyricsearch)) { sockclose scLyricsearch }
      sockopen scLyricsearch lyrics.wikia.com 80
    }
  }
}

on *:sockopen:scLyricsearch:{
  if ($sockerr) { did -ra tblLyricsearch 5 Socket creation error! | halt }
  sockwrite -n $sockname GET / $+ $replace($winampinfo(artist),$chr(32),_) $+ : $+ $replace($winampinfo(title),$chr(32),_) HTTP/1.1
  sockwrite -n $sockname Host: lyrics.wikia.com
  sockwrite -n $sockname User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.0.2) Gecko/2008082714 Firefox/3.0.2
  sockwrite -n $sockname $crlf
}

on *:sockread:scLyricsearch:{
  sockread %x
  if ('lyricbox' isin %x && rtMatcher !isin %x) {
    %x = $replace($replace(%x,<br />,$chr(128)),<br/>,$chr(128))
    did -ra tblLyricsuche 6 $winampinfo(artist) - $winampinfo(title)
    var %lyRegex = $regex(%x,/<div class=\'lyricbox\'>(.*)<!--/)
    %x = $regml(1)
    did -r tblLyricsuche 1
    var %i = 1
    while (%i <= $numtok(%x,128)) {
      did -a tblLyricsuche 1 $unicodetomsl($gettok(%x,%i,128))
      if (%i != $numtok(%x,128)) { did -a tblLyricsuche 1 $crlf }
      inc %i
    }
    did -f tblLyricsuche 1
    sockclose $sockname
  }
  elseif (</html> isin %x) {
    did -ra tblLyricsearch 5 Couldn't find lyrics! :/
    sockclose $sockname
  }
}

on *:unload:{
  if ($sock(scLyricsearch)) { sockclose scLyricsearch }
}
To run this script, use the new context menu entry Lyric Search.
^\__/
..O.o

This is Einkaufswagen. Copy Einkaufswagen into your signature to help him on his way to world domination.

Who is online

Users browsing this forum: No registered users and 0 guests