ard.lua: Cleanup Ard.iter_formats
[libquvi-scripts.git] / share / lua / website / myspass.lua
blob436b83162207e0bfcccacb931781d1edf0aa2046
2 -- libquvi-scripts
3 -- Copyright (C) 2012 Guido Leisker <guido@guido-leisker.de>
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
22 -- About
23 -- Each video url ends with an id composed of digits.
24 -- This id leads us to a metadata xml file (see function
25 -- MySpass.getMetadataValue) containing all necessary information
26 -- including download link.
28 local MySpass = {} -- Utility functions unique to this script
30 -- Identify the script.
31 function ident(self)
32 package.path = self.script_dir .. '/?.lua'
33 local C = require 'quvi/const'
34 local r = {}
35 r.domain = "myspass%.de"
36 r.formats = "default"
37 r.categories = C.proto_http
38 local U = require 'quvi/util'
39 -- expect all urls ending with digits to be videos
40 r.handles = U.handles(self.page_url, {r.domain}, {"/myspass/.-/%d+/?$"})
41 return r
42 end
44 -- Query available formats.
45 function query_formats(self)
46 self.formats = 'default'
47 return self
48 end
50 -- Parse media URL.
51 function parse(self)
52 self.host_id = "myspass"
54 self.id = self.page_url:match("(%d+)/?$")
55 or error("no match: media ID")
57 local format = MySpass.getMetadataValue(self, 'format')
58 local title = MySpass.getMetadataValue(self, 'title')
59 local season = MySpass.getMetadataValue(self, 'season')
60 local episode = MySpass.getMetadataValue(self, 'episode')
61 self.thumbnail_url = MySpass.getMetadataValue(self, 'imagePreview') or ''
63 self.title = string.format("%s %03d %03d %s", format, season,
64 episode, title)
66 self.url = {MySpass.getMetadataValue(self, 'url_flv')}
68 return self
69 end
72 -- Utility functions
75 function MySpass.getMetadataValue(self, key)
76 if self.metadata == nil then
77 self.metadata = quvi.fetch(
78 'http://www.myspass.de/myspass/'
79 .. 'includes/apps/video/getvideometadataxml.php?id='
80 .. self.id ) or error("cannot fetch meta data xml file")
81 end
82 local p = string.format("<%s>(.-)</%s>", key, key)
83 local temp = self.metadata:match(p) or error("meta data: no match: " .. key)
84 local value = temp:match('<!%[CDATA%[(.+)]]>') or temp
85 return value
86 end
88 -- vim: set ts=2 sw=2 tw=72 expandtab: