FIX: website/funnyordie.lua: Media stream pattern (PORTpt9)
[libquvi-scripts.git] / share / lua / website / myspass.lua
blob749308c53af30ff246a57d9cb082e6a0d3bdfe2f
2 -- libquvi-scripts
3 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
4 -- Copyright (C) 2012 Guido Leisker <guido@guido-leisker.de>
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
23 -- About
24 -- Each video url ends with an id composed of digits.
25 -- This id leads us to a metadata xml file (see function
26 -- MySpass.getMetadataValue) containing all necessary information
27 -- including download link.
29 local MySpass = {} -- Utility functions unique to this script
31 -- Identify the script.
32 function ident(self)
33 package.path = self.script_dir .. '/?.lua'
34 local C = require 'quvi/const'
35 local r = {}
36 r.domain = "myspass%.de"
37 r.formats = "default"
38 r.categories = C.proto_http
39 local U = require 'quvi/util'
40 -- expect all urls ending with digits to be videos
41 r.handles = U.handles(self.page_url, {r.domain},{"/myspass/.-/%d+/?$"})
42 return r
43 end
45 -- Query available formats.
46 function query_formats(self)
47 self.formats = 'default'
48 return self
49 end
51 -- Parse media URL.
52 function parse(self)
53 self.host_id = "myspass"
55 self.id = self.page_url:match("(%d+)/?$") or error("no match: media ID")
57 local u = {
58 'http://www.myspass.de/myspass/',
59 'includes/apps/video/getvideometadataxml.php?id=',
60 self.id
62 local m = quvi.fetch(table.concat(u,''))
64 local format = MySpass.getMetadataValue(m, 'format')
65 MySpass.chk_expired(format)
67 local season = MySpass.getMetadataValue(m, 'season')
68 local episode = MySpass.getMetadataValue(m, 'episode')
69 local title = MySpass.getMetadataValue(m, 'title')
71 self.title = string.format("%s %03d %03d %s",
72 format,
73 tonumber(season),
74 tonumber(episode),
75 title)
77 self.thumbnail_url = MySpass.getMetadataValue(m, 'imagePreview') or ''
78 self.url = {MySpass.getMetadataValue(m, 'url_flv')}
80 return self
81 end
84 -- Utility functions
87 function MySpass.getMetadataValue(m, k)
88 local p = string.format("<%s>(.-)</%s>", k, k)
89 local s = m:match(p) or error(string.format('no match: %s', k))
90 return s:match('<!%[CDATA%[(.+)]]>') or ''
91 end
93 function MySpass.chk_expired(s)
94 if #s ==0 then
95 error('no match: metadata: "format": video no longer available?')
96 end
97 end
99 -- vim: set ts=4 sw=4 tw=72 expandtab: