; youtube video search
; returns the first search result for your search terms
; usage for you
;
; trigger: /yt
; syntax: /yt <search terms>
; example: /yt charleston daft punk
; usage for other people
;
; 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_sort=video_view_count&search_query= $+ %yt.searchstring
;
; if you want the regular search, use this line below
; sockwrite -nt $sockname GET /results?search_query= $+ %yt.searchstring HTTP//1.1
;
; the place im referring to is: under the heading on *:sockopen:ytsearch:{
alias yt {
%yt.channel = $chan
if (%yt.channel) { %yt.saystyle = echo -t %yt.channel }
else { %yt.saystyle = echo -at }
%yt.searchstring = $replace($1-,$chr(32),+)
sockclose ytsearch
sockopen ytsearch www.youtube.com 80
}
on $*:TEXT:/^[!@](yt|youtube) */Si:#: {
%yt.channel = $chan
%yt.saystyle = /msg %yt.channel
%yt.searchstring = $replace($2-,$chr(32),+)
if ($2 == $null) { %yt.saystyle Search could not be completed | halt }
sockclose ytsearch
sockopen ytsearch www.youtube.com 80
}
on *:sockopen:ytsearch:{
sockwrite -nt $sockname GET /results?search_query= $+ %yt.searchstring HTTP//1.1
sockwrite -nt $sockname Host: youtube.com
sockwrite -nt $sockname $crlf $crlf
}
on *:sockread:ytsearch:{
sockread -n %yt.temp
if (%yt.founddesc_be) { unset %yt.founddesc_be | %yt.desc_be = $replace($replace($remove(%yt.temp,<b>,</b>, ),<br/>,$chr(32)),",$chr(34)) }
if (<span id="BeginvidDesc isin %yt.temp) %yt.founddesc_be = k
; if (/watch?v= isin %yt.temp) { %yt.resulturl = $remove($gettok(%yt.temp,2,32),href=",") }
if (*<a href="/watch?v=* iswm %yt.temp) { %yt.resulturl = $remove($gettok(%yt.temp,2,32),href=",") }
if (%yt.foundtitle) { inc %yt.titlecounter }
if (%yt.titlecounter = 1) { %yt.searchtitle = $replace($remove($regsubex(%yt.temp,/<a [^>]+>(.+?)</a>/,\1),<b>,</b>,<br/>, ),",$chr(34)) }
if (<div class="vSnippetTitle"> isin %yt.temp) { %yt.foundtitle = k | %yt.titlecounter = 0 }
if (<img class="rating" src="/img/icn_star_full_11x11 isin %yt.temp) { %yt.done = k }
if (%yt.done) {
sockclose ytsearch
unset %yt.done
%yt.saystyle Link: http://www.youtube.com $+ %yt.resulturl
%yt.saystyle Title: %yt.searchtitle
%yt.saystyle Description: %yt.desc_be
unset %yt.*
halt
}
if (*No Videos found* iswm %yt.temp) {
sockclose ytsearch
%yt.saystyle No videos found for %yt.searchstring
unset %yt.*
halt
}
if (*start search results* iswm %yt.temp) { %yt.searchres = 0 }
if (*<a href="/watch?v=* iswm %yt.temp) { inc %yt.searchres }
}