Youtube advanced search

By FordLawnmower on Nov 15, 2009

Youtube search script for mIRC.
Script was requested by kibblz
Syntax : !youtube -novr search words here. The -switches are optional.
Switch explaination : -n (newest) -o (oldest) -v (view count) -r (rating)
!youtube -h for help
Examples : !youtube -n mad dog
Examples: !youtube mad dog
Examples: @youtube mad dog

  • To activate this script for a channel type +youtube (requires ops)
  • To deactivate this script for a channel type -youtube (requires ops)
  • You can right click channel or status and turn the trigger off/on for all channels.
  • The ! trigger will notice the user and the @ trigger will message the channel if the user has halfops or higher.
    Demo:
    02:08:36 @youtube whiskey
    02:08:37 Searching Youtube........
    02:08:39 Title: Brad Paisley and Alison Kraus - Whiskey Lullaby.wmv Length: 5:28 Type: Music User: bubenceto033 Rating: 5.0 Views: 354 237 Added: 2 years ago Link: http://www.youtube.com/watch?v=G0nA74_0K30
    02:08:39 Title: whiskey lullaby Length: 4:20 Type: Music User: mofradan Rating: 5.0 Views: 1 248 088 Added: 2 years ago Link: http://www.youtube.com/watch?v=7gV3g9LCvPc
    02:08:42 Title: Metallica - Whiskey In The Jar: Video Length: 5:00 Type: Music User: universalmusicgroup Rating: 5.0 Views: 1 885 454 Added: 1 year ago Link: http://www.youtube.com/watch?v=7oKLq1JD3vU
;Youtube advanced search by Ford_Lawmower irc.GeekShed.net #Script-Help
alias -l GetYoutube {
  var %MaxResults 3
  var %TitleColor $+($chr(3),$chr(2))
  var %TextColor $+($chr(2),$chr(3),04)
  var %LinkColor $+($chr(3),$chr(31))
  var %logo $+($chr(2),$chr(3),01,$chr(44),00You,$chr(3),00,$chr(44),04Tube,$chr(2))
  $1-2 %logo %TitleColor Searching Youtube........  
  var %sockname $+(YoutubeAdvancedSearch,$network,$2,$ticks), %yt.url $replace($3-,$chr(32),+)
  if ($left($3,1) == -) {
    if ($3 == -h || !$4) {
      $1-2 Syntax is !Youtube search words here. Optionally, you can change the search type by adding a search flag directly after !youtube and before The search word(s)
      $1-2 Valid search flags are -n (newest) -o (oldest) -v (view count) -r (rating) . Ex. !Youtube -n jimi hendrix  <<-- Will show the 3 newest posts with jimi hendrix in them.
      $1-2 You can also use the @ trigger to message the channel if you have halfops or higher. Ex. @Youtube jimi hendrix
      return
    }  
    elseif ($3 == -n) { var %SearchType &search_sort=video_date_uploaded }
    elseif ($3 == -o) { var %SearchType &search_sort=video_date_uploaded_reverse }
    elseif ($3 == -v) { var %SearchType &search_sort=video_view_count }
    elseif ($3 == -r) { var %SearchType &search_sort=video_avg_rating }
    %yt.url = $replace($4-,$chr(32),+) $+ %SearchType
  }
  var %yt.url $replace($iif(- isin $3,$4-,$3-),$chr(32),+) $+ %SearchType
  sockopen %sockname www.youtube.com 80
  sockmark %sockname $1-2 $+(/results?search_type=&aq=f&search_query=,%yt.url,&hl=en) %MaxResults %TitleColor %TextColor %LinkColor %logo
}
menu Channel,Status {
  .$iif($group(#Youtube) == On,$style(1)) Youtube Trigger
  ..$iif($group(#Youtube) == On,$style(2)) On: .enable #Youtube
  ..$iif($group(#Youtube) == Off,$style(2)) Off: .disable #Youtube
}
#Youtube on
On $*:Text:/^(\+|-|!|@)Youtube.*/Si:#: {
  var %action $regml(1)
  if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@)/)) {
    if (%action == +) {
      if ($istok(%YoutubeChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is already running the Youtube script }
      else { 
        .enable #Youtube
        Set %YoutubeChanList $addtok(%YoutubeChanList,$+($network,$chan),32)
        .msg $chan $nick has activated the Youtube script for $chan .
      }
    }
    else {
      if (!$istok(%YoutubeChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is not running the Youtube script }
      else { 
        Set %YoutubeChanList $remtok(%YoutubeChanList,$+($network,$chan),1,32)
        .msg $chan $nick has deactivated the Youtube script for $chan . 
      }
    }
  }
  elseif (!$timer($+(Youtube,$network,$nick))) && ($istok(%YoutubeChanList,$+($network,$chan),32)) {
    .timer $+ $+(Youtube,$network,$nick) 1 6 noop
    var %method $iif(%action == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/),.msg $chan,.notice $nick))
    GetYoutube %method $strip($2-)
  }
}
#Youtube end
On *:sockopen:YoutubeAdvancedSearch*: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
    sockwrite -n $sockname Host: www.youtube.com
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | youtube.cleanup }
}
On *:sockread:YoutubeAdvancedSearch*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | youtube.cleanup }
  else {
    var %Youtube | sockread %Youtube
    ;write youtube.txt %Youtube
    if (No video results isin %Youtube) {
      $gettok($sock($sockname).mark,1-2,32) No results were found for your search!
      youtube.cleanup
    }
    if ($regex(%Youtube,/item-title="(.*?)"\s?data/i)) hadd -m $sockname title $fix($xchr($fix($regml(1))))
    if ($regex(%Youtube,/item-id="(.*?)"\s?data/i)) hadd -m $sockname id $regml(1)    
    if ($regex(%Youtube,/item-user="(.*?)"\s?data/i)) hadd -m $sockname user $regml(1)
    if ($regex(%Youtube,/item-views="(.*?)"\s?data/i)) hadd -m $sockname views $regml(1)    
    if ($regex(%Youtube,/<\/a><\/li><li>(.*?)<\/li><li>/i)) {
      hadd -m $sockname date $regml(1)
      hinc $sockname count      
      var %s $sockname
      tokenize 32 $sock(%s).mark
      $1-2 $8- $+($5,Title:,$6) $hget(%s,title) $+($5,User:,$6) $hget(%s,user) $+($5,Added:,$6) $hget(%s,date) $+($5,Views:,$6) $hget(%s,views) $+($7,http://www.youtube.com/watch?v=,$hget(%s,id))
      if ($hget(%s,count) >= $4) youtube.cleanup      
    }
  }
}
On *:sockclose:YoutubeAdvancedSearch*: youtube.cleanup
alias -l youtube.cleanup {
  if ($hget($sockname)) hfree $v1
  sockclose $sockname
  return
}
alias Youtube { GetYoutube echo -a $1- }
alias -l Xchr { 
  var %return $regsubex($regsubex($1-,/&#x([A-F0-9]{1,2});/g,$chr($base($regml(\n),16,10))),/&#([0-9]{2});/g,$chr(\1)) 
  return $replacecs(%return,&ndash;,,&middot;,·,&raquo;,»,&laquo;,«,&Uuml;,Ü,&uuml;,ü,&Aacute;,Á,&aacute;,á,&Eacute;,$&
    É,&eacute;,é,&Iacute;,Í,&iacute;,í,&Oacute;,Ó,&oacute;,ó,&Ntilde;,Ñ,&ntilde;,ñ,&Uacute;,Ú,&uacute;,ú,&nbsp;,$chr(32),$&
    &aelig;,æ,&quot;,",&lt;,<,&gt;,>)
}
alias -l fix { return $regsubex($remove($replace($1-,&amp;,&,&quot;,"),amp;,<b>,</b>),/&#([0-9]{2});/gi,$chr(\t)) }

Comments

Sign in to comment.
Somsubhra1   -  Jan 20, 2016

Not working anymore, please fix it.
[22:27:55] @youtube whiskey
[22:27:56] YouTube Searching Youtube........

Stewie1k94  -  Jan 20, 2016

http://pastebin.com/gtv9Gu5n

[11:28am] <~GoneNotHereK> @Youtube Whiskey
[11:28am] <&ThunderBolt> YouTube Searching Youtube........
[11:28am] <&ThunderBolt> YouTube Title: Scotch Experts Review Cheap Whiskey User: BuzzFeedBlue Added: 3 months ago Views: 1,493,966 http://www.youtube.com/watch?v=rhdlSpfzPvo
[11:28am] <&ThunderBolt> YouTube Title: how to drink whiskey like a sir User: CineStreamChannel Added: 3 years ago Views: 1,070,801 http://www.youtube.com/watch?v=YVG1U-faqHY
[11:28am] <&ThunderBolt> YouTube Title: Women Drink Whiskey For The First Time User: BuzzFeedVideo Added: 1 year ago Views: 4,916,711 http://www.youtube.com/watch?v=ujZDsdTO2DY
[11:28am] <&ThunderBolt> YouTube Title: Whiskey vs. Scotch vs. Bourbon | Whiskey Guide User: Howcast Added: 1 year ago Views: 81,887 http://www.youtube.com/watch?v=6EMHoBNjID0

Somsubhra1  -  Jan 21, 2016

This not even showing "Searching youtube". No commands work in this for me. BTW if you don't mind then why don't you tell me your irc server and the channel, I'll join there and we can talk there freely about the scripts.

ovelayer  -  Jan 21, 2016

Fordlawnmower no longer supports his scripts...use this one instead
http://hawkee.com/snippet/8577/
The author is a great guy and supports his scripts..plus imo its the best youtube script out there

Stewie1k94  -  Jan 21, 2016

@Somsubhra1 - Maybe update your mIRC to the latest version, I am on the latest version and worked perfectly for me.

I am away until Monday though but would happily assist you on Swift when I am home

@ovelayer - would probably be better if he did use that one since its using the API, it's bothering me he's claiming the script don't work. I wouldn't post it if I wasn't sure.

Stewie1k94  -  Jan 21, 2016

@Somsubhra1 - sorry but I forgot I'd left in my channel in the on TEXT and that's probably why it won't work. Sorry.

Somsubhra1  -  Jan 21, 2016

Yes, now it worked, Thanks. BTW what's your channel on swiftirc? Can you also fix this script.... http://hawkee.com/snippet/6022/ This too doesn't work for me. Thanks in advance :)

Stewie1k94  -  Jan 21, 2016

Yes. I will try when I am home. Swift is also great for help. :)

Sign in to comment

GuitarMasterx7   -  Jan 10, 2014

Aw it doesn't show the title anymore

kriss82  -  Jan 06, 2015

prosze o aktualizacje

Sign in to comment

^WeSt   -  Oct 17, 2013

This add-on does not working..

Stucks on the Searching.... notice!

  • Thanks!
MoonCrawlerVG  -  Nov 23, 2013

Yea I had that some problem too what a shame such a good script.

FordLawnmower  -  Nov 23, 2013

Updated and working again.

MoonCrawlerVG  -  Nov 23, 2013

Wow thanks it works great now, can you tell me how to change the colors of the title and the text color because for me it looks like this.

http://prntscr.com/269jdx

Sign in to comment

ovelayer   -  Jul 06, 2013

doesn't work.. =(

 Respond  
cj42057   -  Apr 20, 2013

awesome script and it worked great for awhile, just a heads up it errors out now ...when I get a chance to go over the code I will attempt to fix it and report my results back here. Screen: http://i.imgur.com/oJNl3ZJ.png

 Respond  
FordLawnmower   -  Dec 28, 2012

Updated

 Respond  
Stewie1k94   -  Dec 14, 2012

I had a go at updating myself:

;Youtube advanced search by Ford_Lawmower irc.GeekShed.net #Script-Help
alias -l GetYoutube {
  var %MaxResults 3
  var %TitleColor $+($chr(3),$chr(2))
  var %TextColor $+($chr(2),$chr(3),04)
  var %LinkColor $+($chr(3),$chr(31))
  var %logo $+($chr(3),14,Y,$chr(3),04,outube) $chr(7)
  $1-2 %logo %TitleColor Searching Youtube........  
  var %sockname $+(YoutubeAdvancedSearch,$network,$2,$ticks), %yt.url $replace($3-,$chr(32),+)
  if ($left($3,1) == -) {
    if ($3 == -h || !$4) {
      $1-2 Syntax is !Youtube search words here. Optionally, you can change the search type by adding a search flag directly after !youtube and before The search word(s)
      $1-2 Valid search flags are -n (newest) -o (oldest) -v (view count) -r (rating) . Ex. !Youtube -n jimi hendrix  <<-- Will show the 3 newest posts with jimi hendrix in them.
      $1-2 You can also use the @ trigger to message the channel if you have halfops or higher. Ex. @Youtube jimi hendrix
      return
    }  
    elseif ($3 == -n) { var %SearchType &search_sort=video_date_uploaded }
    elseif ($3 == -o) { var %SearchType &search_sort=video_date_uploaded_reverse }
    elseif ($3 == -v) { var %SearchType &search_sort=video_view_count }
    elseif ($3 == -r) { var %SearchType &search_sort=video_avg_rating }
    %yt.url = $replace($4-,$chr(32),+) $+ %SearchType
  }
  var %yt.url $replace($iif(- isin $3,$4-,$3-),$chr(32),+) $+ %SearchType
  sockopen %sockname www.youtube.com 80
  sockmark %sockname $1-2 $+(/results?search_type=&aq=f&search_query=,%yt.url,&hl=en) %MaxResults %TitleColor %TextColor %LinkColor %logo
}
menu Channel,Status {
  .$iif($group(#Youtube) == On,$style(1)) Youtube Trigger
  ..$iif($group(#Youtube) == On,$style(2)) On: .enable #Youtube
  ..$iif($group(#Youtube) == Off,$style(2)) Off: .disable #Youtube
}
#Youtube on
On $*:Text:/^(\+|-|!|@)Youtube.*/Si:#: {
  var %action $regml(1)
  if (%action isin +-) && ($regex($nick($chan,$nick).pnick,/(!|~|&|@)/)) {
    if (%action == +) {
      if ($istok(%YoutubeChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is already running the Youtube script }
      else { 
        .enable #Youtube
        Set %YoutubeChanList $addtok(%YoutubeChanList,$+($network,$chan),32)
        .msg $chan $nick has activated the Youtube script for $chan .
      }
    }
    else {
      if (!$istok(%YoutubeChanList,$+($network,$chan),32)) { .msg $chan $nick $chan is not running the Youtube script }
      else { 
        Set %YoutubeChanList $remtok(%YoutubeChanList,$+($network,$chan),1,32)
        .msg $chan $nick has deactivated the Youtube script for $chan . 
      }
    }
  }
  elseif (!$timer($+(Youtube,$network,$nick))) && ($istok(%YoutubeChanList,$+($network,$chan),32)) {
    .timer $+ $+(Youtube,$network,$nick) 1 6 noop
    var %method $iif(%action == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/),.msg $chan,.notice $nick))
    GetYoutube %method $strip($2-)
  }
}
#Youtube end
On *:sockopen:YoutubeAdvancedSearch*: {
  if (!$sockerr) {
    sockwrite -nt $sockname GET $gettok($sock($sockname).mark,3,32) HTTP/1.0
    sockwrite -n $sockname Host: www.youtube.com
    sockwrite -n $sockname $crlf
  }
  else { echo -st Socket Error $nopath($script) | youtube.cleanup }
}
On *:sockread:YoutubeAdvancedSearch*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | youtube.cleanup }
  else {
    var %Youtube | sockread %Youtube
    if (No video results isin %Youtube) {
      $gettok($sock($sockname).mark,1-2,32) No results were found for your search!
      youtube.cleanup
    }
    elseif ($regex(%Youtube,/data-context-item-title="(.*?)"/i)) hadd -m $sockname title $fix($regml(1))
    elseif ($regex(%Youtube,/data-video-ids="(.*?)"/i)) hadd -m $sockname id $regml(1)
    elseif ($regex(%Youtube,/dir="ltr">(.*?)<\/a><span class="metadata-separator">(.*?)<span class="metadata-separator">(.*?) views/i)) {
      hinc -m $sockname count      
      var %s $sockname
      tokenize 32 $sock(%s).mark
      $1-2 $8- $+($5,Title:,$6) $remove($hget(%s,title),<b>,</b>) $+($5,User:,$6) $regml(1) $+($5,Added:,$6) $remove($regml(2),</span>,&bull;) $+($5,Views:,$6) $remove($regml(3),</span>,&bull;) $+($7,http://www.youtube.com/watch?v=,$hget(%s,id))
      if ($hget(%s,count) >= $4) youtube.cleanup      
    }
  }
}
On *:sockclose:YoutubeAdvancedSearch*: youtube.cleanup
alias -l youtube.cleanup {
  if ($hget($sockname)) hfree $v1
  sockclose $sockname
  return
}
alias Youtube { GetYoutube echo -a $1- }
alias -l fix { return $regsubex($remove($replace($1-,&amp;,&,&quot;,"),amp;,<b>,</b>),/&#([0-9]{2});/gi,$chr(\t)) }

[11:47am] <~Stewie> @Youtube Halestorm
[11:47am] <&thunderbolt> Youtube Searching Youtube........
[11:47am] <&thunderbolt> Youtube Title: Halestorm - Bad Romance (cover) HD User: britton stallard Added: 1 year ago Views: 306,257 http://www.youtube.com/watch?v=ZO7NN9w9Z_g
[11:47am] <&thunderbolt> Youtube Title: Halestorm - Daughters of Darkness Lyrics User: denestygg Added: 8 months ago Views: 258,190 http://www.youtube.com/watch?v=3XQ1FB3Rz0g
[11:47am] <&thunderbolt> Youtube Title: Halestorm - I Miss The Misery [Official Video] User: HalestormRocks Added: 5 months ago Views: 2,357,340 http://www.youtube.com/watch?v=YpJAmlnBxoA

 Respond  
amclay   -  Dec 13, 2012

^

 Respond  
play4free2   -  Dec 09, 2012

It broke again when YouTube changed it's format.

 Respond  
chachin   -  Nov 27, 2012

Thanks ford, You're the best ;D

 Respond  
play4free2   -  Jul 18, 2012

Thanks Ford, and btw great work on this too.

 Respond  
FordLawnmower   -  Jul 18, 2012

Updated
Thanks @play4free2

 Respond  
play4free2   -  Jul 17, 2012

It's broke again:

[9:08pm] <~PlaysBot> [YouTube] Title: Disturbed - Down With The Sickness (Video) (Explicit)"data-sessionlink="ei=CJWC_ImtorECFSpRQgodHGVb4w%3D%3D User: warnerbrosrecords Added: 2 years ago Views: 9,360,454 http://www.youtube.com/watch?v=HkhfL0pnMPQ
[9:08pm] <~PlaysBot> [YouTube] Title: Disturbed - Down With The Sickness [Music Video]"data-sessionlink="ei=CJWC_ImtorECFSpRQgodHGVb4w%3D%3D User: DisturbedTV Added: 2 years ago Views: 12,000,085 http://www.youtube.com/watch?v=09LTT0xwdfw
[9:08pm] <~PlaysBot> [YouTube] Title: Disturbed-Down with the Sickness"data-sessionlink="ei=CJWC_ImtorECFSpRQgodHGVb4w%3D%3D User: iamsh Added: 4 years ago Views: 5,472,062 http://www.youtube.com/watch?v=Fq3QmtV8vT0

 Respond  
ryan7461035   -  Jun 25, 2012

How to have it be used by all ? that doesn't requires ops Or Half Op. can you tell me how to let everyone use the !youtube search item

 Respond  
Saigyouji   -  May 15, 2012

Thanks alot.

 Respond  
FordLawnmower   -  May 14, 2012

@Saigyouji I just posted a fix. This script should be working again.

 Respond  
Saigyouji   -  May 14, 2012

It's broken again.

 Respond  
Glaxu   -  Mar 31, 2011

thx u nyaa!

 Respond  
irchainscriptz   -  Mar 31, 2011

thanks FordLawnmower

 Respond  
Stewie1k94   -  Mar 30, 2011

thanks

 Respond  
FordLawnmower   -  Mar 30, 2011

Updated.

 Respond  
Glaxu   -  Mar 30, 2011

i have the same problem ... :s :S :s
[19:57] @Happy_Material: @youtube hola
[19:57] @Soul: Youtube Searching Youtube........
[19:57] @Soul: Youtube Title: User: warnermusicspain Added: 2 years ago Views: 2,904,252 http://www.youtube.com/watch?v=
[19:57] @Soul: Youtube Title: User: nessa89250 Added: 5 years ago Views: 11,705,916 http://www.youtube.com/watch?v=
[19:57] @Soul: Youtube Title: User: mecrazy123 Added: 1 year ago Views: 14,816 http://www.youtube.com/watch?v=
[19:57] @Happy_Material: x_x

 Respond  
Stewie1k94   -  Mar 30, 2011

it's stopped working again
[02:25:22] toclafane: @youtube eminem
[02:25:23] thunderbolt: Youtube Searching Youtube........
[02:25:24] thunderbolt: Youtube Title: User: EminemVEVO Added: 9 months ago Views: 218,676,280 http://www.youtube.com/watch?v=
[02:25:25] thunderbolt: Youtube Title: User: EminemVEVO Added: 1 year ago Views: 20,064,032 http://www.youtube.com/watch?v=
[02:25:26] thunderbolt: Youtube Title: User: EminemVEVO Added: 1 year ago Views: 34,600,884 http://www.youtube.com/watch?v=

 Respond  
Stewie1k94   -  Mar 30, 2011

lokitaespana i asked fordlawnmower to update it as it was not working and the new update is at the top of the page

 Respond  
FordLawnmower   -  Mar 29, 2011

@LokitaEspaña I have this script still working fine with the code at the top of this page.
Are you using the code from this page?
If so, can you explain the problem you are having and post your mIRC version.
The issue you are having could be related to some regional html but I have to check the little things before I get into that.

 Respond  
LokitaEspaña   -  Mar 29, 2011

toclafane1 .. I do not see, can you tell me where is the update of the code? I just see this date to 24 March, I do not see the new update

 Respond  
Stewie1k94   -  Mar 27, 2011

the new code is at the top already been updated

 Respond  
Stewie1k94   -  Mar 27, 2011

he already has

 Respond  
LokitaEspaña   -  Mar 27, 2011

FordLawnmower please can you fix the code? youtube has changed the html tags and this code no longer works, greetings!

 Respond  
Stewie1k94   -  Mar 25, 2011

oh ok thanks

 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.