diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2014-02-07 13:39:48 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2014-02-07 13:39:48 +0100 |
commit | 8643c0593feaa1487c3d9a97b024b5235f9f966b (patch) | |
tree | e4b37a8d79be9d0234b663ca5210bcc5ed7df0ea /.local/share/libquvi-scripts/media | |
parent | dcf2fe944db0664ee6d494185b4802ea23418d53 (diff) | |
download | dotfiles-8643c0593feaa1487c3d9a97b024b5235f9f966b.tar.gz dotfiles-8643c0593feaa1487c3d9a97b024b5235f9f966b.tar.bz2 dotfiles-8643c0593feaa1487c3d9a97b024b5235f9f966b.zip |
quvi: Move soup request function to seperate lua lib
Diffstat (limited to '.local/share/libquvi-scripts/media')
-rw-r--r-- | .local/share/libquvi-scripts/media/xvidstage.lua | 37 |
1 files changed, 2 insertions, 35 deletions
diff --git a/.local/share/libquvi-scripts/media/xvidstage.lua b/.local/share/libquvi-scripts/media/xvidstage.lua index 1312e96..a9df736 100644 --- a/.local/share/libquvi-scripts/media/xvidstage.lua +++ b/.local/share/libquvi-scripts/media/xvidstage.lua @@ -12,9 +12,10 @@ end -- Parse media URL. function parse(qargs) + local R = require 'soup_request' local p = { op = "download1", method_free = "1", id = qargs.input_url:match('xvidstage.com/([^/]+)') } - local c = Xvidstage.request(qargs.input_url, "POST", p) + local c = R.request(qargs.input_url, "POST", p) qargs.id = p.id qargs.title = c:match('Dateiname:</td><td[^>]*>(.-)</td>') @@ -89,38 +90,4 @@ function Xvidstage.can_parse_url(qargs) and true or false end -function Xvidstage.request(url, method, params) - local lgi = require 'lgi' - local Soup = lgi.Soup - local req = lgi.Soup.Session():request_http_uri(method, Soup.URI(url)) - - p = {} - for k,v in pairs(params) do - table.insert(p, table.concat({ k, '=', v })) - end - p = table.concat(p, '&') - - if method == "POST" then - req:get_message():set_request("application/x-www-form-urlencoded", 0, p, #p) - end - - function read(stream) - local Bytes = require 'bytes' - local buffer = Bytes.new(4096) - local out = {} - - while true do - local size = stream:read(buffer) - if size <= 0 then - break; - end - table.insert(out, tostring(buffer):sub(1, size)) - end - - return table.concat(out) - end - - return read(req:send()) -end - -- vim: set ts=2 sw=2 tw=72 expandtab: |