3 -- Copyright (C) 2011 quvi project
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
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
23 local IMDB
= {} -- Utility functions unique to this script
25 -- Identify the script.
27 package
.path
= self
.script_dir
.. '/?.lua'
28 local C
= require
'quvi/const'
30 r
.domain
= 'imdb%.com'
31 r
.formats
= 'default|best'
32 local B
= require
'quvi/bit'
33 r
.categories
= B
.bit_or(C
.proto_http
, C
.proto_rtmp
)
34 local U
= require
'quvi/util'
35 r
.handles
= U
.handles(self
.page_url
,
41 -- Query available formats.
42 function query_formats(self
)
43 local page
= quvi
.fetch(self
.page_url
)
44 local formats
= IMDB
.iter_formats(page
)
47 for _
,v
in pairs(formats
) do
48 table.insert(t
, IMDB
.to_s(v
))
52 self
.formats
= table.concat(t
, "|")
61 self
.id
= self
.page_url
:match('/video/%w+/(vi%d-)/')
63 local page
= quvi
.fetch(self
.page_url
)
64 self
.title
= page
:match('<title>(.-) %- IMDb</title>')
67 -- Format codes (for most videos):
72 local formats
= IMDB
.iter_formats(page
)
73 local U
= require
'quvi/util'
74 local format = U
.choose_format(self
, formats
,
78 or error("unable to choose format")
79 if not format.path
then
80 error("no match: media url")
83 local url
= 'http://www.imdb.com' .. format.path
84 local iframe
= quvi
.fetch(url
, {fetch_type
= 'config'})
85 local file
= iframe
:match('so%.addVariable%("file", "(.-)"%);')
86 file
= U
.unescape(file
)
88 if file
:match('^http.-') then
91 local path
= iframe
:match('so%.addVariable%("id", "(.-)"%);')
92 path
= U
.unescape(path
)
93 self
.url
= {file
.. path
}
96 -- Optional: we can live without these
98 local thumb
= iframe
:match('so%.addVariable%("image", "(.-)"%);')
99 self
.thumbnail_url
= thumb
or ''
108 function IMDB
.iter_formats(page
)
109 local p
= "case '(.-)' :.-url = '(.-)';"
111 for c
,u
in page
:gmatch(p
) do
112 table.insert(t
, {path
=u
, container
=c
})
116 -- First item is ad, so remove it
122 function IMDB
.choose_best(t
) -- Expect the last to be the 'best'
126 function IMDB
.choose_default(t
) -- Expect the second to be the 'default'
130 function IMDB
.to_s(t
)
134 -- vim: set ts=4 sw=4 tw=72 expandtab: