-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathprocessingthread.cpp
More file actions
758 lines (719 loc) · 25.9 KB
/
processingthread.cpp
File metadata and controls
758 lines (719 loc) · 25.9 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
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
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
#include "processingthread.h"
#include "ziphandler.h"
#include <QTemporaryDir>
#include <QProcess>
#include <QFileInfo>
#include <QDebug>
#include <QMutex>
ProcessingThread::ProcessingThread(ProcessingType type, QObject *parent) :
QThread(parent)
{
m_terminate = false;
settings = new Settings(this);
m_force = settings->forceReprocessing();
mp3gainPath = settings->mp3GainPath();
processingType = type;
}
void ProcessingThread::setFiles(QStringList *files)
{
m_files = files;
}
void ProcessingThread::processFileRg(QString fileName)
{
if (fileName.endsWith("mp4", Qt::CaseInsensitive))
{
qWarning() << "Processing - mp4 file: " << fileName;
QString program = mp3gainPath;
QStringList arguments;
arguments << "-c";
arguments << "-r";
arguments << "-T";
arguments << "-s" << "r";
arguments << fileName;
emit stateChanged("Processing - Doing ReplayGain analasis and adjustment");
QProcess process;
process.start(program, arguments);
process.waitForFinished();
int exitCode = process.exitCode();
if (exitCode != 0)
{
qWarning() << "Error occurred while running aacgain, aborting";
return;
}
emit stateChanged("Idle");
return;
}
qWarning() << "Processing - File: " << fileName;
QFileInfo info(fileName);
QString baseName = info.completeBaseName();
emit stateChanged("Extracting file");
QTemporaryDir tmpDir;
ZipHandler zipper;
zipper.setZipFile(fileName);
if ((zipper.containsRGMarkerFile()) && (!m_force))
{
qWarning() << "File contains marker, already processed. Skipping";
emit stateChanged("Skipping file, already processed");
zipper.close();
return;
}
qWarning() << "Processing - Extracting mp3 file";
if (!zipper.extractAudio(QDir(tmpDir.path())))
{
qWarning() << "Bad file contents - error extracting mp3";
emit stateChanged("Error extracting file");
zipper.close();
return;
}
QFile::copy(tmpDir.path() + QDir::separator() + "tmp.mp3", "/storage/KaraokeRGTest/PreRG.mp3");
qWarning() << "Processing - Extracting cdg file";
if (!zipper.extractCdg(QDir(tmpDir.path())))
{
qWarning() << "Processing - Bad file contents - error extracting cdg";
emit stateChanged("Error extracting file");
zipper.close();
return;
}
emit stateChanged("Processing - Doing ReplayGain analasis and adjustment");
zipper.close();
QString program = mp3gainPath;
QStringList arguments;
arguments << "-c";
arguments << "-r";
arguments << "-T";
arguments << "-s" << "r";
arguments << tmpDir.path() + QDir::separator() + "tmp.mp3";
QProcess process;
process.start(program, arguments);
process.waitForFinished();
int exitCode = process.exitCode();
QFile::copy(tmpDir.path() + QDir::separator() + "tmp.mp3", "/storage/KaraokeRGTest/PostRG.mp3");
qWarning() << process.readAllStandardOutput();
//qWarning() << process.readAllStandardError();
if (exitCode != 0)
{
qWarning() << "Error occurred while running mp3gain, aborting";
return;
}
qWarning() << "Processing - Creating zip file";
emit stateChanged("Creating zip file");
QFile::rename(tmpDir.path() + QDir::separator() + "tmp.mp3", tmpDir.path() + QDir::separator() + baseName + ".mp3");
QFile::rename(tmpDir.path() + QDir::separator() + "tmp.cdg", tmpDir.path() + QDir::separator() + baseName + ".cdg");
zipper.setReplaceFnsWithZipFn(false);
zipper.setCompressionLevel(settings->zipCompressionLevel());
if (zipper.createZip(tmpDir.path() + QDir::separator() + info.fileName(), tmpDir.path() + QDir::separator() + baseName + ".cdg", tmpDir.path() + QDir::separator() + baseName + ".mp3", true))
{
qWarning () << "Processing - Replacing original file";
emit stateChanged("Replacing original file");
if (QFile(tmpDir.path() + QDir::separator() + info.fileName()).exists())
{
qWarning() << "Doing QFile::rename(" << info.absoluteFilePath() << ", " << info.absoluteFilePath() + ".tmp" << ");";
if (QFile::rename(info.absoluteFilePath(), info.absoluteFilePath() + ".tmp"))
{
if (QFile::copy(tmpDir.path() + QDir::separator() + info.fileName(), info.absoluteFilePath()))
{
qWarning() << "New file copied into place, deleting old one";
if (!QFile::remove(info.absoluteFilePath() + ".tmp"))
{
qWarning() << "Error deleting old file";
}
}
else
{
qWarning() << "Unable to move new file into place, restoring old one";
QFile::rename(info.absoluteFilePath() + ".tmp", info.absoluteFilePath());
}
}
else
{
qWarning() << "Unable to move existing file to tmp file";
return;
}
}
else
{
qWarning() << "Unexpected error, new processed zip file missing!";
}
emit stateChanged("Idle");
qWarning() << "Processing - Complete for file: " << fileName;
}
else
{
qWarning() << "Failed to create new archive, leaving original file in place";
}
}
void ProcessingThread::processFileZipFix(QString fileName)
{
qWarning() << "Processing - File: " << fileName;
emit stateChanged("Checking file");
ZipHandler zipper;
zipper.setZipFile(fileName);
if (!zipper.isValidZipfile())
{
qWarning() << "File doesn't appear to be a valid zip at all! Skipping";
emit stateChanged("Skipping zipfile, appears to be an invalid or bad zip file!");
return;
}
if (!zipper.containsAudioFile())
{
qWarning() << "Zipfile missing audio file. Skipping";
emit stateChanged("Skipping zipfile, missing audio file. May not be a karaoke file at all.");
return;
}
if (!zipper.containsCdgFile())
{
qWarning() << "Zipfile missing cdg file. Skipping";
emit stateChanged("Skipping file, missing audio file. May not be a karaoke file at all.");
return;
}
if (zipper.compressionSupported())
{
qWarning() << "File compression methods are supported. Skipping";
emit stateChanged("Skipping file, already using standard zip compression");
return;
}
else
{
qWarning() << "File using unsupported compression method, converting.";
emit stateChanged("Converting zip file");
zipper.setReplaceFnsWithZipFn(true);
zipper.setCompressionLevel(settings->zipCompressionLevel());
zipper.reZipUnsupported(fileName);
}
}
void ProcessingThread::processFileUnzip(QString fileName)
{
qWarning() << "Processing - File: " << fileName;
emit stateChanged("Checking file");
ZipHandler zipper;
zipper.setZipFile(fileName);
if (!zipper.compressionSupported())
{
qWarning() << "File compression method not supported. Fixing.";
emit stateChanged("File compression method not supported. Fixing before continuing.");
zipper.setReplaceFnsWithZipFn(true);
zipper.setCompressionLevel(settings->zipCompressionLevel());
if (!zipper.reZipUnsupported(fileName))
{
emit stateChanged("Unable to fix unsupported file. Skipping.");
qWarning() << "Unable to fix unsupported file. Skipping";
return;
}
zipper.setZipFile(fileName);
}
if (!zipper.isValidZipfile())
{
qWarning() << "File doesn't appear to be a valid zip at all! Skipping";
emit stateChanged("Skipping zipfile, appears to be an invalid or bad zip file!");
zipper.close();
return;
}
if (!zipper.containsAudioFile())
{
qWarning() << "Zipfile missing audio file. Skipping";
emit stateChanged("Skipping zipfile, missing audio file. May not be a karaoke file at all.");
zipper.close();
return;
}
if (!zipper.containsCdgFile())
{
qWarning() << "Zipfile missing cdg file. Skipping";
emit stateChanged("Skipping file, missing audio file. May not be a karaoke file at all.");
zipper.close();
return;
}
QTemporaryDir tmpDir;
qWarning() << "File appears to be a valid audio+g zipfile, unzipping.";
emit stateChanged("Extracting zip file");
if (!zipper.extractAudio(tmpDir.path()))
{
qWarning() << "Error extracting audio file";
zipper.close();
return;
}
if (!zipper.extractCdg(tmpDir.path()))
{
qWarning() << "Error extracting cdg file";
zipper.close();
return;
}
zipper.close();
QString zipFileBaseName = QFileInfo(fileName).completeBaseName();
QString cdgFileName = zipFileBaseName + ".cdg";
QString audioFileName = zipFileBaseName + zipper.getAudioExt();
QString destCdg = QFileInfo(fileName).absolutePath() + QDir::separator() + cdgFileName;
QString destAud = QFileInfo(fileName).absolutePath() + QDir::separator() + audioFileName;
if (QFile::exists(destCdg) || QFile::exists(destAud))
{
qWarning() << "Found existing cdg or mp3 file in the destination dir, bailing out";
return;
}
if (!QFile::copy(tmpDir.path() + QDir::separator() + "tmp.cdg", destCdg))
{
qWarning() << "Error copying cdg file to destination dir, bailing out";
return;
}
if (!QFile::copy(tmpDir.path() + QDir::separator() + "tmp" + zipper.getAudioExt(), destAud))
{
qWarning() << "Error copying audio file to the destination dir, bailing out";
return;
}
if (!QFile::exists(destCdg) || !QFile::exists(destAud))
{
qWarning() << "Destination cdg or audio file doesn't exist, something went wrong! Bailing out";
return;
}
if (settings->removeAfterUnzip())
{
if (!QFile::remove(fileName))
{
// May be a lagged out file lock on remote samba shares, sleep a bit and try again...
emit stateChanged("Deleting original file failed, sleeping a bit and trying again in case of stale file locks...");
this->msleep(1000);
if (!QFile::remove(fileName))
{
qWarning() << "Unable to remove original zip file. Bailing out.";
emit stateChanged("Delete failed!");
return;
}
else
{
qWarning() << "Process completed successfully!";
emit stateChanged("Done!");
}
}
else
{
qWarning() << "Process completed successfully!";
emit stateChanged("Done!");
}
}
}
void ProcessingThread::processFileZip(QString fileName)
{
ZipHandler zipper;
emit stateChanged("Searching for matching audio file");
if (!QFile::exists(fileName))
{
qWarning() << "CDG file doesn't exist, bailing out";
return;
}
QString audioExt;
QStringList audioExts = zipper.getSupportedAudioExts();
QString path = QFileInfo(fileName).absolutePath();
QString baseName = QFileInfo(fileName).completeBaseName();
QString audioFile;
QString zipFile = path + QDir::separator() + baseName + ".zip";
QString zipBaseName = baseName + ".zip";
for (int i=0; i < audioExts.size(); i++)
{
if (QFile::exists(path + QDir::separator() + baseName + audioExts.at(i)))
{
qWarning() << "Audio file found, continuing.";
audioFile = path + QDir::separator() + baseName + audioExts.at(i);
break;
}
}
if (audioFile == "")
{
qWarning() << "Matching audio file not found, bailing out";
return;
}
emit stateChanged("Creating zip file");
if (QFile::exists(zipFile))
{
qWarning() << "Zip file already exists, bailing out";
return;
}
QTemporaryDir tmpDir;
if (!zipper.createZip(tmpDir.path() + QDir::separator() + zipBaseName, fileName, audioFile))
{
qWarning() << "Error creating temporary zip file, bailing out";
return;
}
if (!QFile::exists(tmpDir.path() + QDir::separator() + zipBaseName))
{
qWarning() << "Temporary zip file doesn't exist, bailing out";
return;
}
emit stateChanged("Copying zip file to final location");
if (!QFile::copy(tmpDir.path() + QDir::separator() + zipBaseName, zipFile))
{
qWarning() << "Error copying zip file to final destination, bailing out";
return;
}
if (settings->removeAfterZip())
{
emit stateChanged("Removing original cdg and audio file");
if (!QFile::remove(fileName))
{
qWarning() << "Error removing cdg file, bailing out";
return;
}
if (!QFile::remove(audioFile))
{
qWarning() << "Error removing audio file, bailing out";
return;
}
}
emit stateChanged("Finished processing");
qWarning() << "Zipfile created successfully";
}
void ProcessingThread::processFileCaseFix(QString fileName)
{
emit stateChanged("Fixing case");
QString sep = " - ";
int sidSection = 0;
QFileInfo fileinfo(fileName);
QString iFN = fileinfo.completeBaseName();
QStringList nocaps;
nocaps << "a";
nocaps << "an";
nocaps << "the";
nocaps << "at";
nocaps << "by";
nocaps << "for";
nocaps << "in";
nocaps << "of";
nocaps << "on";
nocaps << "to";
nocaps << "up";
nocaps << "and";
nocaps << "as";
nocaps << "but";
nocaps << "or";
nocaps << "nor";
QStringList capsafter;
capsafter << "Mc";
capsafter << "O'";
capsafter << "(";
// capsafter << "-";
// capsafter << ".";
QStringList exceptions;
exceptions << "ACDC";
exceptions << "AC-DC";
exceptions << "Rag'n'Bone";
exceptions << "3LW";
exceptions << "XTC";
exceptions << "MC";
exceptions << "DJ";
exceptions << "SZA";
exceptions << "YOLO";
exceptions << "24K";
exceptions << "...Ready";
exceptions << "FourFiveSeconds";
exceptions << "II";
exceptions << "II)";
exceptions << "ZZ";
exceptions << "'N";
exceptions << "KC";
exceptions << "PJ";
exceptions << "'Til";
exceptions << "NIN";
exceptions << "OMC";
// exceptions << "LA";
exceptions << "UB40";
//exceptions << "s";
// fix common naming problems before processing
QString pfFN = iFN;
pfFN.replace(" let s ", " let's ", Qt::CaseInsensitive);
pfFN.replace(" I M ", " I'm ", Qt::CaseInsensitive);
pfFN.replace(" that s ", " that's ", Qt::CaseInsensitive);
pfFN.replace(" don t ", " don't ", Qt::CaseInsensitive);
pfFN.replace(" won t ", " won't ", Qt::CaseInsensitive);
pfFN.replace(" here s ", " here's ", Qt::CaseInsensitive);
pfFN.replace(" ex s ", " ex's ", Qt::CaseInsensitive);
pfFN.replace(" oh s ", " oh's ", Qt::CaseInsensitive);
pfFN.replace(" can t ", " can't ", Qt::CaseInsensitive);
pfFN.replace(" it s ", " it's ", Qt::CaseInsensitive);
pfFN.replace(" hadn t ", " hadn't ", Qt::CaseInsensitive);
pfFN.replace(" we re ", " we're ", Qt::CaseInsensitive);
pfFN.replace(" donesn t ", " donesn't ", Qt::CaseInsensitive);
pfFN.replace(" you s ", " you's ", Qt::CaseInsensitive);
QStringList sections = pfFN.split(" - ");
QString oFN;
for (int s=0; s < sections.size(); s++)
{
QStringList parts = sections.at(s).split(" ", QString::SkipEmptyParts);
QString oPart;
for (int i=0; i < parts.size(); i++)
{
if (s == sidSection)
{
if (s != 0)
oFN += " - ";
oFN += parts.at(i).toUpper();
continue;
}
QString part = parts.at(i);
bool match = false;
for (int e=0; e < exceptions.size(); e++)
{
if (exceptions.at(e).toLower() == part.toLower())
{
if (i != 0)
oPart += " ";
oPart += exceptions.at(e);
match = true;
break;
}
}
if (match)
continue;
part = part.toLower();
if ((nocaps.contains(part)) && (i != 0) && (i != parts.size() - 1))
{
if (!parts.at(i + 1).startsWith("(") && !parts.at(i + 1).startsWith("["))
{
if (i != 0)
oPart += " ";
oPart += part;
continue;
}
}
part.replace(0,1,part.at(0).toUpper());
for (int j=0; j < capsafter.size(); j++)
{
if ((part.startsWith(capsafter.at(j))) && (part.size() > capsafter.at(j).size()))
{
part.replace(capsafter.at(j).size(), 1, part.at(capsafter.at(j).size()).toUpper());
}
}
for (int z=0; z < part.size(); z++)
{
if (z < part.size() - 1)
{
if ((part.at(z) == QString(".")) || (part.at(z) == QString("-")))
{
QString curLetter = part.at(z + 1);
part.replace(z + 1, 1, curLetter.toUpper());
}
}
}
if (i != 0)
oPart += " ";
oPart += part;
}
if (s != 0)
oFN += " - ";
oFN += oPart;
}
if (iFN != oFN)
{
emit stateChanged("Renaming file");
qWarning() << "iFN: " << iFN << "\noFN: " << oFN << "\nRenaming to: " << QString(fileinfo.absolutePath() + QDir::separator() + oFN + "." + fileinfo.suffix());
QFile::rename(fileName, fileName + ".rntmp");
QFile::rename(fileName + ".rntmp", fileinfo.absolutePath() + QDir::separator() + oFN + "." + fileinfo.suffix());
}
}
void ProcessingThread::processFileCdg2Mp4(QString fileName)
{
if (fileName.endsWith(".cdg", Qt::CaseInsensitive))
{
ZipHandler zipper;
emit stateChanged("Searching for matching audio file");
if (!QFile::exists(fileName))
{
qWarning() << "CDG file doesn't exist, bailing out";
return;
}
QString audioExt;
QStringList audioExts = zipper.getSupportedAudioExts();
QString path = QFileInfo(fileName).absolutePath();
QString baseName = QFileInfo(fileName).completeBaseName();
QString audioFile;
for (int i=0; i < audioExts.size(); i++)
{
if (QFile::exists(path + QDir::separator() + baseName + audioExts.at(i)))
{
qWarning() << "Audio file found, continuing.";
audioFile = path + QDir::separator() + baseName + audioExts.at(i);
break;
}
}
if (audioFile == "")
{
qWarning() << "Matching audio file not found, bailing out";
return;
}
QString mp4file = path + QDir::separator() + baseName + ".mp4";
convertMp3g2Mp4(fileName, audioFile, mp4file);
}
else if (fileName.endsWith(".zip", Qt::CaseInsensitive))
{
qWarning() << this->objectName() << " - Processing - File: " << fileName;
emit stateChanged("Checking file");
ZipHandler zipper;
zipper.setZipFile(fileName);
if (!zipper.compressionSupported())
{
qWarning() << this->objectName() << " - File compression method not supported. Fixing.";
emit stateChanged("File compression method not supported. Fixing before continuing.");
zipper.setReplaceFnsWithZipFn(true);
zipper.setCompressionLevel(settings->zipCompressionLevel());
if (!zipper.reZipUnsupported(fileName))
{
emit stateChanged("Unable to fix unsupported file. Skipping.");
qWarning() << this->objectName() << " - Unable to fix unsupported file. Skipping";
return;
}
zipper.setZipFile(fileName);
}
if (!zipper.isValidZipfile())
{
qWarning() << this->objectName() << " - File doesn't appear to be a valid zip at all! Skipping";
emit stateChanged("Skipping zipfile, appears to be an invalid or bad zip file!");
zipper.close();
return;
}
if (!zipper.containsAudioFile())
{
qWarning() << this->objectName() << " - Zipfile missing audio file. Skipping";
emit stateChanged("Skipping zipfile, missing audio file. May not be a karaoke file at all.");
zipper.close();
return;
}
if (!zipper.containsCdgFile())
{
qWarning() << this->objectName() << " - Zipfile missing cdg file. Skipping";
emit stateChanged("Skipping file, missing audio file. May not be a karaoke file at all.");
zipper.close();
return;
}
QTemporaryDir tmpDir;
qWarning() << this->objectName() << " - File appears to be a valid audio+g zipfile, unzipping.";
emit stateChanged("Extracting zip file");
if (!zipper.extractAudio(tmpDir.path()))
{
qWarning() << this->objectName() << " - Error extracting audio file";
zipper.close();
return;
}
if (!zipper.extractCdg(tmpDir.path()))
{
qWarning() << this->objectName() << " - Error extracting cdg file";
zipper.close();
return;
}
zipper.close();
QString zipFileBaseName = QFileInfo(fileName).completeBaseName();
QString cdgFileName = zipFileBaseName + ".cdg";
QString audioFileName = zipFileBaseName + zipper.getAudioExt();
QString destCdg = tmpDir.path() + QDir::separator() + cdgFileName;
QString destAud = tmpDir.path() + QDir::separator() + audioFileName;
if (QFile::exists(destCdg) || QFile::exists(destAud))
{
qWarning() << this->objectName() << " - Found existing cdg or mp3 file in the destination dir, bailing out";
return;
}
if (!QFile::copy(tmpDir.path() + QDir::separator() + "tmp.cdg", destCdg))
{
qWarning() << this->objectName() << " - Error copying cdg file to destination dir, bailing out";
return;
}
if (!QFile::copy(tmpDir.path() + QDir::separator() + "tmp" + zipper.getAudioExt(), destAud))
{
qWarning() << this->objectName() << " - Error copying audio file to the destination dir, bailing out";
return;
}
if (!QFile::exists(destCdg) || !QFile::exists(destAud))
{
qWarning() << this->objectName() << " - Destination cdg or audio file doesn't exist, something went wrong! Bailing out";
return;
}
QString path = QFileInfo(fileName).absolutePath();
QString baseName = QFileInfo(fileName).completeBaseName();
QString mp4file = path + QDir::separator() + baseName + ".mp4";
convertMp3g2Mp4(destCdg, destAud, mp4file);
}
}
bool ProcessingThread::convertMp3g2Mp4(QString cdgFile, QString mp3File, QString mp4file)
{
emit stateChanged("Converting to mp4...");
qWarning() << this->objectName() << " - Converting " << cdgFile << " and " << mp3File << " to " << mp4file;
QProcess *process = new QProcess(this);
QStringList arguments;
arguments << "-n";
arguments << "-itsoffset";
arguments << "0.5";
arguments << "-i";
arguments << cdgFile;
arguments << "-i";
arguments << mp3File;
arguments << "-s";
arguments << "300x216";
arguments << "-c:a";
arguments << "copy";
arguments << "-r";
arguments << "24";
arguments << "-c:v";
arguments << "libx264";
arguments << "-crf";
arguments << "28";
arguments << "-preset";
arguments << "fast";
arguments << "-tune";
arguments << "animation";
arguments << "-map";
arguments << "0:0";
arguments << "-map";
arguments << "1:0";
arguments << mp4file;
process->start(settings->ffmpegPath(), arguments);
process->waitForFinished();
qWarning() << process->readAllStandardOutput();
qWarning() << process->readAllStandardError();
if (process->exitCode() != 0)
{
emit stateChanged("Conversion FAILED!");
qWarning() << this->objectName() << " - Conversion FAILED!";
return false;
}
else
{
qWarning() << this->objectName() << " - Conversion completed successfully";
emit stateChanged("Conversion complete");
return true;
}
}
QMutex mutex;
void ProcessingThread::run()
{
while (!m_terminate)
{
mutex.lock();
if (m_files->size() > 0)
{
m_currentFile = m_files->at(0);
m_files->removeFirst();
mutex.unlock();
}
else
{
mutex.unlock();
emit processingComplete();
emit processingFile("N/A");
return;
}
emit processingFile(m_currentFile);
if (processingType == ProcessingThread::REPLAY_GAIN)
processFileRg(m_currentFile);
else if (processingType == ProcessingThread::ZIPFIX)
processFileZipFix(m_currentFile);
else if (processingType == ProcessingThread::UNZIP)
processFileUnzip(m_currentFile);
else if (processingType == ProcessingThread::ZIP)
processFileZip(m_currentFile);
else if (processingType == ProcessingThread::CASEFIX)
processFileCaseFix(m_currentFile);
else if (processingType == ProcessingThread::CDG2MP4)
processFileCdg2Mp4(m_currentFile);
emit fileProcessed();
}
emit processingFile("N/A");
emit processingAborted();
}
void ProcessingThread::stopProcessing()
{
m_terminate = true;
}