2 -- Copyright (C) 2011,2013 Toni Gundogdu <legatvs@gmail.com>
3 -- Copyright (C) 2010 quvi project
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 FunnyOrDie
= {} -- Utility functions unique to this script
24 -- Identify the media script.
27 can_parse_url
= FunnyOrDie
.can_parse_url(qargs
),
28 domains
= table.concat({'funnyordie.com'}, ',')
32 -- Parse media properties.
34 quvi
.http
.header('Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0')
35 local p
= quvi
.http
.fetch(qargs
.input_url
).data
37 qargs
.thumb_url
= p
:match('"og:image" content="(.-)"') or ''
38 qargs
.title
= p
:match('"og:title" content="(.-)">') or ''
39 qargs
.id
= p
:match('key:%s+"(.-)"') or ''
41 qargs
.streams
= FunnyOrDie
.iter_streams(p
)
50 function FunnyOrDie
.can_parse_url(qargs
)
51 local U
= require
'socket.url'
52 local t
= U
.parse(qargs
.input_url
)
53 if t
and t
.scheme
and t
.scheme
:lower():match('^http$')
54 and t
.host
and t
.host
:lower():match('funnyordie%.com$')
55 and t
.path
and t
.path
:lower():match('^/videos/%w+')
63 function FunnyOrDie
.iter_streams(p
)
66 -- 41a7516647: added the pattern in the next line, and removed...
67 for u
in p
:gmatch('type: "video/mp4", src: "(.-)"') do table.insert(t
,u
) end
68 for u
in p
:gmatch('source src="(.-)"') do table.insert(t
,u
) end -- ... This.
72 error('no match: media stream URL')
75 local S
= require
'quvi/stream'
78 -- nostd is a dictionary used by this script only. libquvi ignores it.
79 for _
,u
in pairs(t
) do
80 local q
,c
= u
:match('/(%w+)%.(%w+)$')
82 local s
= S
.stream_new(u
)
85 s
.id
= FunnyOrDie
.to_id(s
)
97 function FunnyOrDie
.ch_best(t
)
98 t
[1].flags
.best
= true
101 function FunnyOrDie
.to_id(t
)
102 return string.format("%s_%s", t
.nostd
.quality
, t
.container
)
105 -- vim: set ts=2 sw=2 tw=72 expandtab: