media/tagtele.lua: Relicense under AGPLv3+
[libquvi-scripts.git] / share / media / tapuz.lua
blob2bbd11c2061eb8686bf5223e17838714dc0b3c75
1 -- libquvi-scripts
2 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
3 -- Copyright (C) 2012 Tzafrir Cohen <tzafrir@cohens.org.il>
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 Tapuz = {} -- Utility functions unique to this script
24 -- Identify the media script.
25 function ident(qargs)
26 return {
27 can_parse_url = Tapuz.can_parse_url(qargs),
28 domains = table.concat({'flix.tapuz.co.il'}, ',')
30 end
32 -- Parse the media properties.
33 function parse(qargs)
35 -- Make mandatory: the ID required to fetch the XML data
36 qargs.id = qargs.input_url:match('/v/watch%-(%d+)%-.*%.html')
37 if not qargs.id then
38 qargs.id = qargs.input_url:match('/showVideo%.asp%?m=(%d+)')
39 or error("no match: media ID")
40 end
42 local t = {
43 'http://flix.tapuz.co.il/v/Handlers/XmlForPlayer.ashx?mediaid=',
44 qargs.id, '&playerOptions=0|1|grey|large|0&mako=0'
47 local d = quvi.http.fetch(table.concat(t)).data
48 local L = require 'quvi/lxph'
50 local X = require 'lxp.lom'
51 local x = X.parse(d)
53 qargs.duration_ms = tonumber(L.find_first_tag(x, 'duration')[1] or 0)*1000
55 qargs.thumb_url = L.find_first_tag(x, 'thumbUrl')[1]
57 qargs.title = L.find_first_tag(x, 'title')[1]
59 qargs.streams = Tapuz.iter_streams(L, x)
61 return qargs
62 end
65 -- Utility functions.
68 function Tapuz.can_parse_url(qargs)
69 local U = require 'socket.url'
70 local t = U.parse(qargs.input_url)
71 if t and t.scheme and t.scheme:lower():match('^http$')
72 and t.host and t.host:lower():match('flix%.tapuz%.co%.il$')
73 and t.path and (t.path:lower():match('^/v/watch%-.-%.html$')
74 or t.path:lower():match('/showVideo%.asp%?m=%d+'))
75 then
76 return true
77 else
78 return false
79 end
80 end
82 function Tapuz.iter_streams(L, x)
83 local u = L.find_first_tag(x, 'videoUrl')[1]
84 or error('no match: media stream URL')
85 local S = require 'quvi/stream'
86 return {S.stream_new(u)}
87 end
89 -- vim: set ts=2 sw=2 tw=72 expandtab: