FIX: media/spiegel.lua: title pattern (BACKPORTpt4)
[libquvi-scripts.git] / share / media / charlierose.lua
blob79eed4501dd78d2fe39c5b78fbb552a5ea8ed3d7
1 -- libquvi-scripts
2 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
3 -- Copyright (C) 2010-2012 quvi project
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 CharlieRose = {} -- Utility functions unique to this script.
24 -- Identify the media script.
25 function ident(qargs)
26 return {
27 can_parse_url = CharlieRose.can_parse_url(qargs),
28 domains = table.concat({'charlierose.com'}, ',')
30 end
32 -- Parse media properties.
33 function parse(qargs)
34 local p = quvi.http.fetch(qargs.input_url).data
36 qargs.title = p:match("<title>Charlie Rose%s+-%s+(.-)</title>") or ''
38 qargs.thumb_url = p:match('rel="image_src" href="(.-)"') or ''
40 qargs.id = p:match('view%/content%/(.-)"') or ''
42 qargs.streams = CharlieRose.iter_streams(p)
44 return qargs
45 end
48 -- Utility functions
51 function CharlieRose.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('charlierose%.com$')
56 and t.path and t.path:lower():match('^/view/.-/%d+')
57 then
58 return true
59 else
60 return false
61 end
62 end
64 function CharlieRose.iter_streams(p)
65 local u = p:match('url":"(.-)"') or error("no match: media stream URL")
67 local h = p:match('name="video_height" content="(%d+)"') or 0
68 local w = p:match('name="video_width" content="(%d+)"') or 0
70 local S = require 'quvi/stream'
71 local s = S.stream_new(u)
73 s.video.height = h
74 s.video.width = w
76 return {s}
77 end
79 -- vim: set ts=2 sw=2 tw=72 expandtab: