aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-01-10 10:17:30 +0100
committerMax Kellermann <max@duempel.org>2014-01-11 01:31:13 +0100
commitf031eb1ef22373f94838b7e3357f2913ced6db71 (patch)
treee6261d0a22ba0f08dad462e678611efd9db84ab8 /src
parentb50d79542c95ab88387418b34999e942e6b6a583 (diff)
downloadmpd-f031eb1ef22373f94838b7e3357f2913ced6db71.tar.gz
mpd-f031eb1ef22373f94838b7e3357f2913ced6db71.tar.xz
mpd-f031eb1ef22373f94838b7e3357f2913ced6db71.zip
db/upnp/Directory: parse duration
Don't put all <res/> attributes to the attributes map; parse the "duration" attribute as soon as we receive it, and store it in an integer attribute. This reduces bloat.
Diffstat (limited to 'src')
-rw-r--r--src/db/UpnpDatabasePlugin.cxx15
-rw-r--r--src/db/upnp/Directory.cxx29
-rw-r--r--src/db/upnp/Object.hxx6
3 files changed, 22 insertions, 28 deletions
diff --git a/src/db/UpnpDatabasePlugin.cxx b/src/db/UpnpDatabasePlugin.cxx
index be035bb00..5228d8b60 100644
--- a/src/db/UpnpDatabasePlugin.cxx
+++ b/src/db/UpnpDatabasePlugin.cxx
@@ -229,16 +229,6 @@ titleToPathElt(const std::string &in)
return out;
}
-gcc_pure
-static int
-upnpDurationToSeconds(const std::string &duration)
-{
- const auto v = stringToTokens(duration, ":");
- if (v.size() != 3)
- return 0;
- return atoi(v[0].c_str())*3600 + atoi(v[1].c_str())*60 + atoi(v[2].c_str());
-}
-
// If uri is empty, we use the object's url instead. This happens
// when the target of a Visit() is a song, which only happens when
// "add"ing AFAIK. Visit() calls us with a null uri so that the url
@@ -253,9 +243,8 @@ upnpItemToSong(const UPnPDirObject &dirent, const char *uri)
TagBuilder tag;
- const char *duration = dirent.getprop("duration");
- if (duration != nullptr)
- tag.SetTime(upnpDurationToSeconds(duration));
+ if (dirent.duration > 0)
+ tag.SetTime(dirent.duration);
tag.AddItem(TAG_TITLE, titleToPathElt(dirent.m_title).c_str());
diff --git a/src/db/upnp/Directory.cxx b/src/db/upnp/Directory.cxx
index cbe025e7a..8930890f3 100644
--- a/src/db/upnp/Directory.cxx
+++ b/src/db/upnp/Directory.cxx
@@ -36,16 +36,6 @@ static const char *const upnptags[] = {
nullptr,
};
-static const char *const res_attributes[] = {
- "protocolInfo",
- "size",
- "bitrate",
- "duration",
- "sampleFrequency",
- "nrAudioChannels",
- nullptr,
-};
-
gcc_pure
static UPnPDirObject::ItemClass
ParseItemClass(const char *name)
@@ -58,6 +48,16 @@ ParseItemClass(const char *name)
return UPnPDirObject::ItemClass::UNKNOWN;
}
+gcc_pure
+static int
+ParseDuration(const std::string &duration)
+{
+ const auto v = stringToTokens(duration, ":");
+ if (v.size() != 3)
+ return 0;
+ return atoi(v[0].c_str())*3600 + atoi(v[1].c_str())*60 + atoi(v[2].c_str());
+}
+
/**
* An XML parser which builds directory contents from DIDL lite input.
*/
@@ -114,11 +114,10 @@ protected:
// bitrate="24576" duration="00:03:35" sampleFrequency="44100"
// nrAudioChannels="2">
- for (auto i = res_attributes; *i != nullptr; ++i) {
- const char *value = GetAttribute(attrs, *i);
- if (value != nullptr)
- m_tobj.m_props.emplace(*i, value);
- }
+ const char *duration =
+ GetAttribute(attrs, "duration");
+ if (duration != nullptr)
+ m_tobj.duration = ParseDuration(duration);
}
break;
diff --git a/src/db/upnp/Object.hxx b/src/db/upnp/Object.hxx
index a3bb026b8..91a219534 100644
--- a/src/db/upnp/Object.hxx
+++ b/src/db/upnp/Object.hxx
@@ -58,6 +58,11 @@ public:
// The map keys are the XML tag or attribute names.
std::map<std::string, std::string> m_props;
+ /**
+ * Song duration in seconds. 0 if unknown.
+ */
+ int duration;
+
/** Get named property
* @param property name (e.g. upnp:artist, upnp:album,
* upnp:originalTrackNumber, upnp:genre). Use m_title instead
@@ -80,6 +85,7 @@ public:
type = Type::UNKNOWN;
item_class = ItemClass::UNKNOWN;
m_props.clear();
+ duration = -1;
}
};