Skip to content

Commit

Permalink
Parse the Artist and the Title of a song from the filename if the cor…
Browse files Browse the repository at this point in the history
…responding ID3 tags are empty
  • Loading branch information
badescunicu committed May 10, 2014
1 parent 694f3d7 commit 58e79ec
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/trackinfoobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,14 @@ void TrackInfoObject::parse() {
// TODO(rryan): Should we re-visit this decision?
if (!(pProxiedSoundSource->getArtist().isEmpty())) {
setArtist(pProxiedSoundSource->getArtist());
} else {
parseArtist();
}

if (!(pProxiedSoundSource->getTitle().isEmpty())) {
setTitle(pProxiedSoundSource->getTitle());
} else {
parseTitle();
}

if (!(pProxiedSoundSource->getType().isEmpty())) {
Expand Down Expand Up @@ -207,6 +211,25 @@ void TrackInfoObject::parse() {
}
}

void TrackInfoObject::parseArtist() {
QMutexLocker lock(&m_qMutex);
QString filename = m_fileInfo.fileName();
if (filename.count('-') == 1) {
m_sArtist = filename.section('-', 0, 0).trimmed();
m_sArtist = m_sArtist.replace("_", " ");
setDirty(true);
}
}

void TrackInfoObject::parseTitle() {
QMutexLocker lock(&m_qMutex);
QString filename = m_fileInfo.fileName();
if (filename.count('-') == 1) {
m_sTitle = filename.section('-', 1, 1).trimmed();
m_sTitle = m_sTitle.replace("_", " ");
setDirty(true);
}
}

void TrackInfoObject::parseFilename() {
QMutexLocker lock(&m_qMutex);
Expand Down
4 changes: 3 additions & 1 deletion src/trackinfoobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,11 @@ class TrackInfoObject : public QObject {
// Common initialization function between all TIO constructors.
void initialize(bool parseHeader);

// Method for parsing information from knowing only the file name. It
// Methods for parsing information from knowing only the file name. It
// assumes that the filename is written like: "artist - trackname.xxx"
void parseFilename();
void parseArtist();
void parseTitle();

// Set whether the TIO is dirty not. This should never be called except by
// TIO local methods or the TrackDAO.
Expand Down

0 comments on commit 58e79ec

Please sign in to comment.