|
a/upmpd/upmpdutils.cxx |
|
b/upmpd/upmpdutils.cxx |
|
... |
|
... |
40 |
using namespace std;
|
40 |
using namespace std;
|
41 |
|
41 |
|
42 |
#include "mpdcli.hxx"
|
42 |
#include "mpdcli.hxx"
|
43 |
#include "upmpdutils.hxx"
|
43 |
#include "upmpdutils.hxx"
|
44 |
#include "libupnpp/log.hxx"
|
44 |
#include "libupnpp/log.hxx"
|
|
|
45 |
#include "libupnpp/soaphelp.hxx"
|
45 |
|
46 |
|
46 |
// Append system error string to input string
|
47 |
// Append system error string to input string
|
47 |
void catstrerror(string *reason, const char *what, int _errno)
|
48 |
void catstrerror(string *reason, const char *what, int _errno)
|
48 |
{
|
49 |
{
|
49 |
if (!reason)
|
50 |
if (!reason)
|
|
... |
|
... |
208 |
startPos = ++pos;
|
209 |
startPos = ++pos;
|
209 |
}
|
210 |
}
|
210 |
}
|
211 |
}
|
211 |
}
|
212 |
}
|
212 |
|
213 |
|
213 |
string xmlquote(const string& in)
|
|
|
214 |
{
|
|
|
215 |
string out;
|
|
|
216 |
for (unsigned int i = 0; i < in.size(); i++) {
|
|
|
217 |
switch(in[i]) {
|
|
|
218 |
case '"': out += """;break;
|
|
|
219 |
case '&': out += "&";break;
|
|
|
220 |
case '<': out += "<";break;
|
|
|
221 |
case '>': out += ">";break;
|
|
|
222 |
case '\'': out += "'";break;
|
|
|
223 |
default: out += in[i];
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
return out;
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
// Translate 0-100% MPD volume to UPnP VolumeDB: we do db upnp-encoded
|
214 |
// Translate 0-100% MPD volume to UPnP VolumeDB: we do db upnp-encoded
|
230 |
// values from -10240 (0%) to 0 (100%)
|
215 |
// values from -10240 (0%) to 0 (100%)
|
231 |
int percentodbvalue(int value)
|
216 |
int percentodbvalue(int value)
|
232 |
{
|
217 |
{
|
233 |
int dbvalue;
|
218 |
int dbvalue;
|
|
... |
|
... |
322 |
"xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" "
|
307 |
"xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\" "
|
323 |
"xmlns:dlna=\"urn:schemas-dlna-org:metadata-1-0/\">"
|
308 |
"xmlns:dlna=\"urn:schemas-dlna-org:metadata-1-0/\">"
|
324 |
<< "<item restricted=\"1\">";
|
309 |
<< "<item restricted=\"1\">";
|
325 |
|
310 |
|
326 |
{ const string& val = song.title;
|
311 |
{ const string& val = song.title;
|
327 |
ss << "<dc:title>" << xmlquote(val) << "</dc:title>";
|
312 |
ss << "<dc:title>" << SoapArgs::xmlQuote(val) << "</dc:title>";
|
328 |
}
|
313 |
}
|
329 |
|
314 |
|
330 |
// TBD Playlists etc?
|
315 |
// TBD Playlists etc?
|
331 |
ss << "<upnp:class>object.item.audioItem.musicTrack</upnp:class>";
|
316 |
ss << "<upnp:class>object.item.audioItem.musicTrack</upnp:class>";
|
332 |
|
317 |
|
333 |
{ const string& val = song.artist;
|
318 |
{ const string& val = song.artist;
|
334 |
if (!val.empty()) {
|
319 |
if (!val.empty()) {
|
335 |
string a = xmlquote(val);
|
320 |
string a = SoapArgs::xmlQuote(val);
|
336 |
ss << "<dc:creator>" << a << "</dc:creator>" <<
|
321 |
ss << "<dc:creator>" << a << "</dc:creator>" <<
|
337 |
"<upnp:artist>" << a << "</upnp:artist>";
|
322 |
"<upnp:artist>" << a << "</upnp:artist>";
|
338 |
}
|
323 |
}
|
339 |
}
|
324 |
}
|
340 |
|
325 |
|
341 |
{ const string& val = song.album;
|
326 |
{ const string& val = song.album;
|
342 |
if (!val.empty()) {
|
327 |
if (!val.empty()) {
|
343 |
ss << "<upnp:album>" << xmlquote(val) << "</upnp:album>";
|
328 |
ss << "<upnp:album>" << SoapArgs::xmlQuote(val) << "</upnp:album>";
|
344 |
}
|
329 |
}
|
345 |
}
|
330 |
}
|
346 |
|
331 |
|
347 |
{ const string& val = song.genre;
|
332 |
{ const string& val = song.genre;
|
348 |
if (!val.empty()) {
|
333 |
if (!val.empty()) {
|
349 |
ss << "<upnp:genre>" << xmlquote(val) << "</upnp:genre>";
|
334 |
ss << "<upnp:genre>" << SoapArgs::xmlQuote(val) << "</upnp:genre>";
|
350 |
}
|
335 |
}
|
351 |
}
|
336 |
}
|
352 |
|
337 |
|
353 |
{const string& val = song.tracknum;
|
338 |
{const string& val = song.tracknum;
|
354 |
if (!val.empty()) {
|
339 |
if (!val.empty()) {
|
|
... |
|
... |
368 |
// it out for now.
|
353 |
// it out for now.
|
369 |
// << "bitrate=\"" << mpds.kbrate << "\" "
|
354 |
// << "bitrate=\"" << mpds.kbrate << "\" "
|
370 |
<< "sampleFrequency=\"44100\" audioChannels=\"2\" "
|
355 |
<< "sampleFrequency=\"44100\" audioChannels=\"2\" "
|
371 |
<< "protocolInfo=\"http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000\""
|
356 |
<< "protocolInfo=\"http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000\""
|
372 |
<< ">"
|
357 |
<< ">"
|
373 |
<< xmlquote(song.uri)
|
358 |
<< SoapArgs::xmlQuote(song.uri)
|
374 |
<< "</res>"
|
359 |
<< "</res>"
|
375 |
<< "</item></DIDL-Lite>";
|
360 |
<< "</item></DIDL-Lite>";
|
376 |
return ss.str();
|
361 |
return ss.str();
|
377 |
}
|
362 |
}
|
378 |
|
363 |
|