FIX: resolve_redirections.lua: Do not append #t
[libquvi-scripts.git] / share / util / resolve_redirections.lua
blobf6b3edfeb4825bf81656464a8bc906e50ebd76f5
2 -- libquvi-scripts
3 -- Copyright (C) 2012 Toni Gundogdu <legatvs@gmail.com>
4 --
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 --
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
20 -- 02110-1301 USA
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)
32 end
35 -- Utility functions
38 function ResolveExceptions.YouTube(qargs, dst)
39 -- [UPDATE] 2012-11-18: g00gle servers seem not to strip the #t anymore
40 return dst
41 --[[
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 '')
47 ]]--
48 end
50 -- vim: set ts=2 sw=2 tw=72 expandtab: