3 -- Copyright (C) 2010 Toni Gundogdu <legatvs@gmail.com>
5 -- This file is part of quvi <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
28 -- Check whether the domain is handled
29 function is_handled (page_url
)
30 if page_url
== nil then
33 for k
,domain
in pairs(domains
) do
34 if page_url
:find(domain
) ~= nil then
41 -- Identify the script.
43 package
.path
= self
.script_dir
.. '/?.lua'
44 local C
= require
'quvi/const'
46 r
.domain
= "dailymotion."
47 r
.formats
= "default|best|hq|hd"
48 r
.categories
= C
.proto_http
49 r
.handles
= is_handled (self
.page_url
)
55 self
.host_id
= "dailymotion"
56 self
.page_url
= normalize (self
.page_url
)
58 local _
,_
,s
= self
.page_url
:find ('/family_filter%?urlback=(.+)')
60 self
.page_url
= 'http://dailymotion.com' .. quvi
.unescape (s
)
61 -- We set family_filter arbitrary cookie below.
64 local opts
= { arbitrary_cookie
= 'family_filter=off' }
65 local page
= quvi
.fetch(self
.page_url
, opts
)
67 if (page
:find('SWFObject("http:")') ~= nil) then
68 error ("Looks like a partner video. Refusing to continue.")
71 local _
,_
,s
= page
:find('title="(.-)"')
72 self
.title
= s
or error ("no match: video title")
74 local _
,_
,s
= page
:find("video/(.-)_")
75 self
.id
= s
or error ("no match: video id")
77 -- Some videos have only one link available.
78 local _
,_
,s
= page
:find ('"video", "(.-)"')
82 parse_video_url (self
)
85 if (self
.url
== nil) then
86 error ('no match: video url')
92 function normalize (url
)
93 if (url
:find ("/swf/")) then
94 url
= url
:gsub ("/video/", "/")
95 url
= url
:gsub ("/swf/", "/video/")
100 function parse_video_url (self
)
103 local req_fmt
= self
.requested_format
105 if (req_fmt
== "default") then
106 req_fmt
= "sd" -- Dailymotion defaults to this.
109 for id
,path
in page
:gfind("%%22(%w%w)URL%%22%%3A%%22(.-)%%22") do
110 path
= path
:gsub("%%5C","")
111 path
= quvi
.unescape(path
)
113 if (req_fmt
== id
) then
119 if (best
~= nil and self
.requested_format
== "best") then
126 -- vim: set ts=4 sw=4 tw=72 expandtab: