mIRC Home    About    Download    Register    News    Help

Print Thread
Why doesn't this work? #250833 01/02/15 12:39 AM
Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
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
    }
  }
}

Last edited by Newbie; 01/02/15 01:02 AM.
Re: Why doesn't this work? [Re: Newbie] #250840 01/02/15 02:31 AM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
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
  }
}


#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Re: Why doesn't this work? [Re: judge2020] #250842 01/02/15 02:33 AM
Joined: Mar 2014
Posts: 215
J
judge2020 Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Mar 2014
Posts: 215
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

Last edited by judge2020; 01/02/15 02:35 AM. Reason: edit

#imAbeginner
i made a chat bot for mark_paintball! http://twitch.tv/mark_paintball
Re: Why doesn't this work? [Re: Newbie] #250846 01/02/15 05:52 AM
Joined: Sep 2014
Posts: 259
S
Sakana Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Sep 2014
Posts: 259
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
}

Last edited by Sakana; 01/02/15 09:57 AM.