Switch to unified view

a/doc/upmpdcli-manual.txt b/doc/upmpdcli-manual.txt
...
...
267
compensates the small additional CPU load).
267
compensates the small additional CPU load).
268
268
269
There are situations where the linear formats are needed though, and where
269
There are situations where the linear formats are needed though, and where
270
it may be necessary to use the right MPD and plugins versions.
270
it may be necessary to use the right MPD and plugins versions.
271
271
272
[[radio-definitions]]
272
[[radio-stations]]
273
=== Radio station definitions
273
=== Radio stations
274
274
275
Upmpdcli versions after 0.13 implement an OpenHome Radio service
275
Upmpdcli implements an OpenHome Radio service which allows selecting and
276
which allows selecting and listening to internet radio stations. 
276
listening to internet radio stations when using an OpenHome-compatible
277
Control Point (e.g. Kazoo, Lumin, Bubble UPnP, etc.).
277
278
278
This facility uses Python 2.x, which must be available on the system for
279
This facility uses Python 2.x, which must be available on the system for
279
the radio links to work.
280
the radio links to work.
281
282
Radio channels can be accessed by using the Control Point application to
283
select the _Radio_ OpenHome source.
280
284
281
Radio stations can be defined in the configuration (at the end because of
285
Radio stations can be defined in the configuration (at the end because of
282
the use of section indicators), or in in a separate file by setting the
286
the use of section indicators), or in in a separate file by setting the
283
<<ohproductroom,+radiolist+>> parameter in the main configuration.
287
<<ohproductroom,+radiolist+>> parameter in the main configuration.
284
288
285
Radio channels can be accessed by selecting the _Radio_ Source from an
289
An example of a simple radio station definition follows. The only mandatory
286
OpenHome Control Point.
290
value is the +url+ one, which should point to the actual audio stream or to
287
291
the station playlist link which will redirect to it (more detail in the
288
Example entry:
292
<<RADIO-SCRIPTS,radio scripts section>>. +artUrl+ points to a
293
static logo image for the station.
289
294
290
----
295
----
291
[radio Radio Teddy]
296
[radio Radio Eins]
292
url = http://opml.radiotime.com/Tune.ashx?id=s80044
297
url = http://opml.radiotime.com/Tune.ashx?id=s25111
293
artUrl = http://cdn-radiotime-logos.tunein.com/s80044q.png
298
artUrl = http://cdn-radiotime-logos.tunein.com/s25111q.png
294
artScript = /path/to/some/script
295
metaScript = /path/to/some/other/script
296
----
299
----
297
300
298
The section name must begin with +radio+, the rest will be displayed as the
301
Radio definitions may also include paths to scripts to be executed for
299
station name. The section has several possible entries. Only +url+ is
302
retrieving the metadata and album art for the currently playing song. See
300
mandatory, it points to the playlist or stream.
303
the <<RADIO-SCRIPTS,radio scripts section>> for more detail.
301
302
If set, +artUrl+ is a link to a static icon for the radio (displayed as
303
album art).
304
305
If set, +artScript+ is the path to an executable script which can retrieve
306
the image URL for the currently playing title.
307
308
Some radios (e.g.  link:https://www.radioparadise.com/rp_2.php?#[Radio
309
Paradise]) publish the album art for the currently playing title. The
310
details vary. The +artScript+ parameter, if set, should point to an
311
executable script which prints this dynamic art Uri to stdout. The image
312
will supercede the radio logo, to be displayed by control points. Beware
313
that the path to the script must be accessible by the _upmpdcli_ user,
314
which may not be the case for your home. +/usr/local/bin+ is your
315
friend. As a very rough example here follows a command which would retrieve
316
the Radio Paradise URI (as long as they don't change their format, a proper
317
approach would use an XML parser of course):
318
319
    curl --max-time 5 -s http://radioparadise.com/xml/now.xml | \
320
         grep '<coverart>' | sed -e 's/<coverart>//' -e 's!</coverart>!!'
321
322
Also note that upmpdcli does not set a timeout for the +artScript+
323
execution. A reasonable value should be used inside the script, to avoid
324
freezing upmpdcli forever.
325
326
If set, +metaScript+ is the path to an executable script which can retrieve
327
the metadata (possibly including art Url) for the currently playing title.
328
329
The script should output the metadata in JSON format. Example output
330
(the newlines and blank space are just here for readability):
331
332
333
{
334
    "title":"The title of the current track",
335
    "artist":"The artist playing",
336
    "artUrl":"https://www.somesite.com/path/to/image.jpg",
337
    "reload":103
338
}
339
340
341
The +reload+ value gives the number of seconds after which the script
342
should be re-executed (the clever radio sets this to the remaining song
343
time). By default, the script is executed every 10 S.
344
345
Complete exemple with metadata script:
346
347
348
[radio FIP (Paris)]
349
url = http://direct.fipradio.fr/live/fip-midfi.mp3
350
artUrl = http://www.fipradio.fr/sites/default/files/fip-quadri-filet.png
351
metaScript = /usr/local/bin/fip-paris-meta.rb
352
353
354
And the script (this one in Ruby, thanks to
355
link:https://github.com/distler[Jacques Distler]): 
356
357
358
#!/usr/bin/ruby
359
require 'net/http'
360
require 'json'
361
362
uri = URI('http://www.fipradio.fr/livemeta/7')
363
response = Net::HTTP.get(uri)
364
songs = JSON.parse(response)['steps'].values
365
now = Time.now
366
songs.each do |song|
367
  song_end = Time.at(song['end'])
368
  if (song['embedType'] == 'song' && song_end >= now && Time.at(song['start']) <= now)
369
    title = song['title'] ? song['title'] : ''
370
    artist = song['performers'] ? song['performers'] : song['authors']
371
    metadata = {'title' => title.split.collect{|s| s.capitalize}.join(' '),
372
               'artist' => artist.split.collect{|s| s.capitalize}.join(' '),
373
               'artUrl' => song['visual'],
374
               'reload' => (song_end - now + 1).to_i}
375
    puts JSON.generate(metadata)
376
    break
377
  end
378
end
379
380
381
304
382
[[UPMPDCLI-SONGCAST]]
305
[[UPMPDCLI-SONGCAST]]
383
== Upmpdcli and Songcast
306
== Upmpdcli and Songcast
384
307
385
Upmpdcli implements the Receiver UPnP service, and uses an auxiliary
308
Upmpdcli implements the Receiver UPnP service, and uses an auxiliary
...
...
1201
The +Analog-Input+ sample script has provisions for reading the device name
1124
The +Analog-Input+ sample script has provisions for reading the device name
1202
and setup/teardown instructions from external files, so that it does not
1125
and setup/teardown instructions from external files, so that it does not
1203
need to be modified. This is only relevant for the sample, please have a
1126
need to be modified. This is only relevant for the sample, please have a
1204
look at the comments for details.
1127
look at the comments for details.
1205
1128
1129
[[RADIO-SCRIPTS]]
1130
== Annex: the radio scripts
1131
1132
=== The radio URL script
1133
1134
The +url+ field inside the radio definition can be a direct audio link or a
1135
link to the radio station playlist. This link will be interpreted by the
1136
'fetchstream.py' ('rdpltostream' directory inside the source tree, or see
1137
'/usr/share/upmpdcli/rdpl2stream'). The Python code knows about the various
1138
playlist formats used by the stations.
1139
1140
=== The dynamic album art script
1141
1142
If set, +artScript+ is the path to an executable script which can retrieve
1143
the image URL for the currently playing title. It can also be a simple
1144
script name if this is located in the PATH or in the 'radio_scripts'
1145
directory inside the upmpdcli directory (typically '/usr/share/upmpdcli').
1146
1147
Some radios (e.g.  link:https://www.radioparadise.com/rp_2.php?#[Radio
1148
Paradise]) publish the album art for the currently playing title. The
1149
details vary. The +artScript+ parameter, if set, should point to an
1150
executable script which prints this dynamic art Uri to stdout. The image
1151
will supercede the radio logo, to be displayed by control points. Beware
1152
that the path to the script must be accessible by the _upmpdcli_ user,
1153
which may not be the case for your home. +/usr/local/bin+ is your
1154
friend. The Upmpdcli installation has a very small set of scripts inside
1155
the '/usr/share/upmpdcli/radio_scripts' directory. This includes a very
1156
rough example for retrieving the Radio Paradise art URI,
1157
'radio-paradise-get-art.sh' 
1158
1159
The art script is executed each time the stream metadata changes (the data
1160
is obtained by mpd from Icy metadata in the stream).
1161
1162
Upmpdcli does not set a timeout for the +artScript+ execution. A reasonable
1163
value should be used inside the script, to avoid freezing upmpdcli forever.
1164
1165
There is no reason to have an +artScript+ if +metaScript+ exists for the
1166
radio. +metaScript+ can also return the image URL.
1167
1168
=== The dynamic metadata script
1169
1170
If set, +metaScript+ is the path to an executable script which can retrieve
1171
the metadata (possibly including art Url) for the currently playing
1172
title. It can also be a simple script name if this is located in the PATH
1173
or in the 'radio_scripts' directory inside the upmpdcli directory
1174
(typically '/usr/share/upmpdcli').
1175
1176
1177
The script should output the metadata in JSON format. An example output
1178
follows (the newlines and whitespace are just here for readability, any
1179
valid JSON will do):
1180
1181
----
1182
{
1183
    "title" : "The title of the current track",
1184
    "artist" : "The artist playing",
1185
    "album": "The album name",
1186
    "artUrl" : "https://www.somesite.com/path/to/image.jpg",
1187
    "audioUrl" : "http://some url",
1188
    "reload" : 103
1189
}
1190
----
1191
1192
The +reload+ value gives the number of seconds after which the script
1193
should be re-executed (the clever radio sets this to the remaining song
1194
time). By default, the script is executed every 10 S.
1195
1196
Any value not present will simply not be used (not an error). +audioUrl+ is
1197
generally not set. If it is set, it's the next audio Url to queue after the
1198
current one (this is used for radio streams which are a sequences of URLs
1199
rather than a continuous stream, for example the Radio Paradise FLAC
1200
station).
1201
1202
The 'radio_scripts' directory has two examples of radio metadata scripts, a
1203
simple one ('fip-meta.py'), and a quite complicated one
1204
('radio-paradise-get-flac.py').
1205
1206
1206
1207
[[COMMAND-ENVIRON]]
1207
[[COMMAND-ENVIRON]]
1208
== Annex: command line and environment
1208
== Annex: command line and environment
1209
1209
1210
In most situations, *upmpdcli* will be run as follows:
1210
In most situations, *upmpdcli* will be run as follows: