forked from TheSaw/win7shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.cpp
96 lines (89 loc) · 1.96 KB
/
metadata.cpp
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
#include "gen_win7shell.h"
#include <map>
#include <ctype.h>
#include "metadata.h"
#include <sdk/winamp/wa_ipc.h>
#include <sdk/winamp/gen.h>
#include <loader/loader/utils.h>
#include "api.h"
extern winampGeneralPurposePlugin plugin;
void MetaData::reset(LPCWSTR filename, const bool force)
{
if (force || (filename != mfilename))
{
cache.clear();
mfilename = plugin.memmgr->sysDupStr(filename, mfilename);
}
}
std::wstring MetaData::getMetadata(const std::wstring &tag, void **token, bool* reentrant, INT_PTR *db_error)
{
if (!cache.empty() && cache.find(tag) != cache.end())
{
return cache.find(tag)->second;
}
if (mfilename && *mfilename)
{
wchar_t buffer[GETFILEINFO_TITLE_LENGTH] = { 0 };
// cache the response as long as we got a valid result
GetFileMetaData(mfilename, tag.c_str(), buffer, ARRAYSIZE(buffer),
token, reentrant, db_error);
if (buffer[0])
{
cache[tag] = buffer;
return buffer;
}
else
{
std::wstring ret;
const bool artist = (tag == L"artist"), title = (tag == L"title");
if (title || artist)
{
LPCWSTR playing_title = GetPlayingTitle(0);
if (!playing_title || !*playing_title)
{
return L"";
}
ret = playing_title;
size_t pos = ret.find_first_of('-');
if (pos != std::wstring::npos && pos != 0)
{
if (title)
{
ret = std::wstring(ret, pos + 1, ret.length() - (pos - 2));
if (ret[0] == L' ')
{
ret.erase(0, 1);
}
}
else if (artist)
{
ret = std::wstring(ret, 0, pos);
--pos;
if (ret[pos] == L' ')
{
ret.erase(pos, 1);
}
}
}
else
{
if (artist)
{
return L"";
}
}
}
else
{
return L"";
}
cache[tag] = ret;
return ret;
}
}
return L"";
}
LPCWSTR MetaData::getFileName(void) const
{
return (mfilename && *mfilename ? mfilename : L"");
}