Connecting to https in Lua, Help needed

Discuss your Lua playlist, album art and interface scripts.
Vhati
Blank Cone
Blank Cone
Posts: 16
Joined: 06 Apr 2011 08:07

Connecting to https in Lua, Help needed

Postby Vhati » 19 May 2012 13:14

I'm tinkering with the idea of reading messages live from twitter (from a group of people simultaneously watching a movie) and using osd to show them as if they were subtitles...

The hangup is that Twitter's live API only accepts a POST request over https.

VLC's lua can do a GET by letting an access module do all the work...

Code: Select all

local stream = vlc.stream("https://developers.google.com/webmasters/control-crawl-index/docs/robots_txt") local data = "" while data do data = stream:read(65536) vlc.msg.dbg("[appname] ".. data) break end
This would be great but the access module won't POST.

Note: Some servers run afoul of gnutls root cert issues, but luckily not the google test url above or twitter, on my system. Incidentally certs are read from a file (~/.vlc/ssl/certs/ca-certificates.crt) on linux and a MMC snap-in (certmgr.msc) on windows.


The alternative seems to be vlc.net.connect_tcp(host, port), but that looks like I'd have to handle TLS myself.


For the curious, here's the easy way to query Twitter.*
Lookup a user's numeric id to hardcode in a script (look for /user/id)...

Code: Select all

https://api.twitter.com/1/users/show.xml?screen_name=CHANGE_ME or https://api.twitter.com/1/users/show.json?screen_name=CHANGE_ME
curl -d "follow=THAT_ID" "https://YOUR_USER:YOUR_PASS@stream.twit ... ilter.json"
Then you get a continuous line-oriented json of tweets as they happen. This'll be pretty quiet unless an event is planned.
I just can't figure out how to send that "follow=012345" POST data.

Tantalizingly, I can use the access module to GET a rather overwhelming sample stream intended for testing.
curl "https://YOUR_USER:YOUR_PASS@dev.twitter ... ses/sample"
That'll result in a very busy terminal.


* The more elaborate OAuth method is what's officially recommended; if I can get this working, I can reference the Share on Twitter extension for that.
Last edited by Vhati on 20 May 2012 18:34, edited 4 times in total.

Vhati
Blank Cone
Blank Cone
Posts: 16
Joined: 06 Apr 2011 08:07

Re: Connecting to https in Lua, Help needed

Postby Vhati » 19 May 2012 13:19

Hrm, I probably wouldn't be able to poll the a vlc.stream() object to avoid blocking.

Requesting a vlc.net func to open a TLS'd connection may be asking too much...

Vhati
Blank Cone
Blank Cone
Posts: 16
Joined: 06 Apr 2011 08:07

Re: Connecting to https in Lua, Help needed

Postby Vhati » 20 May 2012 15:43

Wow, I must've been looking at an old API doc at the time (Google's cache circa 2012-04-12 only mentioned POST).
The link I included in the post above resolved my immediate problem.
"Both GET and POST requests are supported"
Which means this works.
curl "https://YOUR_USER:YOUR_PASS@stream.twit ... ow=THAT_ID"

Now I just have to periodically read chunks from the stream, osd a couple of the recent tweets, and silently consume the rest, while trying to avoid blocking or buffer capacity issues...


Return to “Scripting VLC in lua”

Who is online

Users browsing this forum: No registered users and 13 guests