3 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 -- Copyright (C) 2011 Lionel Elie Mamane <lionel@mamane.lu>
6 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
8 -- This library is free software; you can redistribute it and/or
9 -- modify it under the terms of the GNU Lesser General Public
10 -- License as published by the Free Software Foundation; either
11 -- version 2.1 of the License, or (at your option) any later version.
13 -- This library is distributed in the hope that it will be useful,
14 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
15 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 -- Lesser General Public License for more details.
18 -- You should have received a copy of the GNU Lesser General Public
19 -- License along with this library; if not, write to the Free Software
20 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 local Metacafe
= {} -- Utility functions unique to this script.
26 -- Identify the script.
28 package
.path
= self
.script_dir
.. '/?.lua'
29 local C
= require
'quvi/const'
31 r
.domain
= "metacafe%.com"
33 r
.categories
= C
.proto_http
34 local U
= require
'quvi/util'
35 r
.handles
= U
.handles(self
.page_url
, {r
.domain
},
36 {"/watch/%d+/", "/watch/yt-[^/]+/"})
40 -- Query available formats.
41 function query_formats(self
)
42 if not Metacafe
.redirectp(self
) then
43 self
.formats
= 'default'
50 self
.host_id
= "metacafe"
52 if Metacafe
.redirectp(self
) then
56 local U
= require
'quvi/util'
57 local p
= Metacafe
.fetch_page(self
, U
)
59 local v
= p
:match('name="flashvars" value="(.-)"')
60 or error('no match: flashvars')
62 v
= U
.slash_unescape(U
.unescape(v
))
64 self
.thumbnail_url
= p
:match('rel="image_src" href="(.-)"') or ''
66 self
.title
= v
:match('title=(.-)&') or error('no match: media title')
68 self
.id
= v
:match('itemID=(%d+)') or error('no match: media ID')
70 local u
= v
:match('"mediaURL":"(.-)"')
71 or error('no match: media stream URL')
73 local k
= v
:match('"key":"__gda__","value":"(.-)"')
74 or error('no match: key')
76 self
.url
= {string.format("%s?__gda__=%s", u
, k
)}
85 function Metacafe
.redirectp(self
)
86 local s
= self
.page_url
:match('/watch/yt%-([^/]+)/')
87 if s
then -- Hand over to youtube.lua
88 self
.redirect_url
= 'http://youtube.com/watch?v=' .. s
94 function Metacafe
.fetch_page(self
, U
)
95 self
.page_url
= Metacafe
.normalize(self
.page_url
)
97 return quvi
.fetch(self
.page_url
)
100 function Metacafe
.normalize(page_url
) -- "Normalize" embedded URLs
104 -- vim: set ts=4 sw=4 tw=72 expandtab: