FIX: media/spiegel.lua: title pattern (BACKPORTpt4)
[libquvi-scripts.git] / share / media / videa.lua
blobad7e58d47e99215debd67170391c0c52568da463
1 -- libquvi-scripts
2 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
3 -- Copyright (C) 2011 Bastien Nocera <hadess@hadess.net>
4 --
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 --
7 -- This program is free software: you can redistribute it and/or
8 -- modify it under the terms of the GNU Affero General Public
9 -- License as published by the Free Software Foundation, either
10 -- version 3 of the License, or (at your option) any later version.
12 -- This program is distributed in the hope that it will be useful,
13 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
14 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 -- GNU Affero General Public License for more details.
17 -- You should have received a copy of the GNU Affero General
18 -- Public License along with this program. If not, see
19 -- <http://www.gnu.org/licenses/>.
22 local Videa = {} -- Utility functions unique to this script
24 -- Identify the media script.
25 function ident(qargs)
26 Videa.normalize(qargs)
27 return {
28 can_parse_url = Videa.can_parse_url(qargs),
29 domains = table.concat({'videa.hu'}, ',')
31 end
33 -- Parse the media properties.
34 function parse(qargs)
35 Videa.normalize(qargs)
37 local p = quvi.http.fetch(qargs.input_url).data
38 local s = p:match('videok%((.-),player') or error('no match: videok')
40 local J = require 'json'
41 local j = J.decode(s)
43 qargs.thumb_url = p:match('"og:image"%s+content="(.-)"') or ''
45 qargs.duration_ms = tonumber(j['video']['duration'] or 0) * 1000
47 qargs.title = j['video']['title'] or ''
49 qargs.id = j['vcode'] or ''
51 qargs.streams = Videa.iter_streams(j)
53 return qargs
54 end
57 -- Utility functions
60 function Videa.can_parse_url(qargs)
61 local U = require 'socket.url'
62 local t = U.parse(qargs.input_url)
63 if t and t.scheme and t.scheme:lower():match('^http$')
64 and t.host and t.host:lower():match('^videa%.hu$')
65 and t.path and t.path:lower():match('^/videok/.+/.+%-%w+$')
66 then
67 return true
68 else
69 return false
70 end
71 end
73 function Videa.normalize(qargs) -- "Normalize" an embedded URL
74 local s = qargs.input_url:match('/flvplayer%.swf%?v=(.-)$')
75 if s then
76 qargs.input_url = table.concat({'http://videa.hu/videok/',s},'')
77 end
78 end
80 function Videa.iter_streams(j)
81 local w = j['swf_url']:match('=(.-)&') or error('no match: f parameter')
82 local t = {'http://videa.hu/static/video/', (w:gsub('%.%d+$',''))}
84 local S = require 'quvi/stream'
85 local s = S.stream_new(table.concat(t,''))
87 s.video.height = tonumber(j['video']['height'] or 0)
88 s.video.width = tonumber(j['video']['width'] or 0)
90 return {s}
91 end
93 -- vim: set ts=2 sw=2 tw=72 expandtab: