media/: Use socket.url
[libquvi-scripts.git] / share / media / gaskrank.lua
blob71be932679882d4f0d97f63cdc11b6739e1fec44
1 -- libquvi-scripts
2 -- Copyright (C) 2010-2012 Toni Gundogdu <legatvs@gmail.com>
3 --
4 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
5 --
6 -- This library is free software; you can redistribute it and/or
7 -- modify it under the terms of the GNU Lesser General Public
8 -- License as published by the Free Software Foundation; either
9 -- version 2.1 of the License, or (at your option) any later version.
11 -- This library is distributed in the hope that it will be useful,
12 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
13 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 -- Lesser General Public License for more details.
16 -- You should have received a copy of the GNU Lesser General Public
17 -- License along with this library; if not, write to the Free Software
18 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 -- 02110-1301 USA
22 local Gaskrank = {} -- Utility functions unique to this script
24 -- Identify the media script.
25 function ident(qargs)
26 return {
27 can_parse_url = Gaskrank.can_parse_url(qargs),
28 domains = table.concat({'gaskrank.tv'}, ',')
30 end
32 -- Parse media properties.
33 function parse(qargs)
34 local p = quvi.fetch(qargs.input_url)
36 qargs.thumb_url = p:match('"og:image" content="(.-)"') or ''
38 qargs.title = p:match('"og:title" content="(.-)"') or ''
40 qargs.streams = Gaskrank.iter_streams(p)
42 qargs.id = qargs.streams[1].url:match("/%d+/(%d+)%.%w+") or ''
44 return qargs
45 end
48 -- Utility functions.
51 function Gaskrank.can_parse_url(qargs)
52 local U = require 'socket.url'
53 local t = U.parse(qargs.input_url)
54 if t and t.scheme and t.scheme:lower():match('^http$')
55 and t.host and t.host:lower():match('gaskrank%.tv$')
56 and t.path and t.path:lower():match('^/tv/')
57 then
58 return true
59 else
60 return false
61 end
62 end
64 function Gaskrank.iter_streams(p)
65 local u = p:match("(http://movies.-%.flv)")
66 or error("no match: media stream URL")
67 local S = require 'quvi/stream'
68 return {S.stream_new(u)}
69 end
71 -- vim: set ts=2 sw=2 tw=72 expandtab: