File: test-source-grl-media.lua

package info (click to toggle)
grilo-plugins 0.3.3-1%2Bdeb9u1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 10,100 kB
  • sloc: ansic: 43,393; sh: 4,094; makefile: 1,178; xml: 654; python: 423
file content (70 lines) | stat: -rw-r--r-- 2,002 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
--[[
 * Copyright (C) 2015 Victor Toso.
 *
 * Contact: Victor Toso <me@victortoso.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
--]]

---------------------------
-- Source initialization --
---------------------------

source = {
  id = "test-source-grl-media",
  name = "Fake Source",
  description = "a source to test GrlMedia",
  supported_keys = { "title" },
  supported_media = "all",
  resolve_keys = {
    ["type"] = "all",
    required = { "url" } ,
  },
  tags = { 'test', 'net:plaintext' },
}

---------------------------------
-- Handlers of Grilo functions --
---------------------------------

function grl_source_resolve()
  -- This source expects an url which will be fetched and converted
  -- to a GrlMedia with grl.lua.json.string_to_table().
  local req = grl.get_media_keys()
  if not req or not req.url or #req.url == 0 then
    grl.warning("resolve was called without metadata-key url")
    grl.callback()
    return
  end
  grl.fetch(req.url, fetch_url_cb)
end

function fetch_url_cb(feed)
  if not feed or #feed == 0 then
    grl.warning("failed to load json")
    grl.callback()
    return
  end

  local media = grl.lua.json.string_to_table(feed)
  if not media then
    grl.warning ("fail to make media from json")
    grl.callback()
    return
  end
  grl.callback(media, 0)
end