Don't write rating if not set

Fixes issue #4128
This commit is contained in:
Arnaud Bienner 2014-10-21 21:49:23 +02:00
parent c43eb02efd
commit f2eecadbd3
2 changed files with 40 additions and 0 deletions

View File

@ -723,6 +723,14 @@ bool TagReader::SaveSongRatingToFile(
if (filename.isNull()) return false;
qLog(Debug) << "Saving song rating tags to" << filename;
if (song.rating() < 0) {
// The FMPS spec says unrated == "tag not present". For us, no rating
// results in rating being -1, so don't write anything in that case.
// Actually, we should also remove tag set in this case, but in
// Clementine it is not possible to unset rating i.e. make a song "unrated".
qLog(Debug) << "Unrated: do nothing";
return true;
}
std::unique_ptr<TagLib::FileRef> fileref(factory_->GetFileRef(filename));

View File

@ -153,6 +153,38 @@ TEST_F(SongTest, FMPSPlayCountBoth) {
EXPECT_EQ(123, song.playcount());
}
TEST_F(SongTest, FMPSUnrated) {
QStringList files_to_test;
files_to_test <<
":/testdata/beep.m4a" <<
":/testdata/beep.mp3" <<
":/testdata/beep.flac" <<
":/testdata/beep.ogg" <<
":/testdata/beep.spx" <<
":/testdata/beep.wav" <<
":/testdata/beep.wma";
for (const QString& test_filename : files_to_test) {
TemporaryResource r(test_filename);
Song song = ReadSongFromFile(r.fileName());
// beep files don't contain rating info, so they should be considered as
// "unrated" i.e. rating == -1
EXPECT_EQ(-1, song.rating());
// Writing -1 i.e. "unrated" to a file shouldn't write anything
WriteSongRatingToFile(song, r.fileName());
// Compare files
QFile orig_file(test_filename);
orig_file.open(QIODevice::ReadOnly);
QByteArray orig_file_data = orig_file.readAll();
QFile temp_file(r.fileName());
temp_file.open(QIODevice::ReadOnly);
QByteArray temp_file_data = temp_file.readAll();
EXPECT_TRUE(!orig_file_data.isEmpty());
EXPECT_TRUE(!temp_file_data.isEmpty());
EXPECT_TRUE(orig_file_data == temp_file_data);
}
}
TEST_F(SongTest, FMPSScore) {
TemporaryResource r(":/testdata/beep.mp3");
{