mIRC Homepage

youtube script needs a slight upgrade

Posted By: Pescados666

youtube script needs a slight upgrade - 17/12/11 06:20 AM

Can anyone suggest a more efficient way to get the video id without it messing up on links like, http://www.youtube.com/watch?v=VecHdfXeXkA#t=1m, http://www.youtube.com/watch?feature=player_embedded&v=8jnfr_j6cdi , youtu.be , or any others you can think of.

I could always use another script, however, I like that this one works with the API. I couldn't find any others that did that.

Code:
; Requires the $download snippet can be found here: http://sephiroth.bounceme.net/forum/viewtopic.php?t=104
; No need to change anything normally
; Simply paste it to remote and you will get an echo after someone pasted a youtube uri
; if you wanna use it for a bot change the marked line
on *:text:*youtube*:#: {
  var %url = $wildtok($1-,*v=*, 1, 32)
  ;  var %url = $wildtok($1-,*http*://*youtube*/watch?v=*, 1, 32)

  if ($youtube(%url)) {
    tokenize 9 $ifmatch
    ; Author -> $1
    ; Duration -> $2
    ; Rating -> $3
    ; Date (last updated OR published) -> $4
    ; Preview Picture -> $5
    ; Title -> $6
    /*
    change the echo line to a msg # line and it will be posted to the channel :)
    */
  msg # 1,0You0,4Tube15,10 Title: $6 (Rating: $3 $+ ) Length: $2 Author: $1   }
}
alias youtube {
  ; http://www.youtube.com/watch?v=B0fFDk2M0zE&feature=fvhl
  ; example: $youtube(...youtube.com/watch?v=vid)
  var %x = $gettok($1-,2-,63)
  %x = $gettok(%x,1,38)
  if ($gettok(%x,1,61) == v) { %x = $gettok(%x,2,61) }
  else { return $false }
  if ($download(tmpfile,GET,http://gdata.youtube.com/feeds/api/videos/ $+ %x ,2)) {
    bread tmpfile 0 $lof(tmpfile) &bin
    var %string = $b(&bin,<author>)
    if ($regex(%string,/\<author\>\<name\>(.*)\<\/name\>/ig)) { var %author = $regml(1) }
    var %string = $b(&bin,<yt:duration)
    if ($regex(%string,/\<yt:duration seconds='([\d]+)'\/\>/ig)) { var %duration = $gmt($regml(1),HH;nn:ss) }
    var %string = $b(&bin,<gd:rating)
    if ($regex(%string,/average='([^']+)' max='([\d]+)'/ig)) { var %rating = $round($regml(1),3) }
    var %string = $b(&bin,<title)
    if ($regex(%string,/type='text'>([^<]+)/ig)) { var %title = $regml(1) }
    var %string = $b(&bin,<updated>)
    if ($regex(%string,/\<updated>([\d]{4})-([\d]{2})-([\d]{2})T([\d]{2}:[\d]{2})\:/ig)) { var %date = $regml(3) $+ . $+ $regml(2) $+ . $+ $regml(1) $regml(4) }
    else {
      var %string = $b(&bin,<published>)
      if ($regex(%string,/\<published>([\d]{4})-([\d]{2})-([\d]{2})T([\d]{2}:[\d]{2})\:/ig)) { var %date = $regml(3) $+ . $+ $regml(2) $+ . $+ $regml(1) $regml(4) }
    }
    var %preview = http://i.ytimg.com/vi/ $+ %x $+ /0.jpg
    if ($isfile(tmpfile)) { !.remove tmpfile }
    %x = $t(%author,%duration,%rating,%date,%preview,%title)
  }
  else { var %x = $false }
  if ($isfile(tmpfile)) { !.remove tmpfile }
  return %x
}
alias -l t { var %x = $0,%o | while (%x) { %o = $ [ $+ [ %x ] ] $+ $chr(9) $+ %o | dec %x } | return %o }
alias -l b { return $bvar($1,$bfind($1,1,$2).text,800).text }


Thanks!
Posted By: Sephiroth_

Re: youtube script needs a slight upgrade - 21/01/12 07:29 AM

I updated it, just check http://sephiroth.bounceme.net/forum/viewtopic.php?t=111
Posted By: Lou

Re: youtube script needs a slight upgrade - 26/08/14 06:13 PM

Ah yes, very nice, together with the preview & download script too. I've been lookin fo "a" youtube script for my sysreset and most others wouldn't run with sysreset runnin with mIRC 6.21, though this one does it and many thanks. laugh

Though the reason I'm posting is that I would like an addition for it perhaps to be implemented where one can choose which chans the script would be active in and which it will not, as there are some that don't want it in their chans.

Many thanks and I'm hoping that there might be a solution.

Cheers n bai fo now \o.
Posted By: Sjoepele

Re: youtube script needs a slight upgrade - 27/08/14 10:29 AM

So you need a toggle to turn it on or off? I stripped this from RadioBot to make you able to do just that. just type !youtube on or !youtube off to toggle.
Code:
on *:TEXT:!youtube*:#: {
  if ($nick isop $chan) {
    if ($2 == on) {
      if (%youtube.On. [ $+ [ $network ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] == $null) {
        set %youtube.On. [ $+ [ $network ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] 1
        msg $chan Youtube Info is now enabled on $chan .
      }
      else {
        msg $chan Youtube Info is already enabled on $chan .
      }
    }
    if ($2 == off) {
      if (%youtube.On. [ $+ [ $network ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] != $null) {
        unset %youtube.On. [ $+ [ $network ] ] [ $+ [ . ] ] [ $+ [ $chan ] ]
        msg $chan Youtube Info now disabled on $chan  $+ . 
      }
      else {
        msg $chan Youtube Info was already disabled on $chan  $+ .
      }
    }
  }
}


and then add this to the 'on text' events to make them check if they should fire (make sure to close the bracket on the end of the event, ofcourse)
Code:
if (%youtube.On. [ $+ [ $network ] ] [ $+ [ . ] ] [ $+ [ $chan ] ] != $null) {


Have not tested it in this particular script but it should work, i use it all the time.
Posted By: Lou

Re: youtube script needs a slight upgrade - 30/08/14 09:20 PM

Thank you Sjoepele .......
I'm not a scripter or anythin, though if I sit down to try n make somethin work, I'd most possibly get it. So with that, not knowin anythin abt the script to start with, I spent like overnite to get it to work, and it works ......... thank you!

Though, it being a nice feature as in giving access to the bot to the channel's ops, I'm in 10 chans and I don't have axs to 4 of them. So all I can do is turn the whole thing off with the "false" comment. So this is now an op's bot, not my bot any longer if I don't have ops in a chan. How do I gain axs to it to have the same commands as what a channel's op has with it? And also I wouldn't just like any op playin around with it etc, I would possibly have something like an "add user" thing/option to the bot so I can have a say as to who does what with it please. Or rather maybe just turning the op's axs to the script off and making the host the true op of the script ...... laugh

Once again ....... nice option, but ..... ummmmmmmm ..... rather not just for any op!
© 2019 mIRC Discussion Forums