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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
#include "main.h"
#include "../replicant/nu/AutoChar.h"
#include "../replicant/nu/ns_wc.h"
#include <shlwapi.h>
#include <malloc.h> // for alloca
static wchar_t m_lastfn[2048];
static wchar_t m_lastartist[256], m_lasttitle[256], m_lastalbum[256], m_gracenotefileid[128];
static int m_lasttrack;
static int m_playcount;
static int m_ispodcast;
static int m_rating;
static int m_db_found;
void ClearTitleHookCache()
{
memset(m_lastfn, 0, sizeof(m_lastfn));
}
BOOL IPC_HookExtInfoW(INT_PTR param)
{
if (skipTitleInfo) // we're reading metadata and being asked to skip title hooking (so we can get a valid title for guessing, if need be)
return false;
extendedFileInfoStructW *p = (extendedFileInfoStructW *)param;
// fill in our own titles from db? not for now, just let it default to hitting the tags?
if (!g_config->ReadInt(L"newtitle", 1))
return FALSE;
if (NULL == p->filename || L'\0' == *p->filename ||
NULL == p->metadata || L'\0' == *p->metadata)
{
return FALSE;
}
int which = 0;
if (!_wcsicmp(p->metadata, DB_FIELDNAME_artist )) which = 1;
else if (!_wcsicmp(p->metadata, DB_FIELDNAME_title )) which = 2;
else if (!_wcsicmp(p->metadata, DB_FIELDNAME_album )) which = 3;
//else if (!_wcsicmp(p->metadata, L"tuid")) which = 4;
else if (!_wcsicmp(p->metadata, DB_FIELDNAME_track )) which = 5;
else if (!_wcsicmp(p->metadata, DB_FIELDNAME_rating )) which = 6;
else if (!_wcsicmp(p->metadata, DB_FIELDNAME_playcount )) which = 7;
else if (!_wcsicmp(p->metadata, DB_FIELDNAME_GracenoteFileID )) which=8;
else if (!_wcsicmp(p->metadata, DB_FIELDNAME_ispodcast )) which=9;
if (which)
{
if (_wcsicmp(m_lastfn, p->filename))
{
if (!g_table) openDb();
if (!g_table) return 0;
m_lastartist[0] = 0;
m_lasttitle[0] = 0;
m_lastalbum[0] = 0;
m_gracenotefileid[0]=0;
m_lasttrack = 0;
m_rating=-1;
m_playcount=-1;
m_ispodcast=-1;
lstrcpynW(m_lastfn, p->filename, sizeof(m_lastfn)/sizeof(wchar_t));
wchar_t filename2[MAX_PATH] = {0}; // full lfn path if set
EnterCriticalSection(&g_db_cs);
nde_scanner_t s = NDE_Table_CreateScanner(g_table);
int found = FindFileInDatabase(s, MAINTABLE_ID_FILENAME, m_lastfn, filename2);
if (found == 2)
lstrcpynW(m_lastfn, filename2, sizeof(m_lastfn)/sizeof(m_lastfn));
if (found)
{
nde_field_t f = NDE_Scanner_GetFieldByID(s, MAINTABLE_ID_ARTIST);
if (f) lstrcpynW(m_lastartist, NDE_StringField_GetString(f), sizeof(m_lastartist)/sizeof(wchar_t));
f = NDE_Scanner_GetFieldByID(s, MAINTABLE_ID_ALBUM);
if (f) lstrcpynW(m_lastalbum, NDE_StringField_GetString(f), sizeof(m_lastalbum)/sizeof(wchar_t));
f = NDE_Scanner_GetFieldByID(s, MAINTABLE_ID_TITLE);
if (f) lstrcpynW(m_lasttitle, NDE_StringField_GetString(f), sizeof(m_lasttitle)/sizeof(wchar_t));
f = NDE_Scanner_GetFieldByID(s, MAINTABLE_ID_TRACKNB);
if (f) m_lasttrack = NDE_IntegerField_GetValue(f);
f = NDE_Scanner_GetFieldByID(s, MAINTABLE_ID_PLAYCOUNT);
if (f) m_playcount = NDE_IntegerField_GetValue(f);
f = NDE_Scanner_GetFieldByID(s, MAINTABLE_ID_RATING);
if (f) m_rating = NDE_IntegerField_GetValue(f);
f = NDE_Scanner_GetFieldByID(s, MAINTABLE_ID_ISPODCAST);
if (f) m_ispodcast = NDE_IntegerField_GetValue(f);
f = NDE_Scanner_GetFieldByID(s, MAINTABLE_ID_GRACENOTEFILEID);
if (f) lstrcpynW(m_gracenotefileid, NDE_StringField_GetString(f), sizeof(m_gracenotefileid)/sizeof(wchar_t));
m_db_found = 1;
}
else m_db_found = 0;
NDE_Table_DestroyScanner(g_table, s);
LeaveCriticalSection(&g_db_cs);
}
if (m_db_found == 1)
{
switch(which)
{
case 1:
if (m_lastartist[0])
{
lstrcpynW(p->ret, m_lastartist, p->retlen);
return 1;
}
break;
case 2:
if (m_lasttitle[0])
{
lstrcpynW(p->ret, m_lasttitle, p->retlen);
return 1;
}
break;
case 3:
if (m_lastalbum[0])
{
lstrcpynW(p->ret, m_lastalbum, p->retlen);
return 1;
}
break;
case 5:
if (m_lasttrack && m_lasttrack != -1)
{
_snwprintf(p->ret, p->retlen, L"%d", m_lasttrack);
return 1;
}
break;
case 6:
if (m_rating != -1)
{
_snwprintf(p->ret, p->retlen, L"%d", m_rating);
return 1;
}
break;
case 7:
if (m_playcount != -1)
{
_snwprintf(p->ret, p->retlen, L"%d", m_playcount);
return 1;
}
break;
case 8:
if (m_gracenotefileid[0])
{
lstrcpynW(p->ret, m_gracenotefileid, p->retlen);
return 1;
}
break;
case 9:
if (m_ispodcast != -1)
{
_snwprintf(p->ret, p->retlen, L"%d", m_ispodcast);
return 1;
}
break;
}
}
}
return FALSE;
}
BOOL IPC_HookExtInfo(INT_PTR param)
{
extendedFileInfoStruct *p = (extendedFileInfoStruct*)param;
// fill in our own titles from db? not for now, just let it default to hitting the tags?
if (!g_config->ReadInt(L"newtitle", 1))
return FALSE;
if (NULL == p->filename || '\0' == *p->filename ||
NULL == p->metadata || '\0' == *p->metadata)
{
return FALSE;
}
extendedFileInfoStructW pW = {0};
AutoWide wideFn(p->filename), wideMetadata(p->metadata);
pW.filename = wideFn;
pW.metadata = wideMetadata;
pW.retlen = p->retlen;
pW.ret = (wchar_t *)alloca(pW.retlen * sizeof(wchar_t));
if (IPC_HookExtInfoW((INT_PTR)&pW))
{
WideCharToMultiByteSZ(CP_ACP, 0, pW.ret, -1, p->ret, p->retlen, 0, 0);
return 1;
}
return 0;
}
BOOL IPC_HookTitleInfo(INT_PTR param)
{
if (skipTitleInfo) // we're reading metadata and being asked to skip title hooking (so we can get a valid title for guessing, if need be)
return false;
waHookTitleStructW *hts = (waHookTitleStructW*)param;
if (NULL != hts->filename &&
!StrStrW(hts->filename, L"://") &&
g_config->ReadInt(L"newtitle", 1))
{
if (!g_table) openDb();
if (!g_table) return 0;
wchar_t filename2[MAX_PATH] = {0}; // full lfn path if set
EnterCriticalSection(&g_db_cs);
nde_scanner_t s = NDE_Table_CreateScanner(g_table);
int found=FindFileInDatabase(s, MAINTABLE_ID_FILENAME, hts->filename, filename2);
if (found)
{
nde_field_t length = NDE_Scanner_GetFieldByID(s, MAINTABLE_ID_LENGTH);
int l = -1;
if (length)
l = NDE_IntegerField_GetValue(length);
if (l > 0)
hts->length = l;
else hts->length = -1;
if (hts->title)
{
TAG_FMT_EXT(hts->filename, fieldTagFunc, ndeTagFuncFree, (void*)s, hts->title, 2048, 1);
}
}
NDE_Table_DestroyScanner(g_table, s);
LeaveCriticalSection(&g_db_cs);
if (found) return 1;
} // not http://
return FALSE;
}
DWORD doGuessProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
// call the old wndproc, and if it produces empty results or no results, try to guess
extendedFileInfoStruct *p = (extendedFileInfoStruct*)wParam;
LRESULT ret = CallWindowProc(wa_oldWndProc, hwndDlg, uMsg, wParam, lParam);
if (NULL != p &&
(!ret || !p->ret[0]) &&
g_config->ReadInt(L"guessmode", 0) != 2)
{
int which = 0;
if (NULL != p->metadata)
{
if (!_stricmp(p->metadata, "artist")) which = 1;
else if (!_stricmp(p->metadata, "title")) which = 2;
else if (!_stricmp(p->metadata, "album")) which = 3;
else if (!_stricmp(p->metadata, "track")) which = 5;
else which = 0;
}
else
which = 0;
if (which)
{
static char m_lastfn[2048];
if (NULL != p->filename && _strnicmp(m_lastfn, p->filename, sizeof(m_lastfn)))
{
m_db_found = 2;
m_lastartist[0] = 0;
m_lasttitle[0] = 0;
m_lastalbum[0] = 0;
m_lasttrack = 0;
StringCbCopyA(m_lastfn, sizeof(m_lastfn), p->filename);
int tn = 0;
wchar_t *artist = 0, *album = 0, *title = 0;
wchar_t *guessbuf = guessTitles(AutoWide(m_lastfn), &tn, &artist, &album, &title);
if (guessbuf)
{
if (artist) StringCbCopyW(m_lastartist, sizeof(m_lastartist), artist);
if (album) StringCbCopyW(m_lastalbum, sizeof(m_lastalbum), album);
if (title) StringCbCopyW(m_lasttitle, sizeof(m_lasttitle), title);
m_lasttrack = tn;
free(guessbuf);
}
}
if (m_db_found == 2)
{
if (which == 1 && m_lastartist[0])
{
WideCharToMultiByteSZ(CP_ACP, 0, m_lastartist, -1, p->ret, p->retlen, 0, 0);
return 1;
}
if (which == 2 && m_lasttitle[0])
{
WideCharToMultiByteSZ(CP_ACP, 0, m_lasttitle, -1, p->ret, p->retlen, 0, 0);
return 1;
}
if (which == 3 && m_lastalbum[0])
{
WideCharToMultiByteSZ(CP_ACP, 0, m_lastalbum, -1, p->ret, p->retlen, 0, 0);
return 1;
}
if (which == 5 && m_lasttrack)
{
_snprintf(p->ret, p->retlen, "%d", m_lasttrack);
return 1;
}
if (which == 6 && m_rating != -1)
{
_snprintf(p->ret, p->retlen, "%d", m_rating);
return 1;
}
if (which == 7 && m_playcount != -1)
{
_snprintf(p->ret, p->retlen, "%d", m_playcount);
return 1;
}
}
}
}
return (int)ret;
}
|