/usr/share/libquvi-scripts/0.9.20131130/media/vzaar.lua is in libquvi-scripts-0.9 0.9.20131130-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | -- libquvi-scripts v0.9.20131130
-- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
--
-- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
--
-- This program is free software: you can redistribute it and/or
-- modify it under the terms of the GNU Affero General Public
-- License as published by the Free Software Foundation, either
-- version 3 of the License, or (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU Affero General Public License for more details.
--
-- You should have received a copy of the GNU Affero General
-- Public License along with this program. If not, see
-- <http://www.gnu.org/licenses/>.
--
local Vzaar = {} -- Utility functions unique to this script
-- Identify the media script.
function ident(qargs)
return {
can_parse_url = Vzaar.can_parse_url(qargs),
domains = table.concat({'vzaar.com'}, ',')
}
end
-- Parse the media properties.
function parse(qargs)
local U = require 'socket.url'
local r = Vzaar.normalize(U, qargs.input_url)
local u = U.parse(r)
-- Make ID mandatory: It is required to fetch
qargs.id = u.path:match('^/videos/(%d+)$') or error('no match: media ID')
local t = {u.scheme, '://view.vzaar.com/', qargs.id, '/player'}
local p = quvi.http.fetch(table.concat(t)).data
local d = p:match('data%-setup="(.-)"') or
error('no match: data-setup')
local E = require 'quvi/entity'
local J = require 'json'
local j = J.decode(E.convert_html(d))
local l = j['playlist'][1] or error('no data: playlist')
qargs.streams = Vzaar.iter_streams(l)
qargs.thumb_url = l['thumb_url']
qargs.title = l['title']
return qargs
end
--
-- Utility functions.
--
function Vzaar.can_parse_url(qargs)
local U = require 'socket.url'
local u = Vzaar.normalize(U, qargs.input_url)
local t = U.parse(u)
if t and t.scheme and t.scheme:lower():match('^https?$')
and t.host and t.host:lower():match('^vzaar%.com$')
and t.path and t.path:lower():match('^/videos/%d+$')
then
return true
else
return false
end
end
function Vzaar.normalize(U, url)
-- Sanity checks.
if not url then
return url
end
local u = U.parse(url)
if not u or not u.host or not u.path then
return url
end
-- Shortened URLs (http://vzaar.tv/:id:).
u.host = u.host:gsub('vzaar%.tv', 'vzaar.com')
-- Embedded media URLs (http://view.vzaar.com/:id:/player).
u.host = u.host:gsub('^view%.', '')
u.path = u.path:gsub('/player', '')
-- Fix path.
u.path = u.path:gsub('^/(%d+)$', '/videos/%1')
-- Rebuild and return the media URL.
return U.build(u)
end
function Vzaar.iter_streams(l)
local S = require 'quvi/stream'
return {S.stream_new(l['video_content_url'])}
end
--[[
local function test_normalize()
local test_cases = {
{url='http://vzaar.tv/1020181', -- Shortened URL.
expect='http://vzaar.com/videos/1020181'},
{url='http://view.vzaar.com/1020181/player', -- Embedded URL.
expect='http://vzaar.com/videos/1020181'},
{url='http://vzaar.com/videos/1020181', -- Media URL.
expect='http://vzaar.com/videos/1020181'},
}
local U = require 'socket.url'
local i,e = 0,0
for _,v in pairs(test_cases) do
local r = Vzaar.normalize(U, v.url)
if r ~= v.expect then
print(string.format('input: %s (#%s)\nexpected: %s\ngot: %s',
v.url, i, v.expect, r))
e = e+1
end
i = i+1
end
print((e==0) and 'tests OK' or error('failed tests: '..e))
end
test_normalize()
]]--
-- vim: set ts=2 sw=2 tw=72 expandtab:
|