media/: Use socket.url
[libquvi-scripts.git] / share / media / break.lua
blob20976667922d9a7bce82c1bbbe5e348cd1aaaf30
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 Break = {} -- Utility functions unique to this script
24 -- Identify the media script.
25 function ident(qargs)
26 return {
27 can_parse_url = Break.can_parse_url(qargs),
28 domains = table.concat({'break.com'}, ',')
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 ''
37 qargs.title = p:match('id="vid_title" content="(.-)"') or ''
38 qargs.id = p:match("ContentID='(.-)'") or ''
40 local n = p:match("FileName='(.-)'") or error("no match: file name")
41 local h = p:match('flashVars.icon = "(.-)"') or error("no match: file hash")
43 qargs.streams = Break.iter_streams(n, h)
45 return qargs
46 end
49 -- Utility functions.
52 function Break.can_parse_url(qargs)
53 local U = require 'socket.url'
54 local t = U.parse(qargs.input_url)
55 if t and t.scheme and t.scheme:lower():match('^http$')
56 and t.host and t.host:lower():match('break%.com$')
57 and t.path and t.path:lower():match('^/index/')
58 then
59 return true
60 else
61 return false
62 end
63 end
65 function Break.iter_streams(n, h)
66 local u = string.format("%s.flv?%s", n, h)
67 local S = require 'quvi/stream'
68 return {S.stream_new(u)}
69 end
71 -- vim: set ts=2 sw=2 tw=72 expandtab: