File: grl-radiofrance.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 (122 lines) | stat: -rw-r--r-- 3,708 bytes parent folder | download | duplicates (5)
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
--[[
 * Copyright (C) 2014 Bastien Nocera
 *
 * Contact: Bastien Nocera <hadess@hadess.net>
 *
 * 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
 *
--]]

local stations = { 'franceinter', 'franceinfo', 'franceculture', 'francemusique', 'fipradio', 'lemouv' }

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

source = {
  id = "grl-radiofrance-lua",
  name = "Radio France",
  description = "A source for browsing Radio France radio stations",
  supported_keys = { "id", "thumbnail", "title", "url", "mime-type" },
  icon = 'resource:///org/gnome/grilo/plugins/radiofrance/radiofrance.png',
  supported_media = 'audio',
  tags = { 'radio', 'country:fr', 'net:internet', 'net:plaintext' }
}

------------------
-- Source utils --
------------------

function grl_source_browse(media_id)
  if grl.get_options("skip") > 0 then
    grl.callback()
  else
    local urls = {}
    for index, item in pairs(stations) do
      local url = 'http://www.' .. item .. '.fr/player'
      table.insert(urls, url)
    end
    grl.fetch(urls, radiofrance_now_fetch_cb)
  end
end

------------------------
-- Callback functions --
------------------------

-- return all the media found
function radiofrance_now_fetch_cb(results)
  for index, result in pairs(results) do
    local media = create_media(stations[index], result)
    grl.callback(media, -1)
  end

  grl.callback()
end

-------------
-- Helpers --
-------------

function get_thumbnail(id)
  local images = {}
  images['franceinter'] = 'http://www.franceinter.fr/sites/all/themes/franceinter/logo.png'
  images['franceinfo'] = 'http://www.franceinfo.fr/sites/all/themes/custom/france_info/logo.png'
  images['franceculture'] = 'http://www.franceculture.fr/sites/all/themes/franceculture/images/logo.png'
  images['francemusique'] = 'http://www.francemusique.fr/sites/all/themes/custom/france_musique/logo.png'
  images['fipradio'] = 'http://www.fipradio.fr/sites/all/themes/custom/fip/logo.png'
  images['lemouv'] = 'http://www.lemouv.fr/sites/all/themes/mouv/images/logo_119x119.png'

  return images[id]
end

function get_title(id)
  local names = {}
  names['franceinter'] = 'France Inter'
  names['franceinfo'] = 'France Info'
  names['franceculture'] = 'France Culture'
  names['francemusique'] = 'France Musique'
  names['fipradio'] = 'Fip Radio'
  names['lemouv'] = "Le Mouv'"

  return names[id]
end

function create_media(id, result)
  local media = {}

  media.type = "audio"
  media.mime_type = "audio/mpeg"
  media.id = id
  if media.id == 'fipradio' then
    media.id = 'fip'
  end

  media.url = result:match("urlLive:'(http.-%mp3)")
  if not media.url then
    media.url = result:match('player" href="(http.-%.mp3)')
  end
  if not media.url then
    media.url = result:match('data%-url%-live="(http.-%.mp3)')
  end

  media.title = get_title(id)
  media.thumbnail = get_thumbnail(id)

  -- FIXME Add metadata about the currently playing tracks
  -- Available in 'http://www.' .. item .. '.fr/api/now&full=true'
  return media
end