|
a/upmpd/ohplaylist.cxx |
|
b/upmpd/ohplaylist.cxx |
|
... |
|
... |
141 |
{
|
141 |
{
|
142 |
// Retrieve the data for current queue songs from mpd, and make an
|
142 |
// Retrieve the data for current queue songs from mpd, and make an
|
143 |
// ohPlaylist id array.
|
143 |
// ohPlaylist id array.
|
144 |
vector<UpSong> vdata;
|
144 |
vector<UpSong> vdata;
|
145 |
bool ok = m_dev->m_mpdcli->getQueueData(vdata);
|
145 |
bool ok = m_dev->m_mpdcli->getQueueData(vdata);
|
146 |
if (!ok)
|
146 |
if (!ok) {
|
|
|
147 |
LOGERR("OHPlaylist::makeIdArray: getQueueData failed."
|
|
|
148 |
"metacache size " << m_metacache.size() << endl);
|
147 |
return false;
|
149 |
return false;
|
|
|
150 |
}
|
148 |
|
151 |
|
149 |
out = translateIdArray(vdata);
|
152 |
out = translateIdArray(vdata);
|
150 |
|
153 |
|
151 |
// Update metadata cache: entries not in the curren id list are
|
154 |
// Update metadata cache: entries not in the current list are
|
152 |
// not valid any more. Also there may be entries which were added
|
155 |
// not valid any more. Also there may be entries which were added
|
153 |
// through an MPD client and which don't know about, record the
|
156 |
// through an MPD client and which don't know about, record the
|
154 |
// metadata for these. We don't update the current array, but
|
157 |
// metadata for these. We don't update the current array, but
|
155 |
// just build a new cache for data about current entries
|
158 |
// just build a new cache for data about current entries.
|
|
|
159 |
//
|
|
|
160 |
// The songids are not preserved through mpd restarts (they
|
|
|
161 |
// restart at 0) this means that the ids are not a good cache key,
|
|
|
162 |
// we use the uris instead.
|
156 |
unordered_map<int, string> nmeta;
|
163 |
unordered_map<string, string> nmeta;
|
157 |
|
164 |
|
158 |
// Walk the playlist data from MPD
|
165 |
// Walk the playlist data from MPD
|
159 |
for (auto& usong : vdata) {
|
166 |
for (auto& usong : vdata) {
|
160 |
auto inold = m_metacache.find(usong.mpdid);
|
167 |
auto inold = m_metacache.find(usong.uri);
|
161 |
if (inold != m_metacache.end()) {
|
168 |
if (inold != m_metacache.end()) {
|
162 |
// Entries already in the metadata array just get
|
169 |
// Entries already in the metadata array just get
|
163 |
// transferred to the new array
|
170 |
// transferred to the new array
|
164 |
nmeta[usong.mpdid].swap(inold->second);
|
171 |
nmeta[usong.uri].swap(inold->second);
|
165 |
} else {
|
172 |
} else {
|
166 |
// Entries not in the old array are translated from the
|
173 |
// Entries not in the old array are translated from the
|
167 |
// MPD data to our format. They were probably added by
|
174 |
// MPD data to our format. They were probably added by
|
168 |
// another MPD client.
|
175 |
// another MPD client.
|
169 |
nmeta[usong.mpdid] = didlmake(usong);
|
176 |
nmeta[usong.uri] = didlmake(usong);
|
|
|
177 |
LOGDEB("OHPlaylist::makeIdArray: set mpd data for " <<
|
|
|
178 |
usong.mpdid << endl);
|
170 |
}
|
179 |
}
|
171 |
}
|
180 |
}
|
172 |
m_metacache = nmeta;
|
181 |
m_metacache = nmeta;
|
173 |
|
182 |
|
174 |
return true;
|
183 |
return true;
|
|
... |
|
... |
400 |
UpSong song;
|
409 |
UpSong song;
|
401 |
if (ok) {
|
410 |
if (ok) {
|
402 |
ok = m_dev->m_mpdcli->statSong(song, id, true);
|
411 |
ok = m_dev->m_mpdcli->statSong(song, id, true);
|
403 |
}
|
412 |
}
|
404 |
if (ok) {
|
413 |
if (ok) {
|
405 |
auto cached = m_metacache.find(id);
|
414 |
auto cached = m_metacache.find(song.uri);
|
406 |
string metadata;
|
415 |
string metadata;
|
407 |
if (cached != m_metacache.end()) {
|
416 |
if (cached != m_metacache.end()) {
|
408 |
metadata = SoapArgs::xmlQuote(cached->second);
|
417 |
metadata = SoapArgs::xmlQuote(cached->second);
|
409 |
} else {
|
418 |
} else {
|
|
|
419 |
metadata = didlmake(song);
|
|
|
420 |
m_metacache[song.uri] = metadata;
|
410 |
metadata = SoapArgs::xmlQuote(didlmake(song));
|
421 |
metadata = SoapArgs::xmlQuote(metadata);
|
411 |
}
|
422 |
}
|
412 |
data.addarg("Uri", song.uri);
|
423 |
data.addarg("Uri", song.uri);
|
413 |
data.addarg("Metadata", metadata);
|
424 |
data.addarg("Metadata", metadata);
|
414 |
}
|
425 |
}
|
415 |
return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
|
426 |
return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
|
|
... |
|
... |
439 |
for (auto& sid : ids) {
|
450 |
for (auto& sid : ids) {
|
440 |
int id = atoi(sid.c_str());
|
451 |
int id = atoi(sid.c_str());
|
441 |
UpSong song;
|
452 |
UpSong song;
|
442 |
if (!m_dev->m_mpdcli->statSong(song, id, true))
|
453 |
if (!m_dev->m_mpdcli->statSong(song, id, true))
|
443 |
continue;
|
454 |
continue;
|
444 |
auto mit = m_metacache.find(id);
|
455 |
auto mit = m_metacache.find(song.uri);
|
445 |
string metadata;
|
456 |
string metadata;
|
446 |
if (mit != m_metacache.end()) {
|
457 |
if (mit != m_metacache.end()) {
|
|
|
458 |
//LOGDEB("readList: metadata for songid " << id << " uri "
|
|
|
459 |
// << song.uri << " found in cache " << endl);
|
447 |
metadata = SoapArgs::xmlQuote(mit->second);
|
460 |
metadata = SoapArgs::xmlQuote(mit->second);
|
448 |
} else {
|
461 |
} else {
|
|
|
462 |
//LOGDEB("readList: metadata for songid " << id << " uri "
|
|
|
463 |
// << song.uri << " not found " << endl);
|
|
|
464 |
metadata = didlmake(song);
|
|
|
465 |
m_metacache[song.uri] = metadata;
|
449 |
metadata = SoapArgs::xmlQuote(didlmake(song));
|
466 |
metadata = SoapArgs::xmlQuote(metadata);
|
450 |
}
|
467 |
}
|
451 |
out += "<Entry><Id>";
|
468 |
out += "<Entry><Id>";
|
452 |
out += sid.c_str();
|
469 |
out += sid.c_str();
|
453 |
out += "</Id><Uri>";
|
470 |
out += "</Id><Uri>";
|
454 |
out += song.uri;
|
471 |
out += song.uri;
|
|
... |
|
... |
482 |
LOGDEB("OHPlaylist::insert: afterid " << afterid << " Uri " <<
|
499 |
LOGDEB("OHPlaylist::insert: afterid " << afterid << " Uri " <<
|
483 |
uri << " Metadata " << metadata << endl);
|
500 |
uri << " Metadata " << metadata << endl);
|
484 |
if (ok) {
|
501 |
if (ok) {
|
485 |
int id = m_dev->m_mpdcli->insertAfterId(uri, afterid);
|
502 |
int id = m_dev->m_mpdcli->insertAfterId(uri, afterid);
|
486 |
if ((ok = (id != -1))) {
|
503 |
if ((ok = (id != -1))) {
|
487 |
m_metacache[id] = metadata;
|
504 |
m_metacache[uri] = metadata;
|
488 |
data.addarg("NewId", SoapArgs::i2s(id));
|
505 |
data.addarg("NewId", SoapArgs::i2s(id));
|
489 |
}
|
506 |
}
|
490 |
}
|
507 |
}
|
491 |
maybeWakeUp(ok);
|
508 |
maybeWakeUp(ok);
|
492 |
return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
|
509 |
return ok ? UPNP_E_SUCCESS : UPNP_E_INTERNAL_ERROR;
|