media/tagtele.lua: Relicense under AGPLv3+
[libquvi-scripts.git] / share / media / myspass.lua
blob6062a13870dcff2cd1789c8beb6ee0f8efbd2aef
1 -- libquvi-scripts
2 -- Copyright (C) 2013 Toni Gundogdu <legatvs@gmail.com>
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 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 local MySpass = {} -- Utility functions unique to this script
24 -- Identify the media script.
25 function ident(qargs)
26 return {
27 can_parse_url = MySpass.can_parse_url(qargs),
28 domains = table.concat({'myspass.de'}, ',')
30 end
32 -- Parse the media properties.
33 function parse(qargs)
35 -- Make mandatory: the media ID is needed to fetch the data XML.
36 qargs.id = qargs.input_url:match("(%d+)/?$") or error("no match: media ID")
38 local t = {
39 'http://www.myspass.de/myspass/includes/apps/video',
40 '/getvideometadataxml.php?id=', qargs.id
43 local c = quvi.http.fetch(table.concat(t)).data
44 local P = require 'lxp.lom'
46 local L = require 'quvi/lxph'
47 local x = P.parse(c)
49 qargs.thumb_url = L.find_first_tag(x, 'imagePreview')[1]
51 qargs.duration_ms = MySpass.to_duration_ms(L, x)
53 qargs.streams = MySpass.iter_streams(L, x)
55 qargs.title = MySpass.to_title(L, x)
57 return qargs
58 end
61 -- Utility functions
64 function MySpass.can_parse_url(qargs)
65 local U = require 'socket.url'
66 local t = U.parse(qargs.input_url)
67 if t and t.scheme and t.scheme:lower():match('^http$')
68 and t.host and t.host:lower():match('myspass%.de$')
69 -- Expect all URLs ending with digits to be videos.
70 and t.path and t.path:lower():match('^/myspass/.-/%d+/?$')
71 then
72 return true
73 else
74 return false
75 end
76 end
78 function MySpass.iter_streams(L, x)
79 local u = L.find_first_tag(x, 'url_flv')[1]
80 local S = require 'quvi/stream'
81 return {S.stream_new(u)}
82 end
84 function MySpass.to_duration_ms(L, x)
85 local m,s = L.find_first_tag(x, 'duration')[1]:match('(%d+)%:(%d+)')
86 m = tonumber(((m or ''):gsub('%a',''))) or 0
87 m = tonumber(((s or ''):gsub('%a',''))) or 0
88 return (m*60000) + (s*1000)
89 end
91 function MySpass.to_title(L, x)
92 local t = {
93 L.find_first_tag(x, 'format')[1],
94 string.format('s%02de%02d -', L.find_first_tag(x, 'season')[1],
95 L.find_first_tag(x, 'episode')[1]),
96 L.find_first_tag(x, 'title')[1]
98 return table.concat(t, ' ')
99 end
101 -- vim: set ts=2 sw=2 tw=72 expandtab: