Hmm, yeah. I did say it was a crude version (Meaning I didn't test it for searches that have no search results... whoops. stupid me)

try this instead:

Code:
; youtube video search
; returns the first search result for your search terms
;
; triggers: !youtube @youtube !tube @tube
; syntax: @youtube <search terms.
; example: !tube charleston daft punk


; if you want to sort search by VIEW COUNT, use this line below
; sockwrite -nt $sockname GET /results?search_query=
;
; if you want the regular search, use this line below
; sockwrite -nt $sockname GET /results?search_query= $+ %tube.search HTTP//1.1
;
; you'd put either one of those on line 32 of this script
; that line number may be different when this script is put into a bigger script
; so the place im referring to is: under the heading on *:sockopen:ytsearch:{


on $*:TEXT:/^[!@](youtube|tube) */Si:#: { 
  %linenumber = 0
  set %chan.tube $chan
  set %tube.style /msg %chan.tube
  set %tube.search $replace($2-,$chr(32),+)

  if ($2 == $null) { %tube.style Search could not be completed | halt }
  sockopen ytsearch www.youtube.com 80
}


on *:sockopen:ytsearch:{
  sockwrite -nt $sockname GET /results?search_query= $+ %tube.search HTTP//1.1
  ;
  ; if you want to sort search by VIEW COUNT, use this instead of the line above
  ; sockwrite -nt $sockname GET /results?search_query= $+ %tube.search $+ &search_sort=video_view_count HTTP//1.1

  sockwrite -nt $sockname Host: youtube.com 
  sockwrite -nt $sockname $crlf $crlf 
}

on *:sockread:ytsearch:{
  var %temp
  sockread %temp

  if (%searchres == 1) {
    %searchtitle = $remove($regsubex(%temp,/<a [^>]+>(.+?)</a>/,\1),<br/>,	)
    set %tube.url $remove($gettok(%temp,2,32),href=",")

    if (/watch?v= isin %tube.url) {
      %tube.style %searchtitle $+ : http://www.youtube.com $+ %tube.url

      unset %linenumber
      unset %tube.search
      unset %searchtitle
      unset %chan.tube
      unset %tube.style
      unset %searchres      
      unset %tube.url

      sockclose ytsearch
      halt
    }
  }
  if ( *start search results* iswm %temp) { set %searchres 0 }  
  if (*<a href="/watch?v=* iswm %temp) { inc %searchres }
  if (*No Videos found* iswm %temp) {
    %tube.style No videos found for %tube.search
    unset %linenumber
    unset %tube.search
    unset %searchtitle
    unset %chan.tube
    unset %tube.style
    unset %searchres      
    unset %tube.url
    sockclose ytsearch
    halt
  }
  inc %linenumber
}