summaryrefslogtreecommitdiff
path: root/.local/share/libquvi-scripts/media/radiode.lua
blob: b56f65917d9a265a46dc89417f1ae4d1af0dd419 (plain)
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
-- libquvi-scripts

local Radio = {}

-- Identify the script.
function ident(qargs)
  return {
    domains = table.concat({'radio.de'}, ','),
    can_parse_url = Radio.can_parse_url(qargs)
  }
end

-- Parse media URL.
function parse(qargs)
  local S = require 'quvi/stream'
  local c = quvi.http.fetch(qargs.input_url).data

  if c:match('<error>') then
    local s = c:match('<message>(.-)[\n<]')
    error((not s) and "no match: error message" or s)
  end

  qargs.id = qargs.input_url:match('http://(.-)%.radio%.de')
  qargs.title = c:match('property="og:title" content="(.-)"')
  qargs.thumb_url = c:match('property="og:image" content="(.-)"')

  local url = c:match('_getPlaylist.*"stream":"(.-)"')
  qargs.streams = { S.stream_new(url) }

  return qargs
end

function Radio.can_parse_url(qargs)
  local U = require 'socket.url'
  local t = U.parse(qargs.input_url)

  return t and t.scheme and t.scheme:lower():match('^http$')
           and t.host and t.host:lower():match('.-%.radio%.de$')
           and t.host ~= "www.radio.de" and true or false
end

-- vim: set ts=2 sw=2 tw=72 expandtab: