FIX: website/tcmag.lua: Media stream URL pattern
[libquvi-scripts.git] / share / lua / website / tcmag.lua
blob1fb0aa03bb5650ffaa737acccc5c0253a5f3f198
2 -- libquvi-scripts
3 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 -- Copyright (C) 2011 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 local TCMag = {} -- Utility functions specific to this script
26 -- Identify the script.
27 function ident(self)
28 package.path = self.script_dir .. '/?.lua'
29 local C = require 'quvi/const'
30 local r = {}
31 r.domain = "tcmag%.com"
32 r.formats = "default"
33 r.categories = C.proto_http
34 local U = require 'quvi/util'
35 r.handles = U.handles(self.page_url, {r.domain}, {"/magazine/.+"})
36 return r
37 end
39 -- Query available formats.
40 function query_formats(self)
41 self.formats = 'default'
42 return TCMag.check_external_content(self)
43 end
45 -- Parse media URL.
46 function parse(self)
47 self.host_id = "tcmag"
48 return TCMag.check_external_content(self)
49 end
52 -- Utility functions
55 function TCMag.check_external_content(self)
56 local p = quvi.fetch(self.page_url)
58 self.url = {p:match("file: '(.-)'")
59 or error("no match: media stream URL")}
61 if self.url[1]:match('%.%w+$') then
62 -- Self-hosted content.
63 self.title = p:match('<h1>(.-)</h1>')
64 or error ("no match: media title")
65 self.id = self.url[1]:match("/%d+/%d+/(.-)/sizes/")
66 or error ("no match: media id")
67 self.thumbnail_url = p:match('"og:image" content="(.-)"') or ''
68 else -- Affiliate content.
69 self.redirect_url = self.url[1]
70 return self
71 end
73 return self
74 end
76 -- vim: set ts=4 sw=4 tw=72 expandtab: