mIRC Home    About    Download    Register    News    Help

Print Thread
D
DharmaTurtle
DharmaTurtle
D
I'm trying to get metadata of youtube links echoed beneath them when they're posted.

Code:
Alias youtube {
  sockClose youtube
  sockOpen youtube gdata.youtube.com 80
}

on *:SockOpen:youtube.*: {
  sockwrite -nt $sockname GET /feeds/api/videos/oqT14k6BsC0 HTTP/1.1
  sockwrite -nt $sockname Host: gdata.youtube.com
  sockwrite -nt $sockname User-Agent: mIRC Script
  ; sockwrite -nt $sockname Cache-Control: no-cache
  sockwrite -nt $sockname Accept-Encoding: gzip
  sockwrite -nt $sockname $crlf
}

on *:SockRead:youtube.*: {
  var %read
  sockRead %read
  echo -a zzzzzzzzzzzzz %read
}


For the majority of youtube links, this code works fine. However, every now and then, the sockread messes up and inserts random characters for no reason (as far as I can see).

For example, for the video ID oqT14k6BsC0, I get

Code:
blahblahblah...<media:title type='plain'>League of Legends - Spectator Mode</media:title><yt:duration seconds='277'/></media:group><gd:rating averag
zzzzzzzzzzzzz 9d
zzzzzzzzzzzzz e='4.924626' max='5' min='1' numRaters='9287'...blahblahblah


If you look at the link: http://gdata.youtube.com/feeds/api/videos/oqT14k6BsC0

You can see that "9d" never appears. Where did that come from? Why is it on its own line? How do I get rid of it? They occur in places that mess up my parsing of the XML. In the code above for example, it prevents me from getting the "rating" of the video since the tag head and the value are on different lines.

Thanks very much!

Joined: Jan 2004
Posts: 1,330
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,330
You can't depend on getting everything you want on a single line, or in the same /sockread. It's best to save the entire response from the server and then parse it (maybe you're doing so already).

As for your problem, the server would have sent a "Transfer-Encoding: chunked" header (the 9d is hex for the number of bytes it will send next). This is an option for HTTP/1.1 responses from the server. I don't know of a way to stop it, other than requesting HTTP/1.0. If you must use 1.1, you will need to handle this encoding.


Link Copied to Clipboard