aboutsummaryrefslogtreecommitdiffstats
path: root/src/db/upnp/Directory.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-14 12:22:37 +0100
committerMax Kellermann <max@duempel.org>2014-01-14 12:22:37 +0100
commitefdb41f2a6c194f0ec6371684a8f6b8fcdbe0bcd (patch)
treed6ece56552200b98168018ecb3bde94dfa885bdc /src/db/upnp/Directory.cxx
parent26b850c15c605b4fc1404c4e8683791603f0e43c (diff)
downloadmpd-efdb41f2a6c194f0ec6371684a8f6b8fcdbe0bcd.tar.gz
mpd-efdb41f2a6c194f0ec6371684a8f6b8fcdbe0bcd.tar.xz
mpd-efdb41f2a6c194f0ec6371684a8f6b8fcdbe0bcd.zip
db/upnp/Object: add attribute "name"
Call titleToPathElt() only once for each object.
Diffstat (limited to '')
-rw-r--r--src/db/upnp/Directory.cxx23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx
index 3b75eceda..ba759837d 100644
--- a/src/db/upnp/Directory.cxx
+++ b/src/db/upnp/Directory.cxx
@@ -22,6 +22,7 @@
#include "Util.hxx"
#include "Expat.hxx"
+#include <algorithm>
#include <string>
#include <vector>
@@ -58,6 +59,19 @@ ParseDuration(const std::string &duration)
}
/**
+ * Transform titles to turn '/' into '_' to make them acceptable path
+ * elements. There is a very slight risk of collision in doing
+ * this. Twonky returns directory names (titles) like 'Artist/Album'.
+ */
+gcc_pure
+static std::string
+titleToPathElt(std::string s)
+{
+ std::replace(s.begin(), s.end(), '/', '_');
+ return s;
+}
+
+/**
* An XML parser which builds directory contents from DIDL lite input.
*/
class UPnPDirParser final : public CommonExpatParser {
@@ -125,7 +139,7 @@ protected:
bool checkobjok() {
if (m_tobj.m_id.empty() || m_tobj.m_pid.empty() ||
- m_tobj.m_title.empty() ||
+ m_tobj.name.empty() ||
(m_tobj.type == UPnPDirObject::Type::ITEM &&
m_tobj.item_class == UPnPDirObject::ItemClass::UNKNOWN))
return false;
@@ -154,8 +168,11 @@ protected:
trimstring(str);
switch (m_path.back()[0]) {
case 'd':
- if (!m_path.back().compare("dc:title"))
- m_tobj.m_title += str;
+ if (!m_path.back().compare("dc:title")) {
+ m_tobj.m_title = str;
+ m_tobj.name = titleToPathElt(str);
+ }
+
break;
case 'r':
if (!m_path.back().compare("res")) {