From 5127283f417ddeb3b3843bd96172bc9d463f08fb Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Thu, 6 Feb 2014 13:04:08 +0100 Subject: quvi 0.9: Add script from xvidstage.com Have to use own http client code, to be able to do POST requests. Using libsoup with lua gobject introspection (so lgi is required). --- .local/share/libquvi-scripts/media/xvidstage.lua | 90 ++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .local/share/libquvi-scripts/media/xvidstage.lua diff --git a/.local/share/libquvi-scripts/media/xvidstage.lua b/.local/share/libquvi-scripts/media/xvidstage.lua new file mode 100644 index 0000000..15396cd --- /dev/null +++ b/.local/share/libquvi-scripts/media/xvidstage.lua @@ -0,0 +1,90 @@ +-- libquvi-scripts + +local Xvidstage = {} + +-- Identify the script. +function ident(qargs) + return { + domains = table.concat({'xvidstage.com'}, ','), + can_parse_url = Xvidstage.can_parse_url(qargs) + } +end + +-- Parse media URL. +function parse(qargs) + local p = { op = "download1", method_free = "1", + id = qargs.input_url:match('xvidstage.com/([^/]+)') } + local c = Xvidstage.request(qargs.input_url, "POST", p) + + qargs.id = p.id + qargs.title = c:match('Dateiname:]*>(.-)') + qargs.streams = Xvidstage.iter_streams(c, qargs) + + return qargs +end + +function Xvidstage.iter_streams(c, qargs) + local S = require 'quvi/stream' + + local mp3_url = c:match("addVariable%('file','(.-%.mp3)'%)") + if mp3_url then + local s = S.stream_new(mp3_url) + s.container = "mp3" + return { s } + end + + local hash_pattern = string.rep('[a-z0-9]', 56) + container, hash, port = c:match('|([^|]-)|(' .. hash_pattern .. ')|(%d-)|') + ip4, ip3, ip2, ip1 = c:match('|(%d-)|+(%d-)|+(%d-)|+(%d-)|') + + local ip = table.concat({ip1,ip2,ip3,ip4},'.') + local url = { "http://", ip , ':', port, '/d/', hash, '/', qargs.title } + local s = S.stream_new(table.concat(url)) + s.container = container + return { s } +end + +function Xvidstage.can_parse_url(qargs) + local U = require 'socket.url' + local t = U.parse(qargs.input_url) + + return t and t.scheme and t.scheme:lower():match('^http$') + and t.host and t.host:lower():match('xvidstage%.com$') + 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: -- cgit