-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.cpp
704 lines (638 loc) · 27 KB
/
main.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
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
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
/*
* This file is part of Neposync program.
* Copyright (C) 2010 Eric Pignet <eric at erixpage dot com>
*
* 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
*/
#include <nepomuk/global.h>
#include <nepomuk/resource.h>
#include <nepomuk/resourcemanager.h>
#include <nepomuk/tag.h>
#include <nepomuk/variant.h>
#include <Soprano/Vocabulary/NAO>
#include <iostream>
#include <libkexiv2/kexiv2.h>
#include <QtCore/QDirIterator>
#include "AmarokCollection.h"
#include "ID3Utilities.h"
void showUsage()
{
std::cout << "Common usage:" << std::endl;
std::cout << " neposync -nf [OPTIONS..] [DIRECTORY]" << std::endl;
std::cout << " neposync -fn [OPTIONS..] [DIRECTORY]" << std::endl;
std::cout << "Actions (nepomuk):" << std::endl;
std::cout << " -nf, --nepomuk-to-files Read tags/ratings from Nepomuk and store them in files metadata" << std::endl;
std::cout << " -fn, --files-to-nepomuk Read tags/ratings from files metadata and store them in Nepomuk" << std::endl;
std::cout << " -dn, --display-nepomuk Display all Nepomuk tags/ratings" << std::endl;
std::cout << " -cn, --clear-nepomuk Clear all Nepomuk tags/ratings" << std::endl;
std::cout << "Actions (amarok):" << std::endl;
std::cout << " -af, --amarok-to-files Read ratings from Amarok collection and store them in files metadata" << std::endl;
std::cout << " -fa, --files-to-amarok Read ratings from files metadata and store them in Amarok collection" << std::endl;
std::cout << " -da, --display-amarok Display all Amarok ratings" << std::endl;
std::cout << " -qa, --query-amarok QUERY Execute Mysql query QUERY in Amarok collection" << std::endl;
std::cout << "Options:" << std::endl;
std::cout << " -r --recursive Recurse into sub-directories" << std::endl;
std::cout << " -f --force Copy tags/ratings even if empty on source side" << std::endl;
std::cout << " -V --verbose Display all nepomuk output (depending on KDebug settings)" << std::endl;
std::cout << " -h --help Display this usage information" << std::endl;
std::cout << " --version Display version and copyright information" << std::endl;
std::cout << "DIRECTORY is optional, if absent the current directory is synchronized" << std::endl;
std::cout << std::endl;
std::cout << "Remarks: neposync uses IPTC 'keyword' metadata to read/store tags in image files (as Digikam)" << std::endl;
std::cout << " neposync uses XMP 'Rating' metadata to read/store ratings in image files (as Digikam)" << std::endl;
std::cout << " neposync uses ID3v2 'Popularimeter/POPM' metadata to read/store ratings in MP3 files" << std::endl;
}
void showVersion()
{
std::cout << "Neposync 0.5" << std::endl;
std::cout << "Copyright © 2010 Eric Pignet" << std::endl;
std::cout << "Licence GPLv2+" << std::endl;
}
void displayFileName(QString iFileName, bool isNewFile = false, bool isVerbose = false)
{
static bool fileDisplayed;
if (isNewFile)
{
fileDisplayed = false;
}
if ( (isNewFile && isVerbose)
|| (!isNewFile && !fileDisplayed)
)
{
std::cout << "File: " << QString(iFileName.toLocal8Bit()).toStdString() << std::endl;
fileDisplayed = true;
}
}
int main(int argc, char *argv[])
{
bool isNepomukToFiles = false;
bool isFilesToNepomuk = false;
bool isDisplayNepomuk = false;
bool isClearNepomuk = false;
bool isAmarokToFiles = false;
bool isFilesToAmarok = false;
bool isDisplayAmarok = false;
bool isQueryAmarok = false;
QString amarokQuery;
bool forceCopy = false;
bool recurseDirectories = false;
bool isVerbose = false;
int nbActions = 0;
QString workingDirectory;
//------------------
// Parse arguments
for (int i=1; i<argc; ++i)
{
if (!strcmp(argv[i], "-nf") || !strcmp(argv[i],"--nepomuk-to-files"))
{
isNepomukToFiles = true;
nbActions ++;
}
else if (!strcmp(argv[i], "-fn") || !strcmp(argv[i],"--files-to-nepomuk"))
{
isFilesToNepomuk = true;
nbActions ++;
}
else if (!strcmp(argv[i], "-dn") || !strcmp(argv[i],"--display-nepomuk"))
{
isDisplayNepomuk = true;
nbActions ++;
}
else if (!strcmp(argv[i], "-cn") || !strcmp(argv[i],"--clear-nepomuk"))
{
isClearNepomuk = true;
nbActions ++;
}
else if (!strcmp(argv[i], "-af") || !strcmp(argv[i],"--amarok-to-files"))
{
isAmarokToFiles = true;
nbActions ++;
}
else if (!strcmp(argv[i], "-fa") || !strcmp(argv[i],"--files-to-amarok"))
{
isFilesToAmarok = true;
nbActions ++;
}
else if (!strcmp(argv[i], "-da") || !strcmp(argv[i],"--display-amarok"))
{
isDisplayAmarok = true;
nbActions ++;
}
else if (!strcmp(argv[i], "-qa") || !strcmp(argv[i],"--query-amarok"))
{
isQueryAmarok = true;
nbActions ++;
i++;
if ((i == argc) || (argv[i][0] == '-'))
{
std::cout << "A Mysql query must follow --query-amarok action." << std::endl;
return 1;
}
else
{
amarokQuery = argv[i];
}
}
else if (!strcmp(argv[i], "-r") || !strcmp(argv[i], "--recursive"))
{
recurseDirectories = true;
}
else if (!strcmp(argv[i], "-f") || !strcmp(argv[i], "--force"))
{
forceCopy = true;
}
else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
{
showUsage();
return 0;
}
else if (!strcmp(argv[i], "-V") || !strcmp(argv[i], "--verbose"))
{
isVerbose = true;
}
else if (!strcmp(argv[i], "--version"))
{
showVersion();
return 0;
}
else if (argv[i][0] != '-')
{
workingDirectory = argv[i];
}
}
if (nbActions == 0)
{
showUsage();
return 0;
}
else if (nbActions > 1)
{
std::cout << "Only one action must be specified." << std::endl;
return 1;
}
//------------------
// Initializations
if (!isVerbose)
{
// Nepomuk and exiv2 libraries are *very* verbose, they pollute the program's output.
// I didn't manage to filter them efficiently, even using KDebug settings.
// So in "not verbose" mode, we throw all stderr to /dev/null.
freopen ("/dev/null","w",stderr);
}
KExiv2Iface::KExiv2::initializeExiv2();
Nepomuk::ResourceManager::instance()->init();
if (workingDirectory.isNull())
{
// If directory not specified, current directory is used.
// But current directory found by Qt is not reliable: it will always return the absolute path on filesystem.
// If files were tagged in Nepomuk via an alternative path (with symlinks), sync will not work.
// Only pwd command can return the simplified path, if any.
if (getenv("PWD") != NULL)
{
workingDirectory = QString::fromLocal8Bit(getenv("PWD"));
}
else
{
// If PWD not available on the platform, fallback to portable Qt method.
workingDirectory = QDir::currentPath();
}
}
else
{
// Remove final / character if present
if (workingDirectory[workingDirectory.length()-1] == '/')
{
workingDirectory.truncate(workingDirectory.length()-1);
}
}
if (isVerbose)
std::cout << "Path used: " << std::string(workingDirectory.toLocal8Bit()) << std::endl;
//------------------
// Nepomuk to files
if (isNepomukToFiles)
{
QDirIterator it(workingDirectory, QDir::Files | QDir::NoDotAndDotDot, (recurseDirectories?QDirIterator::Subdirectories:QDirIterator::NoIteratorFlags));
while (it.hasNext())
{
QString currentFileName(it.next());
if ( !it.fileInfo().suffix().compare("jpg", Qt::CaseInsensitive)
|| !it.fileInfo().suffix().compare("jpeg", Qt::CaseInsensitive))
{
displayFileName(currentFileName, true, isVerbose);
Nepomuk::Resource aFile(it.filePath());
// Copy of tags
QList<Nepomuk::Variant> vl = aFile.property( Soprano::Vocabulary::NAO::hasTag() ).toVariantList();
if (!vl.isEmpty() || forceCopy)
{
KExiv2Iface::KExiv2 myExifData(currentFileName);
QStringList oldKeywords = myExifData.getIptcKeywords();
QStringList newKeywords;
foreach (Nepomuk::Variant vv, vl)
{
Nepomuk::Tag tag(vv.toString());
newKeywords.append(tag.label());
}
QStringList oldKeywordsSorted(oldKeywords);
QStringList newKeywordsSorted(newKeywords);
oldKeywordsSorted.sort();
newKeywordsSorted.sort();
if (oldKeywordsSorted != newKeywordsSorted)
{
displayFileName(currentFileName);
std::cout << " Needs to replace IPTC keywords to: ";
foreach (QString keyword, newKeywords) std::cout << keyword.toStdString() << " ";
std::cout << std::endl;
myExifData.setIptcKeywords(oldKeywords, newKeywordsSorted);
myExifData.applyChanges();
}
}
// Copy of rating
if (aFile.hasProperty(aFile.ratingUri()))
{
KExiv2Iface::KExiv2 myXMPData(currentFileName);
QString rating = myXMPData.getXmpTagString("Xmp.xmp.Rating");
if (rating.isNull() || rating.toUInt() != aFile.rating())
{
displayFileName(currentFileName);
std::cout << " Needs to copy rating: " << QString::number(aFile.rating()).toStdString() << std::endl;
myXMPData.setXmpTagString("Xmp.xmp.Rating",QString::number(aFile.rating()), false);
myXMPData.applyChanges();
}
}
else if (forceCopy)
{
KExiv2Iface::KExiv2 myXMPData(currentFileName);
QString rating = myXMPData.getXmpTagString("Xmp.xmp.Rating");
if (!rating.isNull())
{
displayFileName(currentFileName);
std::cout << " Needs to clear rating" << std::endl;
myXMPData.setXmpTagString("Xmp.xmp.Rating",NULL, false);
myXMPData.applyChanges();
}
}
}
else if (!it.fileInfo().suffix().compare("mp3", Qt::CaseInsensitive))
{
displayFileName(currentFileName, true, isVerbose);
Nepomuk::Resource aFile(it.filePath());
if (aFile.hasProperty(aFile.ratingUri()))
{
int id3rating = 0;
ID3Utilities::getID3Rating(currentFileName, id3rating, isVerbose);
if ((unsigned int)id3rating != aFile.rating())
{
displayFileName(currentFileName);
std::cout << " Needs to copy rating: " << aFile.rating() << "/10" << std::endl;
ID3Utilities::setID3Rating(currentFileName, aFile.rating(), isVerbose);
}
}
else if (forceCopy)
{
int id3rating = 0;
ID3Utilities::getID3Rating(currentFileName, id3rating, isVerbose);
if (id3rating > 0)
{
displayFileName(currentFileName);
std::cout << " Needs to clear rating" << std::endl;
ID3Utilities::setID3Rating(currentFileName, 0, isVerbose);
}
}
}
}
}
//------------------
// Files to Nepomuk
if (isFilesToNepomuk)
{
QDirIterator it(workingDirectory, QDir::Files | QDir::NoDotAndDotDot, (recurseDirectories?QDirIterator::Subdirectories:QDirIterator::NoIteratorFlags));
while (it.hasNext()) {
QString currentFileName(it.next());
if ( !it.fileInfo().suffix().compare("jpg", Qt::CaseInsensitive)
|| !it.fileInfo().suffix().compare("jpeg", Qt::CaseInsensitive))
{
KExiv2Iface::KExiv2 myExifData(currentFileName);
displayFileName(currentFileName, true, isVerbose);
// Copy of tags
QStringList keywords = myExifData.getIptcKeywords();
if (!keywords.isEmpty() || forceCopy)
{
Nepomuk::Resource aFile(it.fileInfo().absoluteFilePath());
QList<Nepomuk::Tag> fileTags = aFile.tags();
// Remove unneeded tags, if any (more performant than removing everything then recreating)
QList<Nepomuk::Variant> tagsToRemove;
foreach (Nepomuk::Tag fileTag, fileTags)
{
if (!keywords.contains(fileTag.label()))
{
displayFileName(currentFileName);
std::cout << " Needs to remove tag: " << fileTag.label().toStdString() << std::endl;
tagsToRemove.append(fileTag.resourceUri());
}
}
if (!tagsToRemove.isEmpty())
{
Nepomuk::Variant tagsToRemoveVar(tagsToRemove);
aFile.removeProperty(Soprano::Vocabulary::NAO::hasTag(), tagsToRemoveVar);
}
// Add missing tags
foreach (const QString& keyword, keywords)
{
if (!fileTags.contains(keyword))
{
displayFileName(currentFileName);
std::cout << " Needs to add tag: " << QString(keyword.toLocal8Bit()).toStdString() << std::endl;
Nepomuk::Tag tag(keyword);
tag.setLabel(keyword);
aFile.addTag(tag);
}
}
}
// Copy of rating
QString rating = myExifData.getXmpTagString("Xmp.xmp.Rating");
if (!rating.isNull())
{
Nepomuk::Resource aFile(it.fileInfo().absoluteFilePath());
if (!aFile.hasProperty(aFile.ratingUri()) || rating.toUInt() != aFile.rating())
{
displayFileName(currentFileName);
std::cout << " Needs to replace rating: " << rating.toStdString() << std::endl;
aFile.setRating(rating.toUInt());
}
}
else if (forceCopy)
{
Nepomuk::Resource aFile(it.fileInfo().absoluteFilePath());
if (aFile.hasProperty(aFile.ratingUri()))
{
displayFileName(currentFileName);
std::cout << " Needs to clear rating" << std::endl;
aFile.removeProperty(aFile.ratingUri());
}
}
}
else if (!it.fileInfo().suffix().compare("mp3", Qt::CaseInsensitive))
{
displayFileName(currentFileName, true, isVerbose);
int id3rating = 0;
ID3Utilities::getID3Rating(currentFileName, id3rating, isVerbose);
if (id3rating > 0)
{
Nepomuk::Resource aFile(it.fileInfo().absoluteFilePath());
if (!aFile.hasProperty(aFile.ratingUri()) || ((unsigned int)id3rating != aFile.rating()))
{
displayFileName(currentFileName);
std::cout << " Needs to replace rating: " << id3rating << std::endl;
aFile.setRating((unsigned int)id3rating);
}
}
else if (forceCopy)
{
Nepomuk::Resource aFile(it.fileInfo().absoluteFilePath());
if (aFile.hasProperty(aFile.ratingUri()))
{
displayFileName(currentFileName);
std::cout << " Needs to clear rating" << std::endl;
aFile.removeProperty(aFile.ratingUri());
}
}
}
}
}
//------------------
// Display Nepomuk
if (isDisplayNepomuk)
{
if (forceCopy)
{
std::cout << "In display-nepomuk mode, --force-copy option has no effect." << std::endl;
}
QDirIterator it(workingDirectory, QDir::Files | QDir::NoDotAndDotDot, (recurseDirectories?QDirIterator::Subdirectories:QDirIterator::NoIteratorFlags));
while (it.hasNext())
{
QString currentFileName(it.next());
if ( !it.fileInfo().suffix().compare("jpg", Qt::CaseInsensitive)
|| !it.fileInfo().suffix().compare("jpeg", Qt::CaseInsensitive))
{
displayFileName(currentFileName, true, isVerbose);
Nepomuk::Resource aFile(it.filePath());
// Display tags
QList<Nepomuk::Tag> fileTags = aFile.tags();
if (!fileTags.isEmpty())
{
displayFileName(currentFileName);
std::cout << " Tags:";
foreach (Nepomuk::Tag fileTag, fileTags)
{
std::cout << " " << QString(fileTag.label().toLocal8Bit()).toStdString();
}
std::cout << std::endl;
}
// Display rating
if (aFile.hasProperty(aFile.ratingUri()))
{
displayFileName(currentFileName);
std::cout << " Rating: " << aFile.rating() << std::endl;
}
}
else if (!it.fileInfo().suffix().compare("mp3", Qt::CaseInsensitive))
{
displayFileName(currentFileName, true, isVerbose);
Nepomuk::Resource aFile(it.filePath());
if (aFile.hasProperty(aFile.ratingUri()))
{
displayFileName(currentFileName);
std::cout << " Rating: " << aFile.rating() << std::endl;
}
}
}
}
//------------------
// Clear Nepomuk
if (isClearNepomuk)
{
if (forceCopy)
{
std::cout << "In clear-nepomuk mode, --force-copy option has no effect." << std::endl;
}
QDirIterator it(workingDirectory, QDir::Files | QDir::NoDotAndDotDot, (recurseDirectories?QDirIterator::Subdirectories:QDirIterator::NoIteratorFlags));
while (it.hasNext())
{
QString currentFileName(it.next());
if ( !it.fileInfo().suffix().compare("jpg", Qt::CaseInsensitive)
|| !it.fileInfo().suffix().compare("jpeg", Qt::CaseInsensitive)
|| !it.fileInfo().suffix().compare("mp3", Qt::CaseInsensitive))
{
displayFileName(currentFileName, true, isVerbose);
Nepomuk::Resource aFile(it.filePath());
// Clear tags
QList<Nepomuk::Tag> fileTags = aFile.tags();
if (!fileTags.isEmpty())
{
displayFileName(currentFileName);
std::cout << " Remove tags:";
foreach (Nepomuk::Tag fileTag, fileTags)
{
std::cout << " " << fileTag.label().toStdString();
aFile.removeProperty(Soprano::Vocabulary::NAO::hasTag(), fileTag.resourceUri());
}
std::cout << std::endl;
}
// Clear rating
if (aFile.hasProperty(aFile.ratingUri()))
{
displayFileName(currentFileName);
std::cout << " Clear rating" << std::endl;
aFile.removeProperty(aFile.ratingUri());
}
}
}
}
// Amarok initialization
if (isAmarokToFiles || isFilesToAmarok || isDisplayAmarok || isQueryAmarok)
{
AmarokCollection amarokDb(isVerbose);
if (!amarokDb.connect())
{
return 1;
}
//------------------
// Amarok to Files
if (isAmarokToFiles)
{
QDirIterator it(workingDirectory, QDir::Files | QDir::NoDotAndDotDot, (recurseDirectories?QDirIterator::Subdirectories:QDirIterator::NoIteratorFlags));
while (it.hasNext())
{
QString currentFileName(it.next());
if (!it.fileInfo().suffix().compare("mp3", Qt::CaseInsensitive))
{
displayFileName(currentFileName, true, isVerbose);
bool urlPresent = false;
int amarokRating = 0;
amarokDb.getRating(currentFileName, urlPresent, amarokRating);
if (amarokRating > 0)
{
int id3rating = 0;
ID3Utilities::getID3Rating(currentFileName, id3rating, isVerbose);
if (id3rating != amarokRating)
{
displayFileName(currentFileName);
std::cout << " Needs to copy rating: " << amarokRating << "/10" << std::endl;
ID3Utilities::setID3Rating(currentFileName, amarokRating, isVerbose);
}
}
else if (forceCopy)
{
int id3rating = 0;
ID3Utilities::getID3Rating(currentFileName, id3rating, isVerbose);
if (id3rating != 0)
{
displayFileName(currentFileName);
std::cout << " Needs to clear rating" << std::endl;
ID3Utilities::setID3Rating(currentFileName, 0, isVerbose);
}
}
}
}
}
//------------------
// Files to Amarok
if (isFilesToAmarok)
{
QDirIterator it(workingDirectory, QDir::Files | QDir::NoDotAndDotDot, (recurseDirectories?QDirIterator::Subdirectories:QDirIterator::NoIteratorFlags));
while (it.hasNext())
{
QString currentFileName(it.next());
if (!it.fileInfo().suffix().compare("mp3", Qt::CaseInsensitive))
{
displayFileName(currentFileName, true, isVerbose);
int id3rating = 0;
ID3Utilities::getID3Rating(currentFileName, id3rating, isVerbose);
if (id3rating > 0)
{
bool urlPresent = false;
int amarokRating = 0;
amarokDb.getRating(currentFileName, urlPresent, amarokRating);
if (!urlPresent)
{
displayFileName(currentFileName);
std::cout << " File has rating " << id3rating << " but is not in Amarok collection. Do nothing" << std::endl;
}
else
{
if (id3rating != amarokRating)
{
displayFileName(currentFileName);
std::cout << " Needs to copy rating: " << id3rating << std::endl;
amarokDb.setRating(currentFileName, id3rating);
}
}
}
else if (forceCopy)
{
bool urlPresent = false;
int amarokRating = 0;
amarokDb.getRating(currentFileName, urlPresent, amarokRating);
if (amarokRating != 0)
{
displayFileName(currentFileName);
std::cout << " Needs to clear rating" << std::endl;
amarokDb.setRating(currentFileName, id3rating);
}
}
}
}
}
//------------------
// Display Amarok
if (isDisplayAmarok)
{
QMap<QString, int> ratings;
amarokDb.getAllRating(workingDirectory, ratings);
QMap<QString, int>::const_iterator i = ratings.constBegin();
while (i != ratings.constEnd())
{
if (recurseDirectories ||
(i.key().count("/") == workingDirectory.count("/")+1))
{
std::cout << QString(i.key().toLocal8Bit()).toStdString() << ": " << i.value() << std::endl;
}
++i;
}
}
//------------------
// Query Amarok
if (isQueryAmarok)
{
if (isVerbose)
{
std::cout << "Query: " << amarokQuery.toStdString() << std::endl;
}
QList<QString> rows;
amarokDb.query(amarokQuery, rows);
QList<QString>::const_iterator row = rows.constBegin();
while (row != rows.constEnd())
{
std::cout << (*row).toStdString() << std::endl;
++row;
}
}
}
if (!isVerbose)
{
fclose(stderr);
}
return 0;
}