forked from nu774/qaac
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplaylist.cpp
More file actions
55 lines (50 loc) · 1.91 KB
/
playlist.cpp
File metadata and controls
55 lines (50 loc) · 1.91 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
#include "playlist.h"
#include "strutil.h"
#include "metadata.h"
#include "expand.h"
namespace playlist {
class TagLookup {
typedef std::map<std::string, std::string> meta_t;
const meta_t &tracktags;
public:
TagLookup(const meta_t &tags): tracktags(tags) {}
std::wstring operator()(const std::wstring &name) {
std::string key =
TextBasedTag::normalizeTagName(strutil::w2us(name).c_str());
meta_t::const_iterator iter = tracktags.find(key);
if (iter == tracktags.end())
return L"";
else if (key == "track number" || key == "DISC NUMBER") {
strutil::Tokenizer<char> tok(iter->second, "/");
unsigned n = 0;
sscanf(tok.next(), "%u", &n);
return strutil::format(L"%02u", n);
}
auto val = strutil::us2w(iter->second);
return strutil::strtransform(val, [](wchar_t c)->wchar_t {
return std::wcschr(L":/\\?|<>*\"", c) ? L'_' : c;
});
}
};
std::wstring generateFileName(const std::wstring &spec,
const std::map<std::string, std::string> &tag)
{
auto spec2 = strutil::strtransform(spec, [](wchar_t c)->wchar_t {
return c == L'\\' ? L'/' : c;
});
auto res = process_template(spec2, TagLookup(tag));
std::vector<std::wstring> comp;
strutil::Tokenizer<wchar_t> tokens(res, L"/");
wchar_t *tok;
while ((tok = tokens.next())) {
if (wcslen(tok) > 250)
tok[250] = 0;
comp.push_back(tok);
}
res.clear();
for (size_t i = 0; i < comp.size() - 1; ++i)
res += comp[i] + L"/";
res += comp[comp.size() - 1];
return res;
}
} // namespace playlist