mIRC Homepage

Why doesn't this work?

Posted By: Newbie

Why doesn't this work? - 01/02/15 12:39 AM

I've been messing around with this code and even tried adding regex but it just won't give me the length of the video

Code:
on *:TEXT:!yt &:#: { 
  if ($sock(YTube)) .sockclose YTube
  set %link $2
  sockopen -e YTube www.youtube.com 443
}

on *:SOCKOPEN:YTube: {
  sockwrite -nt $sockname GET /watch?v= $+ %link HTTP/1.1
  sockwrite -nt $sockname Host: www.youtube.com $+ $str($crlf,2)
}

on *:SOCKREAD:YTube: {
  if (!$sockerr) {
    var %sockreader | sockread %sockreader
    tokenize 32 %sockreader
    if ($regex(%sockreader,/"length_seconds":".+?"/)) {
      echo -a $1
      unset %link
      sockclose YTube
    }
  }
}
Posted By: judge2020

Re: Why doesn't this work? - 01/02/15 02:31 AM

i think you have a misplaced bracket for the sockerr statement
Code:
on *:SOCKREAD:YTube: {
  if (!$sockerr) {
    var %sockreader | sockread %sockreader
    tokenize 32 %sockreader
  }
    if ($regex(%sockreader,/"length_seconds":".+?"/)) {
      echo -a $1
      unset %link
      sockclose YTube
  }
}
Posted By: judge2020

Re: Why doesn't this work? - 01/02/15 02:33 AM

also here's a debug-like version. you'll be able to see what point it gets to by the echo's.
Code:
on *:TEXT:!yt &:#: {  
  echo -a 1
  if ($sock(YTube)) .sockclose YTube
  set %link $2
  sockopen -e YTube www.youtube.com 443
}

on *:SOCKOPEN:YTube: {
  echo -a 2
  sockwrite -nt $sockname GET /watch?v= $+ %link HTTP/1.1
  sockwrite -nt $sockname Host: www.youtube.com $+ $str($crlf,2)
}

on *:SOCKREAD:YTube: {
  echo -a 3
  if (!$sockerr) {
    var %sockreader | sockread %sockreader
    tokenize 32 %sockreader
    echo -a error $1-
  }
  if ($regex(%sockreader,/"length_seconds":".+?"/)) {
    echo -a $1
    unset %link
    sockclose YTube
    echo -a regex
  }
}


EDIT:
i ran your script with LBr7kECsjcQ, and got these socket errors:
Quote:
error HTTP/1.1 301 Moved Permanently
3
error Date: Sun, 01 Feb 2015 02:34:23 GMT
3
error Server: gwiseguy/2.0
3
error Location: https://www.youtube.com/
3
error X-Frame-Options: SAMEORIGIN
3
error X-XSS-Protection: 1; mode=block; report=https://www.google.com/appserve/security-bugs/log/youtube
3
error Cache-Control: no-cache
3
error Content-Type: text/html; charset=utf-8
3
error Expires: Tue, 27 Apr 1971 19:44:06 EST
3
error P3P: CP="This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en for more info."
3
error X-Content-Type-Options: nosniff
3
error Set-Cookie: VISITOR_INFO1_LIVE=KbLAQ04pw8g; expires=Fri, 02-Oct-2015 14:27:23 GMT; path=/; domain=.youtube.com
3
error Set-Cookie: YSC=IJF3VIdZXqY; path=/; domain=.youtube.com; HttpOnly
3
error Alternate-Protocol: 443:quic,p=0.02
3
error Accept-Ranges: none
3
error Vary: Accept-Encoding
3
error Transfer-Encoding: chunked
Posted By: Sakana

Re: Why doesn't this work? - 01/02/15 05:52 AM

Originally Posted By: Newbie
I've been messing around with this code and even tried adding regex but it just won't give me the length of the video


Your regex isn't correct. This will work

Code:
if ($regex(%sockreader,/"length_seconds":"(.*?)"/)) { 
      echo -a $regml(1) 
      sockclose YTube
}
© 2019 mIRC Discussion Forums