-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathanalyzefiletask.cpp
More file actions
88 lines (77 loc) · 2.47 KB
/
Copy pathanalyzefiletask.cpp
File metadata and controls
88 lines (77 loc) · 2.47 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
#include <QDebug>
#include <QFile>
#include "decoder.h"
#include "tagreader.h"
#include "utils.h"
#include "analyzefiletask.h"
#include "constants.h"
AnalyzeFileTask::AnalyzeFileTask(const QString &path)
: m_path(path)
{
}
void AnalyzeFileTask::run()
{
qDebug() << "Analyzing file" << m_path;
AnalyzeResult *result = new AnalyzeResult();
result->fileName = m_path;
TagReader tags(m_path);
if (!tags.read()) {
result->error = true;
result->errorMessage = "Couldn't read metadata";
emit finished(result);
return;
}
qDebug() << "Track:" << tags.track();
qDebug() << "Artist:" << tags.artist();
qDebug() << "Album:" << tags.album();
qDebug() << "AlbumArtist:" << tags.albumArtist();
qDebug() << "TrackNo:" << tags.trackNo();
qDebug() << "DiscNo:" << tags.discNo();
qDebug() << "Year:" << tags.year();
qDebug() << "PUID:" << tags.puid();
result->mbid = tags.mbid();
result->track = tags.track();
result->artist = tags.artist();
result->album = tags.album();
result->albumArtist = tags.albumArtist();
result->puid = tags.puid();
result->trackNo = tags.trackNo();
result->discNo = tags.discNo();
result->year = tags.year();
result->length = tags.length();
result->bitrate = tags.bitrate();
if (result->length < 10) {
result->error = true;
result->errorMessage = "Too short audio stream, should be at least 10 seconds";
emit finished(result);
return;
}
if (result->mbid.isEmpty() && result->puid.isEmpty() && (result->track.isEmpty() || result->album.isEmpty() || result->artist.isEmpty())) {
result->error = true;
result->errorMessage = "Couldn't find any usable metadata";
emit finished(result);
return;
}
#ifdef Q_OS_WIN32
QByteArray encodedPath = m_path.toUtf8();
#else
QByteArray encodedPath = QFile::encodeName(m_path);
#endif
Decoder decoder(encodedPath.data());
if (!decoder.Open()) {
result->error = true;
result->errorMessage = QString("Couldn't open the file: ") + QString::fromStdString(decoder.LastError());
emit finished(result);
return;
}
FingerprintCalculator fpcalculator;
if (!fpcalculator.start(decoder.SampleRate(), decoder.Channels())) {
result->error = true;
result->errorMessage = "Error while fingerpriting the file";
emit finished(result);
return;
}
decoder.Decode(&fpcalculator, AUDIO_LENGTH);
result->fingerprint = fpcalculator.finish();
emit finished(result);
}