Read date and genre from individual tracks in cue sheets

Fixes #347
This commit is contained in:
Jonas Kvinge
2020-04-25 13:47:25 +02:00
parent 8e1def225b
commit ae05a61551

View File

@@ -79,7 +79,9 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
QString album_composer; QString album_composer;
QString file; QString file;
QString file_type; QString file_type;
QString album_genre;
QString genre; QString genre;
QString album_date;
QString date; QString date;
QString disc; QString disc;
@@ -91,66 +93,46 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
if (splitted.size() < 2) { if (splitted.size() < 2) {
continue; continue;
} }
QString line_name = splitted[0].toLower(); QString line_name = splitted[0].toLower();
QString line_value = splitted[1]; QString line_value = splitted[1];
// PERFORMER
if (line_name == kPerformer) { if (line_name == kPerformer) {
album_artist = line_value; album_artist = line_value;
// TITLE
} }
else if (line_name == kTitle) { else if (line_name == kTitle) {
album = line_value; album = line_value;
// SONGWRITER
} }
else if (line_name == kSongWriter) { else if (line_name == kSongWriter) {
album_composer = line_value; album_composer = line_value;
// FILE
} }
else if (line_name == kFile) { else if (line_name == kFile) {
file = QDir::isAbsolutePath(line_value) ? line_value : dir.absoluteFilePath(line_value); file = QDir::isAbsolutePath(line_value) ? line_value : dir.absoluteFilePath(line_value);
if (splitted.size() > 2) { if (splitted.size() > 2) {
file_type = splitted[2]; file_type = splitted[2];
} }
// REM
} }
else if (line_name == kRem) { else if (line_name == kRem) {
if (splitted.size() < 3) { if (splitted.size() < 3) {
break; break;
} }
// REM GENRE
if (line_value.toLower() == kGenre) { if (line_value.toLower() == kGenre) {
genre = splitted[2]; album_genre = splitted[2];
}
// REM DATE else if (line_value.toLower() == kDate) {
} else if (line_value.toLower() == kDate) { album_date = splitted[2];
date = splitted[2]; }
else if (line_value.toLower() == kDisc) {
// REM DISC
} else if (line_value.toLower() == kDisc) {
disc = splitted[2]; disc = splitted[2];
} }
}
// end of the header -> go into the track mode // end of the header -> go into the track mode
} else if (line_name == kTrack) { else if (line_name == kTrack) {
files++; files++;
break; break;
} }
// just ignore the rest of possible field types for now... // just ignore the rest of possible field types for now...
} while (!(line = text_stream.readLine()).isNull()); }
while (!(line = text_stream.readLine()).isNull());
if(line.isNull()) { if(line.isNull()) {
qLog(Warning) << "the .cue file from " << dir_path << " defines no tracks!"; qLog(Warning) << "the .cue file from " << dir_path << " defines no tracks!";
@@ -183,12 +165,12 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
// the beginning of another track's definition - we're saving the current one for later (if it's valid of course) // the beginning of another track's definition - we're saving the current one for later (if it's valid of course)
// please note that the same code is repeated just after this 'do-while' loop // please note that the same code is repeated just after this 'do-while' loop
if(valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type == kAudioTrackType)) { if (valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type == kAudioTrackType)) {
entries.append(CueEntry(file, index, title, artist, album_artist, album, composer, album_composer, genre, date, disc)); entries.append(CueEntry(file, index, title, artist, album_artist, album, composer, album_composer, genre, (date.isEmpty() ? album_date : date), disc));
} }
// clear the state // clear the state
track_type = index = artist = title = ""; track_type = index = artist = composer = title = date = genre = "";
if (!line_additional.isEmpty()) { if (!line_additional.isEmpty()) {
track_type = line_additional; track_type = line_additional;
@@ -207,18 +189,28 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
} }
} }
} }
else if (line_name == kPerformer) {
artist = line_value;
}
else if (line_name == kTitle) { else if (line_name == kTitle) {
title = line_value; title = line_value;
} }
else if (line_name == kDate) {
date = line_value;
}
else if (line_name == kPerformer) {
artist = line_value;
}
else if (line_name == kSongWriter) { else if (line_name == kSongWriter) {
composer = line_value; composer = line_value;
// End of track's for the current file -> parse next one // End of track's for the current file -> parse next one
} }
else if (line_name == kRem && splitted.size() >= 3) {
if (line_value.toLower() == kGenre) {
genre = splitted[2];
}
else if (line_value.toLower() == kDate) {
date = splitted[2];
}
}
else if (line_name == kFile) { else if (line_name == kFile) {
break; break;
} }
@@ -227,8 +219,8 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
while (!(line = text_stream.readLine()).isNull()); while (!(line = text_stream.readLine()).isNull());
// We didn't add the last song yet... // We didn't add the last song yet...
if(valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type == kAudioTrackType)) { if (valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type == kAudioTrackType)) {
entries.append(CueEntry(file, index, title, artist, album_artist, album, composer, album_composer, genre, date, disc)); entries.append(CueEntry(file, index, title, artist, album_artist, album, composer, album_composer, (genre.isEmpty() ? album_genre : genre), (date.isEmpty() ? album_date : date), disc));
} }
} }
@@ -259,7 +251,8 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
if (!UpdateSong(entry, entries.at(i + 1).index, &song)) { if (!UpdateSong(entry, entries.at(i + 1).index, &song)) {
continue; continue;
} }
} else { }
else {
// incorrect index? // incorrect index?
if (!UpdateLastSong(entry, &song)) { if (!UpdateLastSong(entry, &song)) {
continue; continue;