3 -- Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
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 ResolveExceptions
= {} -- Utility functions unique to this script
25 function resolve_redirections(qargs
)
26 -- Let libcURL resolve the URL redirections for us.
27 local resolved
, dst
= quvi
.resolve(qargs
.input_url
)
28 if not resolved
then return qargs
.input_url
end
30 -- Apply any exception rules to the destination URL.
31 return ResolveExceptions
.YouTube(qargs
, dst
)
38 function ResolveExceptions
.YouTube(qargs
, dst
)
39 -- [UPDATE] 2012-11-18: g00gle servers seem not to strip the #t anymore
42 -- Preserve the t= parameter (if any). The g00gle servers
43 -- strip them from the destination URL after redirecting.
44 -- e.g. http://www.youtube.com/watch?v=LWxTGJ3TK1U#t=2m22s
45 -- -> http://www.youtube.com/watch?v=LWxTGJ3TK1U
46 return dst .. (qargs.input_url:match('(#t=%w+)') or '')
50 -- vim: set ts=2 sw=2 tw=72 expandtab: