media/tapuz.lua: Rewrite ident function
[libquvi-scripts.git] / share / media / tapuz.lua
blobd238ef67cd929e5c2a438acd5456dd1e3bbdeb00
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 -- Query available formats.
33 function query_formats(self)
34 self.formats = 'default'
35 return self
36 end
38 -- Parse media URL.
39 function parse(self)
40 self.host_id = 'tapuz-flix'
42 self.id = self.page_url:match('/v/watch%-(%d+)%-.*%.html')
43 if not self.id then
44 self.id = self.page_url:match('/showVideo%.asp%?m=(%d+)')
45 or error("no match: media ID")
46 end
48 local xml_url_base = 'v/Handlers/XmlForPlayer.ashx' -- Variable?
49 local mako = 0 -- Does it matter?
50 local playerOptions = '0|1|grey|large|0' -- Does it matter? Format?
52 local p = quvi.fetch(self.page_url)
53 self.title = p:match('<meta name="item%-title" content="([^"]*)" />')
55 local s_fmt =
56 'http://flix.tapuz.co.il/%s?mediaid=%d&autoplay=0&mako=%d'
57 .. '&playerOptions=%s'
59 local xml_url =
60 string.format(s_fmt, xml_url_base, self.id, mako, playerOptions)
62 local xml_page = quvi.fetch(xml_url)
63 self.url = { xml_page:match('<videoUrl>.*(http://.*%.flv).*</videoUrl>') }
65 return self
66 end
69 -- Utility functions.
72 function Tapuz.can_parse_url(qargs)
73 local U = require 'socket.url'
74 local t = U.parse(qargs.input_url)
75 if t and t.scheme and t.scheme:lower():match('^http$')
76 and t.host and t.host:lower():match('flix%.tapuz%.co%.il$')
77 and t.path and (t.path:lower():match('^/v/watch%-.-%.html$')
78 or t.path:lower():match('/showVideo%.asp%?m=%d+'))
79 then
80 return true
81 else
82 return false
83 end
84 end
86 -- vim: set ts=4 sw=4 tw=72 expandtab: