Parent: [be9be8] (diff)

Child: [4b5ddb] (diff)

Download this file

upmpdutils.hxx    147 lines (126 with data), 4.8 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* Copyright (C) 2014 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef _UPMPDUTILS_H_X_INCLUDED_
#define _UPMPDUTILS_H_X_INCLUDED_
#include <string>
#include <unordered_map>
#include <vector>
#include <unordered_set>
#include <unistd.h>
namespace UPnPClient {
class UPnPDirObject;
};
// Read file from datadir
bool readLibFile(const std::string& name, std::string& contents);
// This was originally purely a translation of data from mpd. Extended
// to general purpose track/container descriptor
class UpSong {
public:
UpSong() {
}
void clear() {
*this = UpSong();
}
std::string id;
std::string parentid;
std::string uri;
std::string name; // only set for radios apparently.
std::string artist;
std::string album;
std::string title;
std::string tracknum; // Reused as annot for containers
std::string genre;
std::string artUri;
std::string upnpClass;
std::string mime;
std::string date;
int duration_secs{0};
int64_t size{0};
int bitrate{0};
int samplefreq{0};
int bitsPerSample{0};
int channels{0};
int mpdid{0};
bool iscontainer{false};
bool searchable{false};
std::string dump() {
return std::string("class [" + upnpClass + "] Artist [" + artist +
"] Album [" + album + " Title [" + title +
"] Tno [" + tracknum + "] Uri [" + uri + "]");
}
// Format to DIDL fragment
std::string didl() const;
static UpSong container(const std::string& id, const std::string& pid,
const std::string& title, bool sable = true,
const std::string& annot = std::string()) {
UpSong song;
song.iscontainer = true;
song.id = id;
song.parentid = pid;
song.title = title;
song.searchable = sable;
song.tracknum = annot;
return song;
}
static UpSong item(const std::string& id, const std::string& parentid,
const std::string& title) {
UpSong song;
song.iscontainer = false;
song.id = id;
song.parentid = parentid;
song.title = title;
return song;
}
};
// Convert between db value to percent values (Get/Set Volume and VolumeDb)
extern int percentodbvalue(int value);
extern int dbvaluetopercent(int dbvalue);
extern bool sleepms(int ms);
// Return mapvalue or null strings, for maps where absent entry and
// null data are equivalent
extern const std::string& mapget(
const std::unordered_map<std::string, std::string>& im,
const std::string& k);
// Format a didl fragment from MPD status data. Used by the renderer
extern std::string didlmake(const UpSong& song);
// Wrap DIDL entries in header / trailer
extern const std::string& headDIDL();
extern const std::string& tailDIDL();
extern std::string wrapDIDL(const std::string& data);
// Convert UPnP metadata to UpSong for mpdcli to use
extern bool uMetaToUpSong(const std::string&, UpSong *ups);
// Convert UPnP content directory entry object to UpSong
bool dirObjToUpSong(const UPnPClient::UPnPDirObject& dobj, UpSong *ups);
// upsong with "Unknown" or such everywhere for when we get no metadata
void noMetaUpSong(UpSong *ups);
// Replace the first occurrence of regexp. cxx11 regex does not work
// that well yet...
extern std::string regsub1(const std::string& sexp, const std::string& input,
const std::string& repl);
// Return map with "newer" elements which differ from "old". Old may
// have fewer elts than "newer" (e.g. may be empty), we use the
// "newer" entries for diffing. This is used to compute state changes.
extern std::unordered_map<std::string, std::string>
diffmaps(const std::unordered_map<std::string, std::string>& old,
const std::unordered_map<std::string, std::string>& newer);
#define UPMPD_UNUSED(X) (void)(X)
extern bool ensureconfreadable(const char *fn, const char *user, uid_t uid,
gid_t gid);
class ConfSimple;
extern bool configBool(ConfSimple *conf, const std::string& nm,
bool dflt = false);
#endif /* _UPMPDUTILS_H_X_INCLUDED_ */