94
94
<span class="ptBrand">by <a href="/Amon-Amarth/e/B000APIBHO/ref=sr_ntt_srch_lnk_1?qid=1328870421&sr=1-1">Amon Amarth</a> and <a href="/Amon-Amarth/e/B002E4DJ7Q/ref=sr_ntt_srch_lnk_1?qid=1328870421&sr=1-1">Amon Amarth</a></span>
96
96
QString str = QString::fromLatin1(searchStr);
97
QRegExp catIdTitleArtistRe(
97
QRegExp catIdTitleArtistRe(QLatin1String(
98
98
"<a class=\"title\" href=\"[^\"]+/(dp|ASIN|images|product|-)/([A-Z0-9]+)[^\"]+\">"
99
"([^<]+)<.*>\\s*by\\s*(?:<[^>]+>)?([^<]+)<");
100
QStringList lines = str.remove('\r').split(QRegExp("\\n{2,}"));
99
"([^<]+)<.*>\\s*by\\s*(?:<[^>]+>)?([^<]+)<"));
100
QStringList lines = str.remove(QLatin1Char('\r')).split(QRegExp(QLatin1String("\\n{2,}")));
101
101
m_albumListModel->clear();
102
102
for (QStringList::const_iterator it = lines.begin(); it != lines.end(); ++it) {
103
103
QString line(*it);
104
line.remove(QLatin1Char('\n'));
105
105
if (catIdTitleArtistRe.indexIn(line) != -1) {
106
106
m_albumListModel->appendRow(new AlbumListItem(
107
removeHtml(catIdTitleArtistRe.cap(4)) + " - " +
107
removeHtml(catIdTitleArtistRe.cap(4)) + QLatin1String(" - ") +
108
108
removeHtml(catIdTitleArtistRe.cap(3)),
109
109
catIdTitleArtistRe.cap(1),
110
110
catIdTitleArtistRe.cap(2)));
153
153
QString str = QString::fromLatin1(albumStr);
154
154
FrameCollection framesHdr;
155
const bool standardTags = getStandardTags();
155
156
// search for 'id="btAsinTitle"', text after '>' until ' [' or '<' => album
157
int start = str.indexOf("id=\"btAsinTitle\"");
159
start = str.indexOf(">", start);
158
int start = str.indexOf(QLatin1String("id=\"btAsinTitle\""));
159
if (start >= 0 && standardTags) {
160
start = str.indexOf(QLatin1Char('>'), start);
160
161
if (start >= 0) {
161
end = str.indexOf("<", start);
162
end = str.indexOf(QLatin1Char('<'), start);
162
163
if (end > start) {
163
int bracketPos = str.indexOf(" [", start);
164
int bracketPos = str.indexOf(QLatin1String(" ["), start);
164
165
if (bracketPos >= 0 && bracketPos < end) {
165
166
end = bracketPos;
168
169
replaceHtmlEntities(str.mid(start + 1, end - start - 1)));
170
171
// next '<a href=', text after '>' until '<' => artist
171
start = str.indexOf("<a href=", end);
172
start = str.indexOf(QLatin1String("<a href="), end);
172
173
if (start >= 0) {
173
start = str.indexOf(">", start);
174
start = str.indexOf(QLatin1Char('>'), start);
174
175
if (start >= 0) {
175
end = str.indexOf("<", start);
176
end = str.indexOf(QLatin1Char('<'), start);
176
177
if (end > start) {
177
178
framesHdr.setArtist(
178
179
replaceHtmlEntities(str.mid(start + 1, end - start - 1)));
186
187
// search for >Product Details<, >Original Release Date:<, >Label:<
187
188
const bool additionalTags = getAdditionalTags();
188
189
QString albumArtist;
189
start = str.indexOf(">Product Details<");
190
start = str.indexOf(QLatin1String(">Product Details<"));
190
191
if (start >= 0) {
191
int detailStart = str.indexOf(">Original Release Date:<", start);
192
int detailStart = str.indexOf(QLatin1String(">Original Release Date:<"), start);
192
193
if (detailStart < 0) {
193
detailStart = str.indexOf(">Audio CD<", start);
194
detailStart = str.indexOf(QLatin1String(">Audio CD<"), start);
195
if (detailStart >= 0) {
196
int detailEnd = str.indexOf("\n", detailStart + 10);
196
if (detailStart >= 0 && standardTags) {
197
int detailEnd = str.indexOf(QLatin1Char('\n'), detailStart + 10);
197
198
if (detailEnd > detailStart + 10) {
198
QRegExp yearRe("(\\d{4})");
199
QRegExp yearRe(QLatin1String("(\\d{4})"));
199
200
if (yearRe.indexIn(
200
201
str.mid(detailStart + 10, detailEnd - detailStart - 11)) >= 0) {
201
202
framesHdr.setYear(yearRe.cap(1).toInt());
205
206
if (additionalTags) {
206
detailStart = str.indexOf(">Label:<", start);
207
detailStart = str.indexOf(QLatin1String(">Label:<"), start);
207
208
if (detailStart > 0) {
208
int detailEnd = str.indexOf("\n", detailStart + 8);
209
int detailEnd = str.indexOf(QLatin1Char('\n'), detailStart + 8);
209
210
if (detailEnd > detailStart + 8) {
210
QRegExp labelRe(">\\s*([^<]+)<");
211
QRegExp labelRe(QLatin1String(">\\s*([^<]+)<"));
211
212
if (labelRe.indexIn(
212
213
str.mid(detailStart + 8, detailEnd - detailStart - 9)) >= 0) {
213
214
framesHdr.setValue(Frame::FT_Publisher, removeHtml(labelRe.cap(1)));
217
detailStart = str.indexOf(">Performer:<", start);
218
detailStart = str.indexOf(QLatin1String(">Performer:<"), start);
218
219
if (detailStart > 0) {
219
int detailEnd = str.indexOf("</li>", detailStart + 12);
220
int detailEnd = str.indexOf(QLatin1String("</li>"), detailStart + 12);
220
221
if (detailEnd > detailStart + 12) {
221
222
framesHdr.setValue(
222
223
Frame::FT_Performer,
223
224
removeHtml(str.mid(detailStart + 11, detailEnd - detailStart - 11)));
226
detailStart = str.indexOf(">Orchestra:<", start);
227
detailStart = str.indexOf(QLatin1String(">Orchestra:<"), start);
227
228
if (detailStart > 0) {
228
int detailEnd = str.indexOf("</li>", detailStart + 12);
229
int detailEnd = str.indexOf(QLatin1String("</li>"), detailStart + 12);
229
230
if (detailEnd > detailStart + 12) {
231
232
removeHtml(str.mid(detailStart + 11, detailEnd - detailStart - 11));
234
detailStart = str.indexOf(">Conductor:<", start);
235
detailStart = str.indexOf(QLatin1String(">Conductor:<"), start);
235
236
if (detailStart > 0) {
236
int detailEnd = str.indexOf("</li>", detailStart + 12);
237
int detailEnd = str.indexOf(QLatin1String("</li>"), detailStart + 12);
237
238
if (detailEnd > detailStart + 12) {
238
239
framesHdr.setValue(
239
240
Frame::FT_Conductor,
240
241
removeHtml(str.mid(detailStart + 11, detailEnd - detailStart - 11)));
243
detailStart = str.indexOf(">Composer:<", start);
244
detailStart = str.indexOf(QLatin1String(">Composer:<"), start);
244
245
if (detailStart > 0) {
245
int detailEnd = str.indexOf("</li>", detailStart + 11);
246
int detailEnd = str.indexOf(QLatin1String("</li>"), detailStart + 11);
246
247
if (detailEnd > detailStart + 11) {
247
248
framesHdr.setValue(
248
249
Frame::FT_Composer,
255
256
ImportTrackDataVector trackDataVector(m_trackDataModel->getTrackData());
257
trackDataVector.setCoverArtUrl(QString());
256
258
if (getCoverArt()) {
257
259
// <input type="hidden" id="ASIN" name="ASIN" value="B0025AY48W" />
258
start = str.indexOf("id=\"ASIN\"");
260
start = str.indexOf(QLatin1String("id=\"ASIN\""));
260
start = str.indexOf("value=\"", start);
262
start = str.indexOf(QLatin1String("value=\""), start);
262
end = str.indexOf("\"", start + 7);
264
end = str.indexOf(QLatin1Char('"'), start + 7);
263
265
if (end > start) {
264
266
trackDataVector.setCoverArtUrl(
265
QString("http://www.amazon.com/dp/") +
267
QLatin1String("http://www.amazon.com/dp/") +
266
268
str.mid(start + 7, end - start - 7));
272
274
bool hasTitleCol = false;
273
bool hasArtist = str.indexOf("<td>Song Title</td><td>Artist</td>") != -1;
275
bool hasArtist = str.indexOf(QLatin1String("<td>Song Title</td><td>Artist</td>")) != -1;
274
276
// search 'class="titleCol"', next '<a href=', text after '>' until '<'
276
278
// if not found: alternatively look for 'class="listRow'
277
start = str.indexOf("class=\"titleCol\"");
279
start = str.indexOf(QLatin1String("class=\"titleCol\""));
278
280
if (start >= 0) {
279
281
hasTitleCol = true;
281
start = str.indexOf("class=\"listRow");
283
start = str.indexOf(QLatin1String("class=\"listRow"));
283
285
if (start >= 0) {
284
QRegExp durationRe("(\\d+):(\\d+)");
285
QRegExp nrTitleRe("\\s*\\d+\\.\\s+(.*\\S)");
286
QRegExp durationRe(QLatin1String("(\\d+):(\\d+)"));
287
QRegExp nrTitleRe(QLatin1String("\\s*\\d+\\.\\s+(.*\\S)"));
286
288
FrameCollection frames(framesHdr);
287
289
ImportTrackDataVector::iterator it = trackDataVector.begin();
288
290
bool atTrackDataListEnd = (it == trackDataVector.end());
293
295
int duration = 0;
294
296
if (hasTitleCol) {
295
end = str.indexOf("\n", start);
297
end = str.indexOf(QLatin1Char('\n'), start);
296
298
if (end > start) {
297
299
QString line = str.mid(start, end - start);
298
int titleStart = line.indexOf("<a href=");
300
int titleStart = line.indexOf(QLatin1String("<a href="));
299
301
if (titleStart >= 0) {
300
titleStart = line.indexOf(">", titleStart);
302
titleStart = line.indexOf(QLatin1Char('>'), titleStart);
301
303
if (titleStart >= 0) {
302
int titleEnd = line.indexOf("<", titleStart);
304
int titleEnd = line.indexOf(QLatin1Char('<'), titleStart);
303
305
if (titleEnd > titleStart) {
304
306
title = line.mid(titleStart + 1, titleEnd - titleStart - 1);
305
307
// if there was an Artist title,
306
308
// search for artist in a second titleCol
308
310
int artistStart =
309
line.indexOf("class=\"titleCol\"", titleEnd);
311
line.indexOf(QLatin1String("class=\"titleCol\""), titleEnd);
310
312
if (artistStart >= 0) {
311
artistStart = line.indexOf("<a href=", artistStart);
313
artistStart = line.indexOf(QLatin1String("<a href="), artistStart);
312
314
if (artistStart >= 0) {
313
artistStart = line.indexOf(">", artistStart);
315
artistStart = line.indexOf(QLatin1Char('>'), artistStart);
314
316
if (artistStart >= 0) {
315
int artistEnd = line.indexOf("<", artistStart);
317
int artistEnd = line.indexOf(QLatin1Char('<'), artistStart);
316
318
if (artistEnd > artistStart) {
317
319
artist = line.mid(
318
320
artistStart + 1, artistEnd - artistStart - 1);
327
329
// search for next 'class="', if it is 'class="runtimeCol"',
328
330
// text after '>' until '<' => duration
329
331
int runtimeStart =
330
line.indexOf("class=\"runtimeCol\"", titleEnd);
332
line.indexOf(QLatin1String("class=\"runtimeCol\""), titleEnd);
331
333
if (runtimeStart >= 0) {
332
runtimeStart = line.indexOf(">", runtimeStart + 18);
334
runtimeStart = line.indexOf(QLatin1Char('>'), runtimeStart + 18);
333
335
if (runtimeStart >= 0) {
334
int runtimeEnd = line.indexOf("<", runtimeStart);
336
int runtimeEnd = line.indexOf(QLatin1Char('<'), runtimeStart);
335
337
if (runtimeEnd > runtimeStart) {
336
338
if (durationRe.indexIn(
337
339
line.mid(runtimeStart + 1,
353
355
// 'class="listRow' found
354
start = str.indexOf("<td>", start);
356
start = str.indexOf(QLatin1String("<td>"), start);
355
357
if (start >= 0) {
356
end = str.indexOf("</td>", start);
358
end = str.indexOf(QLatin1String("</td>"), start);
357
359
if (end > start &&
358
360
nrTitleRe.indexIn(str.mid(start + 4, end - start - 4)) >= 0) {
359
361
title = nrTitleRe.cap(1);
360
start = str.indexOf("class=\"listRow", end);
362
start = str.indexOf(QLatin1String("class=\"listRow"), end);
366
368
if (!title.isEmpty()) {
367
frames.setTitle(replaceHtmlEntities(title));
368
if (!artist.isEmpty()) {
369
frames.setArtist(replaceHtmlEntities(artist));
370
frames.setTitle(replaceHtmlEntities(title));
371
if (!artist.isEmpty()) {
372
frames.setArtist(replaceHtmlEntities(artist));
374
frames.setTrack(trackNr);
371
376
if (!albumArtist.isEmpty() && additionalTags) {
372
377
frames.setValue(Frame::FT_AlbumArtist, albumArtist);
374
frames.setTrack(trackNr);
375
379
if (atTrackDataListEnd) {
376
380
ImportTrackData trackData;
377
381
trackData.setFrameCollection(frames);
439
443
* http://www.amazon.com/gp/search/ref=sr_adv_m_pop/?search-alias=popular&field-artist=amon+amarth&field-title=the+avenger
441
445
sendRequest(cfg->m_server,
442
QString("/gp/search/ref=sr_adv_m_pop/"
446
QLatin1String("/gp/search/ref=sr_adv_m_pop/"
443
447
"?search-alias=popular&field-artist=") +
444
encodeUrlQuery(artist) + "&field-title=" + encodeUrlQuery(album));
448
encodeUrlQuery(artist) + QLatin1String("&field-title=") + encodeUrlQuery(album));