Youtube advanced search

Moderator: GeekShed.Net Staff

Youtube advanced search

Postby Ford » Sun Nov 15, 2009 8:23 am

Youtube search script for mIRC.
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

The ! trigger will notice the user and the @ trigger will message the channel if the user has halfops or higher.

Demo:
02:08:36 <Ford_Lawnmower> @youtube whiskey
02:08:37 <MyMulez> Searching Youtube........
02:08:39 <MyMulez> 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 <MyMulez> 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 <MyMulez> 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

Code: Select all
;Youtube advanced search by Ford_Lawmower irc.GeekShed.net #Script-Help
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:#: {
  if (!$timer($+(Youtube,$network,$nick))) {
    .timer $+ $+(Youtube,$network,$nick) 1 6 noop
    var %method $iif($regml(1) == !,.notice $nick,$iif($regex($nick($chan,$nick).pnick,/(!|~|&|@|%)/),.msg $chan,.notice $nick))
    Youtube %method $2-
  }
}
#Youtube end
alias EchoYoutube { Youtube echo -a $1- }
alias -l Youtube {
  $1-2 07» Searching Youtube........
  var %sockname $+(Youtube,$network,$2,$ticks)
  var %ut.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 }
    %ut.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=,%ut.url) 0 title duration category user 04Rating08:0 views uploader link
}
On *:sockopen:Youtube*: {
  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) | sockclose $sockname | return }
}
On *:sockread:Youtube*: {
  if ($sockerr) { echo -st Socket Error $nopath($script) | sockclose $sockname | return }
  else {
    var %Youtube | sockread %Youtube
    if (No videos found for isin %youtube) { $gettok($sock($sockname).mark,1-2,32) Sorry No Results! | sockclose $sockname | return }
    if ($regex(%Youtube,/<strong class="hovercard-title" >(.*)</strong><br>/)) sockmark $sockname $puttok($sock($sockname).mark,$+(04Title08: ,$sp($+($chr(32),$regml(1)))),5,32)
    if ($regex(%youtube,/<span class="hovercard-duration">(.*)</span> &nbsp;/)) sockmark $sockname $puttok($sock($sockname).mark,$+(04Length08: ,$sp($+($chr(32),$regml(1)))),6,32)
    if ($regex(%youtube,/<p class="hovercard-category">(.*)</p>/)) sockmark $sockname $puttok($sock($sockname).mark,$+(04Type08: ,$sp($+($chr(32),$regml(1)))),7,32)
    if ($regex(%youtube,/<p class="hovercard-username">(.*)</p>/)) sockmark $sockname $puttok($sock($sockname).mark,$+(04User08: ,$sp($+($chr(32),$regml(1)))),8,32)
    if ($regex(%youtube,/ratingL ratingL-5.0" title="(.*)"></button>/)) sockmark $sockname $puttok($sock($sockname).mark,$sp($+(04Rating08: ,$+($chr(32),$regml(1)))),9,32)
    if ($regex(%youtube,/<span class="hovercard-views">(.*)views</span>/)) sockmark $sockname $puttok($sock($sockname).mark,$+(04Views08: ,$sp($+($chr(32),$regml(1)))),10,32)
    if ($regex(%youtube,/class="video-date-added">(.*)</span>/)) sockmark $sockname $puttok($sock($sockname).mark,$+(04Added08: ,$sp($+($chr(32),$regml(1)))),11,32)
    if ($regex(%youtube,/<a id="video-long-title-(.*)" href="/)) { sockmark $sockname $puttok($sock($sockname).mark,$sp($+(04Link08:,$chr(32),http://www.youtube.com/watch?v=,$regml(1))),12,32) }
    if (<div class="video-clear-list-left"></div> isin %youtube) {
      sockmark $sockname $puttok($sock($sockname).mark,$calc($gettok($sock($sockname).mark,4,32) + 1),4,32)
      $gettok($sock($sockname).mark,1-2,32) 07» $sp($gettok($sock($sockname).mark,5-12,32))
    }
    if ($gettok($sock($sockname).mark,4,32) >= 3) { sockclose $sockname | return }
  }
}
alias -l Sp { return $iif($chr(7) isin $1-,$replace($1-,$chr(7),$chr(32)),$replace($1-,$chr(32),$chr(7))) }
Ford
 
Posts: 48
Joined: Wed Oct 28, 2009 1:01 am

Return to Script help

Who is online

Users browsing this forum: No registered users and 1 guest

cron