2 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 -- This program is free software: you can redistribute it and/or
7 -- modify it under the terms of the GNU Affero General Public
8 -- License as published by the Free Software Foundation, either
9 -- version 3 of the License, or (at your option) any later version.
11 -- This program 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
14 -- GNU Affero General Public License for more details.
16 -- You should have received a copy of the GNU Affero General
17 -- Public License along with this program. If not, see
18 -- <http://www.gnu.org/licenses/>.
21 local Dorkly
= {} -- Utility functions unique to this script
23 -- Identify the media script.
26 can_parse_url
= Dorkly
.can_parse_url(qargs
),
27 domains
= table.concat({'dorkly.com'}, ',')
31 -- Parse the media properties.
34 if Dorkly
.is_affiliate(qargs
) then
38 -- Make mandatory: the ID is required to fetch the stream data
39 qargs
.id
= qargs
.input_url
:match('/video/(%d+)/')
40 or qargs
.input_url
:match('/embed/(%d+)/')
41 or error('no match: media ID')
43 local t
= {'http://www.dorkly.com/moogaloop/video/', qargs
.id
}
44 local d
= quvi
.http
.fetch(table.concat(t
)).data
46 local L
= require
'quvi/lxph'
47 local P
= require
'lxp.lom'
50 local v
= L
.find_first_tag(x
, 'video')
52 qargs
.duration_ms
= tonumber(L
.find_first_tag(v
, 'duration')[1])
54 qargs
.thumb_url
= L
.find_first_tag(v
, 'thumbnail')[1]
56 qargs
.title
= L
.find_first_tag(v
, 'caption')[1]
58 qargs
.streams
= Dorkly
.iter_streams(L
, v
)
67 function Dorkly
.can_parse_url(qargs
)
68 local U
= require
'socket.url'
69 local t
= U
.parse(qargs
.input_url
)
70 if t
and t
.scheme
and t
.scheme
:lower():match('^http$')
71 and t
.host
and t
.host
:lower():match('dorkly%.com$')
72 and t
.path
and (t
.path
:lower():match('^/video/%d+/')
73 or t
.path
:lower():match('^/embed/%d+/'))
81 function Dorkly
.is_affiliate(qargs
)
82 if not qargs
.input_url
:match('/embed/') then
86 local p
= quvi
.http
.fetch(qargs
.input_url
).data
88 local u
= p
:match('iframe.-src="(.-)"')
89 or error('no match: iframe: src')
91 if not u
:match('^http:') then
92 u
= table.concat({'http:',u
}) -- Fix URL if the scheme is missing.
99 function Dorkly
.iter_streams(L
, v
)
100 local u
= L
.find_first_tag(v
, 'file')[1]
101 local S
= require
'quvi/stream'
102 return {S
.stream_new(u
)}
105 -- vim: set ts=2 sw=2 tw=72 expandtab: