/usr/share/libquvi-scripts/0.9.20131130/media/arte.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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | -- libquvi-scripts v0.9.20131130
-- Copyright (C) 2013 Mohamed El Morabity <melmorabity@fedoraproject.org>
-- Copyright (C) 2012-2013 Toni Gundogdu <legatvs@gmail.com>
-- Copyright (C) 2011 Raphaƫl Droz <raphael.droz+floss@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/>.
--
-- NOTE: Most videos expire some (7?) days after their original broadcast
local Arte = {} -- Utility functions unique to to this script.
-- Identify the media script.
function ident(qargs)
return {
can_parse_url = Arte.can_parse_url(qargs),
domains = table.concat({'arte.tv'}, ',')
}
end
-- Parse media properties.
function parse(qargs)
local J = require 'json'
-- Fetch the video data JSON.
local p = quvi.http.fetch(qargs.input_url).data
local u = p:match('arte_vp_url="(.-/ALL%.json)"')
or error('no match: config URL')
local c = quvi.http.fetch(u).data
local j = J.decode(c)
-- Check the video expiration date.
local d = j['videoJsonPlayer']['VRU']
if d and Arte.has_expired(d) then
error('media no longer available (expired)')
end
qargs.id = j['videoJsonPlayer']['VPI']
qargs.title = j['videoJsonPlayer']['VTI']
qargs.thumb_url = j['videoJsonPlayer']['programImage']
qargs.duration_ms = j['videoJsonPlayer']['videoDurationSeconds'] * 1000
qargs.streams = Arte.iter_streams(j)
return qargs
end
--
-- Utility functions
--
function Arte.can_parse_url(qargs)
local U = require 'socket.url'
local t = U.parse(qargs.input_url)
if t and t.scheme and t.scheme:lower():match('^http$')
and t.host and t.host:lower():match('www.arte%.tv$')
and t.path and t.path:lower():match('^/guide/%w+/')
then
return true
else
return false
end
end
function Arte.iter_streams(j)
local S = require 'quvi/stream'
local d = j['videoJsonPlayer']['VSR']
local r = {}
for _, v in pairs(d) do
local s = v['streamer'] -- Handle available RTMP streams.
and table.concat({v['streamer'], 'mp4:', v['url']})
or v['url']
local t = S.stream_new(s)
t.video = {
bitrate_kbit_s = v['bitrate'],
width = v['width'],
height = v['height']
}
-- Save the property values that may be used later, these depend
-- on the language setting. Many of these are the so called
-- "optional media properties". The 'nostd' dictionary is used
-- only by this script. libquvi ignores it completely.
t.nostd = {
quality = v['quality'],
-- versionProg is an ID corresponding to the video language.
-- versionProg == 1 -> default language version, matching the video URL
-- language
-- versionProg == 2 -> alternate language version
-- versionProg == 3 -> original version with default language subtitles
-- versionProg == 8 -> default language version with subtitle for
-- hard-of-hearing
versionProg = tonumber(v['versionProg']),
versionCode = v['versionCode'],
mediaType = v['mediaType']
}
t.id = Arte.to_id(t)
table.insert(r, t)
end
if #r >1 then
Arte.ch_best(S, r)
end
return r
end
function Arte.ch_best(S, t, l)
local r = t[1]
r.flags.best = true
for _,v in pairs(t) do
if Arte.is_best_stream(v, r) then
r = S.swap_best(r, v)
end
end
end
function Arte.has_expired(e)
local d, mo, y, h, m, sc = e:match('(%d+)/(%d+)/(%d+) (%d+):(%d+):(%d+)')
local t = os.time({ year = y, month = mo, day = d,
hour = h, min = m, sec = sc })
return (t - os.time()) < 0
end
-- Return an ID for a stream.
function Arte.to_id(t)
-- Streaming protocol
local s = (t.nostd.mediaType == '') and 'http' or t.nostd.mediaType
return string.format("%s_%s_%s", t.nostd.quality, s, t.nostd.versionCode)
:gsub('%s?%-%s?', '_'):lower()
end
-- Check which stream of two is the "best".
function Arte.is_best_stream(v1, v2)
-- Select stream in default language version rather than in alternate.
if v2.nostd.versionProg == 2
and v1.nostd.versionProg ~= 2 then
return true
end
-- Select stream in default language version rather than in original
-- version/with subtitles for hard-of-hearing.
if v1.nostd.versionProg < v2.nostd.versionProg then
return true
end
return v1.video.height > v2.video.height
or (v1.video.height == v2.video.height
and v1.video.bitrate_kbit_s > v2.video.bitrate_kbit_s)
end
-- vim: set ts=2 sw=2 tw=72 expandtab:
|