Music Hub  ..
A session-wide music playback service
metadata.cpp
Go to the documentation of this file.
1 /*
2  * Copyright © 2016 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
17  */
18 
19 #include "xesam.h"
20 
21 #include <core/media/track.h>
22 
23 #include <glib.h>
24 
25 namespace media = core::ubuntu::media;
26 
27 std::string media::Track::MetaData::encode(const std::string& key) const
28 {
29  if (not is_set(key))
30  return std::string{};
31 
32  char* escaped {g_uri_escape_string(map.at(key).c_str(),
33  "!$&'()*+,;=:/?[]@", // Reserved chars
34  true)};
35  if (!escaped)
36  {
37  return std::string{};
38  }
39  else
40  {
41  std::string s{escaped};
42  g_free(escaped);
43  return s;
44  }
45 }
46 
47 const std::string& media::Track::MetaData::album() const
48 {
49  return map.at(xesam::Album::name);
50 }
51 
52 const std::string& media::Track::MetaData::artist() const
53 {
54  return map.at(xesam::Artist::name);
55 }
56 
57 const std::string& media::Track::MetaData::title() const
58 {
59  return map.at(xesam::Title::name);
60 }
61 
62 const std::string& media::Track::MetaData::track_id() const
63 {
64  return map.at(media::Track::MetaData::TrackIdKey);
65 }
66 
67 const std::string& media::Track::MetaData::track_length() const
68 {
69  return map.at(media::Track::MetaData::TrackLengthKey);
70 }
71 
72 const std::string& media::Track::MetaData::art_url() const
73 {
74  return map.at(media::Track::MetaData::TrackArtlUrlKey);
75 }
76 
77 const std::string& media::Track::MetaData::last_used() const
78 {
79  return map.at(xesam::LastUsed::name);
80 }
81 
82 void media::Track::MetaData::set_album(const std::string& album)
83 {
84  map[xesam::Album::name] = album;
85 }
86 
87 void media::Track::MetaData::set_artist(const std::string& artist)
88 {
89  map[xesam::Artist::name] = artist;
90 }
91 
92 void media::Track::MetaData::set_title(const std::string& title)
93 {
94  map[xesam::Title::name] = title;
95 }
96 
97 void media::Track::MetaData::set_track_id(const std::string& id)
98 {
99  map[media::Track::MetaData::TrackIdKey] = id;
100 }
101 
102 void media::Track::MetaData::set_track_length(const std::string& length)
103 {
104  map[media::Track::MetaData::TrackLengthKey] = length;
105 }
106 
107 void media::Track::MetaData::set_art_url(const std::string& url)
108 {
109  map[media::Track::MetaData::TrackArtlUrlKey] = url;
110 }
111 
112 void media::Track::MetaData::set_last_used(const std::string& datetime)
113 {
114  map[xesam::LastUsed::name] = datetime;
115 }