FIX: media/spiegel.lua: title pattern (BACKPORTpt4)
[libquvi-scripts.git] / share / media / 101greatgoals.lua
blobb8f7fd5dab0e6f252aa54aad13d86e2a772d880b
1 -- libquvi-scripts
2 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
3 -- Copyright (C) 2012 quvi project
4 --
5 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
6 --
7 -- This program is free software: you can redistribute it and/or
8 -- modify it under the terms of the GNU Affero General Public
9 -- License as published by the Free Software Foundation, either
10 -- version 3 of the License, or (at your option) any later version.
12 -- This program 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
15 -- GNU Affero General Public License for more details.
17 -- You should have received a copy of the GNU Affero General
18 -- Public License along with this program. If not, see
19 -- <http://www.gnu.org/licenses/>.
22 -- Hundred and One Great Goals (aggregator)
23 local HaOgg = {} -- Utility functions specific to this script
25 -- Identify the media script.
26 function ident(qargs)
27 return {
28 can_parse_url = HaOgg.can_parse_url(qargs),
29 domains = table.concat({'101greatgoals.com'}, ',')
31 end
33 -- Parse the media properties.
34 function parse(qargs)
35 local p = quvi.http.fetch(qargs.input_url).data
37 qargs.goto_url = HaOgg.chk_self_hosted(p) or HaOgg.chk_embedded(p)
38 or error('unable to determine media source')
40 return qargs
41 end
44 -- Utility functions
47 function HaOgg.can_parse_url(qargs)
48 local U = require 'socket.url'
49 local t = U.parse(qargs.input_url)
50 if t and t.scheme and t.scheme:lower():match('^http$')
51 and t.host and t.host:lower():match('101greatgoals%.com$')
52 and t.path and t.path:lower():match('^/gvideos/.+/$')
53 then
54 return true
55 else
56 return false
57 end
58 end
60 function HaOgg.chk_self_hosted(p)
62 -- Previously referred to as the "self-hosted" media, although according
63 -- to the old notes, these were typically hosted by YouTube.
64 -- http://is.gd/EKKPy2
66 -- 2013-05-05: The contents of the URL no longer seems to contain the
67 -- "file" value, see chk_embedded for notes; keep this
68 -- function around for now
70 local d = p:match('%.setup%((.-)%)')
71 if d then
72 local s = d:match('"file":"(.-)"') or error('no match: file')
73 if #s ==0 then
74 error('empty media URL ("file")')
75 end
76 local U = require 'quvi/util'
77 return (U.slash_unescape(U.unescape(s)))
78 end
79 end
81 function HaOgg.chk_embedded(p)
83 -- 2013-05-05: Most of the content appears to be embedded from elsewhere
85 -- Instead of trying to check for each, parse the likely embedded source
86 -- and pass it back to libquvi to find a media script that accepts the
87 -- parsed (embedded) media URL.
89 -- NOTE: This means that those media scripts must unwrangle the embedded
90 -- media URLs passed from this script
92 local s = p:match('class="post%-type%-gvideos">(.-)</')
93 or p:match('id="jwplayer%-1">(.-)</>')
94 or error('unable to determine embedded source')
95 return s:match('value="(.-)"') or s:match('src="(.-)"')
96 end
98 -- vim: set ts=2 sw=2 tw=72 expandtab: