Move website/101greatgoals.lua to media/
[libquvi-scripts.git] / share / media / 101greatgoals.lua
blob4661652c66d05fbd468ca0a675fff71fc611a3f8
2 -- libquvi-scripts
3 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 -- Copyright (C) 2012 quvi project
5 --
6 -- This file is part of libquvi-scripts <http://quvi.sourceforge.net/>.
7 --
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
21 -- 02110-1301 USA
24 -- Hundred and One Great Goals (aggregator)
25 local HaOgg = {} -- Utility functions specific to this script
27 -- Identify the script.
28 function ident(self)
29 package.path = self.script_dir .. '/?.lua'
30 local C = require 'quvi/const'
31 local r = {}
32 r.domain = "101greatgoals%.com"
33 r.formats = "default"
34 r.categories = C.proto_http
35 local U = require 'quvi/util'
36 r.handles = U.handles(self.page_url, {r.domain}, {"/gvideos/.+/$"})
37 return r
38 end
40 -- Query available formats.
41 function query_formats(self)
42 self.formats = 'default'
43 return HaOgg.chk_ext_content(self)
44 end
46 -- Parse media URL.
47 function parse(self)
48 self.host_id = "101greatgoals"
49 return HaOgg.chk_ext_content(self)
50 end
53 -- Utility functions
56 function HaOgg.chk_self_hosted(p)
58 -- Previously referred to as the "self-hosted" media, although according
59 -- to the old notes, these were typically hosted by YouTube.
60 -- http://is.gd/EKKPy2
62 -- 2013-05-05: The contents of the URL no longer seems to contain the
63 -- "file" value, see chk_embedded for notes; keep this
64 -- function around for now
66 local d = p:match('%.setup%((.-)%)')
67 if d then
68 local s = d:match('"file":"(.-)"') or error('no match: file')
69 if #s ==0 then
70 error('empty media URL ("file")')
71 end
72 local U = require 'quvi/util'
73 return (U.slash_unescape(U.unescape(s)))
74 end
75 end
77 function HaOgg.chk_embedded(p)
79 -- 2013-05-05: Most of the content appears to be embedded from elsewhere
81 -- Instead of trying to check for each, parse the likely embedded source
82 -- and pass it back to libquvi to find a media script that accepts the
83 -- parsed (embedded) media URL.
85 -- NOTE: This means that those media scripts must unwrangle the embedded
86 -- media URLs passed from this script
88 local s = p:match('class="post%-type%-gvideos">(.-)</')
89 or p:match('id="jwplayer%-1">(.-)</>')
90 or error('unable to determine embedded source')
91 return s:match('value="(.-)"') or s:match('src="(.-)"')
92 end
94 function HaOgg.chk_ext_content(self)
95 local p = quvi.fetch(self.page_url)
97 self.redirect_url = HaOgg.chk_self_hosted(p) or HaOgg.chk_embedded(p)
98 or error('unable to determine media source')
100 return self
103 -- vim: set ts=4 sw=4 tw=72 expandtab: