2 -- Copyright (C) 2012,2013 Toni Gundogdu <legatvs@gmail.com>
3 -- Copyright (C) 2010-2011 Lionel Elie Mamane <lionel@mamane.lu>
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
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 CollegeHumor
= {} -- Utility functions unique to this script
24 -- Identify the media script.
27 can_parse_url
= CollegeHumor
.can_parse_url(qargs
),
28 domains
= table.concat({'collegehumor.com'}, ',')
32 -- Parse the media properties.
34 local p
= quvi
.http
.fetch(qargs
.input_url
).data
36 local u
= p
:match('source type=.- src="(.-)"')
37 or error('no match: media stream URL')
39 if u
:match('%.%w+$') then -- Stream URL ends to a file extension?
40 local S
= require
'quvi/stream'
41 qargs
.streams
= {S
.stream_new(u
)}
43 qargs
.goto_url
= u
-- Affiliate content.
44 return qargs
-- Pass the new page URL back to the library.
48 tonumber(p
:match('"video:duration" content="(%d+)"') or 0) *1000
50 qargs
.thumb_url
= p
:match('"og:image" content="(.-)"') or ''
52 qargs
.title
= p
:match('"og:title" content="(.-)"') or ''
54 qargs
.id
= qargs
.input_url
:match('/video/(%d+)/')
55 or qargs
.input_url
:match('/embed/(%d+)/') or ''
64 function CollegeHumor
.can_parse_url(qargs
)
65 local U
= require
'socket.url'
66 local t
= U
.parse(qargs
.input_url
)
67 if t
and t
.scheme
and t
.scheme
:lower():match('^http$')
68 and t
.host
and t
.host
:lower():match('collegehumor%.com$')
69 and t
.path
and (t
.path
:lower():match('^/video/%d+/')
70 or t
.path
:lower():match('^/embed/%d+/'))
78 -- vim: set ts=2 sw=2 tw=72 expandtab: