Set release details for 0.2.13
[quvi.git] / share / lua / website / collegehumor.lua
blob34d23430fac6d7f62e3fae44fd0a965e686b83d3
2 -- quvi
3 -- Copyright (C) 2010 Lionel Elie Mamane <lionel@mamane.lu>
4 --
5 -- This file is part of quvi <http://quvi.sourceforge.net/>.
6 --
7 -- This library is free software; you can redistribute it and/or
8 -- modify it under the terms of the GNU Lesser General Public
9 -- License as published by the Free Software Foundation; either
10 -- version 2.1 of the License, or (at your option) any later version.
12 -- This library 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 GNU
15 -- Lesser General Public License for more details.
17 -- You should have received a copy of the GNU Lesser General Public
18 -- License along with this library; if not, write to the Free Software
19 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 -- 02110-1301 USA
23 -- Identify the script.
24 function ident (self)
25 package.path = self.script_dir .. '/?.lua'
26 local C = require 'quvi/const'
27 local r = {}
28 r.domain = "collegehumor.com"
29 r.formats = "default"
30 -- Commented out due to limited hd support
31 -- r.formats = "default|best|hd"
32 r.categories = C.proto_http
33 r.handles =
34 (self.page_url ~= nil and self.page_url:find(r.domain) ~= nil)
35 return r
36 end
38 -- Parse video URL.
39 function parse (self)
40 self.host_id = "collegehumor"
42 local success, _, vid =
43 self.page_url:find("^http://www%.collegehumor%.com/video:(%d+)")
45 if ( success == nil ) then
46 error("expected URL beginning with 'http://collegehumor.com/video:'")
47 end
49 self.id = vid
51 local page = quvi.fetch(self.page_url)
52 local _,_,s = page:find('<meta name="title" content="(.-)"')
53 self.title = s or error("no match: video title")
55 local page =
56 quvi.fetch("http://www.collegehumor.com/moogaloop/video:" .. vid,
57 {fetch_type = 'config'})
59 local _,_,s = page:find('<file>([%w%p]+)</file>')
60 local default = s or error("no match: default quality URL")
62 local _,_,s = page:find('<hq>([%w%p]+)</hq>')
63 local hq = s
65 self.url = { default }
66 if (self.requested_format == "hd" or self.requested_format == "best") then
67 if ( hq ~= nil ) then
68 self.url = { hq }
69 end
70 end
72 return self
73 end
75 -- vim: set ts=4 sw=4 tw=72 expandtab: