2 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
3 -- Copyright (C) 2012 Ross Burton <ross@burtonini.com>
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 Lego
= {} -- Utility functions unique to this script
24 -- Identify the media script.
27 can_parse_url
= Lego
.can_parse_url(qargs
),
28 domains
= table.concat({'lego.com'}, ',')
32 -- Parse media properties.
34 local p
= quvi
.http
.fetch(qargs
.input_url
).data
36 if p
:match('FirstVideoData') then
37 Lego
.parse_movies(qargs
, p
)
39 Lego
.parse_videos(qargs
,p
)
49 function Lego
.can_parse_url(qargs
)
50 local U
= require
'socket.url'
51 local t
= U
.parse(qargs
.input_url
)
52 if t
and t
.scheme
and t
.scheme
:lower():match('^http$')
53 and t
.host
and t
.host
:lower():match('lego%.com$')
54 and t
.path
and (t
.path
:lower():match('/movies/')
55 or t
.path
:lower():match('/videos$'))
63 function Lego
.movies_iter_streams(j
)
64 local v
= j
['VideoHtml5'] or error('no match: VideoHtml5')
65 local u
= v
['Url'] or error('no match: media stream URL')
66 local S
= require
'quvi/stream'
67 return {S
.stream_new(u
)}
70 function Lego
.movies_thumb(qargs
, p
)
71 local t
= {'thumbNavigation.+', '<img src="(.-)" alt="',qargs
.title
, '"/>',}
72 qargs
.thumb_url
= p
:match(table.concat(t
,'') or '')
75 function Lego
.parse_movies(qargs
, p
) -- /movies/
76 local d
= p
:match('FirstVideoData = (.-);')
77 or error('no match: FirstVideoData')
79 local J
= require
'json'
82 qargs
.title
= j
['Name'] or ''
83 Lego
.movies_thumb(qargs
, p
)
85 qargs
.streams
= Lego
.movies_iter_streams(j
)
86 qargs
.id
= j
['LikeObjectGuid'] or ''
89 function Lego
.videos_iter_streams(L
, i
)
90 local u
= L
.find_first_tag(i
, 'movie')[1]
91 local S
= require
'quvi/stream'
92 return {S
.stream_new(u
)}
95 function Lego
.parse_videos(qargs
, p
) -- /videos?video=ID
96 local d
= p
:match('name="flashvars" value="configxml=(.-</lego>)')
97 or error('no match: flashvars: configxml')
99 local L
= require
'quvi/lxph'
100 local P
= require
'lxp.lom'
103 local m
= L
.find_first_tag(x
, 'movieplayer')
105 local c
= L
.find_first_tag(m
, 'content')
106 local i
= L
.find_first_tag(c
, 'item')
108 qargs
.title
= L
.find_first_tag(i
, 'trackingName')[1]
109 qargs
.thumb_url
= L
.find_first_tag(i
, 'cover')[1]
111 qargs
.id
= (qargs
.input_url
:match('video=%{(.-)%}') or ''):lower()
112 qargs
.streams
= Lego
.videos_iter_streams(L
, i
)
115 -- vim: set ts=2 sw=2 tw=72 expandtab: