Youtube Video Search

By iamdegenatron on Feb 25, 2007

YouTube Video Search
returns the first search result on youtube to you via a command, and others via a !trigger of your choosing. This script has been updated to work with youtube.com's recent site changes and will also be regularly updated in case it breaks due to more changes in Youtube's site structure.

I saw that the other person's script for searching for a youtube video wasn't working as expected so I created another one based on J40K's concepts :)

You can either use /yt to search for a video yourself, or people can search for a video using triggers like !youtube !tube !yt or @yt @tube @youtube

Personally I turn off the search for other people, so that I do not become a search bot for them :) The decision is upto you, I only include the possibility.

usage for you

trigger: /yt
syntax: /yt
example: /yt charleston daft punk

usage for other people

triggers: !youtube @youtube !tube @tube
syntax: @youtube
example: !tube charleston daft punk

; 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= $+ %yts.searchstring
;
; if you want the regular search, use this line below
; sockwrite -nt $sockname GET /results?search_query= $+ %yts.searchstring HTTP//1.1
;
; the place im referring to is: under the heading on *:sockopen:ytsearch:{

alias yt {
  %yts.channel = $chan
  if (%yts.channel) { %yts.saystyle = echo -t %yts.channel }
  else { %yts.saystyle = echo -at }

  %yts.searchstring = $replace($1-,$chr(32),+)
  sockclose ytsearch
  sockopen ytsearch www.youtube.com 80
}

on *:text:*:*: {
  ; youtube video search
  ; returns the first search result for your search terms
  if ( $regex($1-,/^[!@](yt|youtube) */Si) ) { 
    %yts.channel = $chan
    %yts.nick = $nick
    if (%yts.channel) { %yts.saystyle = /msg %yts.channel }
    if (%yts.channel == $null && %yts.nick) { %yts.saystyle = /msg %yts.nick }

    %yts.searchstring = $replace($2-,$chr(32),+)
    if ($2 == $null) { %yts.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= $+ %yts.searchstring HTTP//1.1
  sockwrite -nt $sockname Host: youtube.com 
  sockwrite -nt $sockname $crlf $crlf 
}

on *:sockread:ytsearch:{
  sockread -n %yts.temp

  if (%yts.founddesc_be) { unset %yts.founddesc_be | %yts.desc_be = $replace($replace($replace($remove(%yts.temp,<b>,</b>,  ),<br/>,$chr(32)),&quot;,$chr(34)),&#39;,') }
  if (<span id="BeginvidDesc isin %yts.temp) %yts.founddesc_be = k
  if (*<a href="/watch?v=* iswm %yts.temp) { %yts.resulturl = $remove($gettok(%yts.temp,2,32),href=",") }
  if (<a class="newvtitlelink" isin %yts.temp) { %yts.searchtitle = $replace($replace($remove($regsubex(%yts.temp,/<a [^>]+>(.+?)</a>/,1),<b>,</b>,<br/>,   ),&quot;,$chr(34)),&#39;,') }
  if (<img class="rating icn_star_full_11x11gif" isin %yts.temp) { %yts.done = k }  

  if (%yts.done) {
    sockclose ytsearch
    unset %yts.done

    %yts.saystyle Link: http://www.youtube.com $+ %yts.resulturl
    %yts.saystyle Title: %yts.searchtitle
    %yts.saystyle Description: %yts.desc_be

    unset %yts.*
    halt
  }

  if (*No Videos found* iswm %yts.temp) {
    sockclose ytsearch
    %yts.saystyle No videos found for %yts.searchstring

    unset %yts.*
    halt
  }

  if (*start search results* iswm %yts.temp) { %yts.searchres = 0  }  
  if (*<a href="/watch?v=* iswm %yts.temp) { inc %yts.searchres }
}

Comments

Sign in to comment.
Addiction   -  May 19, 2012

i have tried every single youtube addon but no one works

 Respond  
rsb   -  Mar 16, 2008

it gets URL but not info

 Respond  
fooddude707   -  Aug 30, 2007

it doesnt work for me on /yt or the others. i tried putting it in my remotes and tried putting it in my bots remotes but neither worked. help?

 Respond  
Aaron   -  Feb 25, 2007

you could also add:

var %saystyle = $iif($left($1,1) == @,msg $chan,notice $nick)

 Respond  
Korvin   -  Feb 25, 2007

you could change it to
on $:TEXT:?youtube :#: {
couldnt you?
cause then you can use as:
.youtube
!youtube
\'youtube
@youtube
?youtube
thats all the ones i know lol

 Respond  
iamdegenatron   -  Feb 25, 2007

This works great in conjunction with my other Youtube script that logs video urls and fetches their important info into an organized place in mIRC in a @window :)

http://www.hawkee.com/snippet.php?snippet_id=2417

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.