Read/Write FMPS tags for Ogg files
This commit is contained in:
parent
16793744c0
commit
1386a54d78
@ -185,7 +185,6 @@ void TagReader::ReadFile(const QString& filename,
|
|||||||
// Check POPM tags
|
// Check POPM tags
|
||||||
// We do this after checking FMPS frames, so FMPS have precedence, as we
|
// We do this after checking FMPS frames, so FMPS have precedence, as we
|
||||||
// will consider POPM tags iff song has no rating/playcount already set.
|
// will consider POPM tags iff song has no rating/playcount already set.
|
||||||
qLog(Debug) << "POPM";
|
|
||||||
if (!map["POPM"].isEmpty()) {
|
if (!map["POPM"].isEmpty()) {
|
||||||
const TagLib::ID3v2::PopularimeterFrame* frame =
|
const TagLib::ID3v2::PopularimeterFrame* frame =
|
||||||
dynamic_cast<const TagLib::ID3v2::PopularimeterFrame*>(map["POPM"].front());
|
dynamic_cast<const TagLib::ID3v2::PopularimeterFrame*>(map["POPM"].front());
|
||||||
@ -383,6 +382,12 @@ void TagReader::ParseOggTag(const TagLib::Ogg::FieldListMap& map,
|
|||||||
|
|
||||||
if (!map["COVERART"].isEmpty())
|
if (!map["COVERART"].isEmpty())
|
||||||
song->set_art_automatic(kEmbeddedCover);
|
song->set_art_automatic(kEmbeddedCover);
|
||||||
|
|
||||||
|
if (!map["FMPS_RATING"].isEmpty() && song->rating() <= 0)
|
||||||
|
song->set_rating(TStringToQString( map["FMPS_RATING"].front() ).trimmed().toFloat());
|
||||||
|
|
||||||
|
if (!map["FMPS_PLAYCOUNT"].isEmpty() && song->playcount() <= 0)
|
||||||
|
song->set_playcount(TStringToQString( map["FMPS_PLAYCOUNT"].front() ).trimmed().toFloat());
|
||||||
}
|
}
|
||||||
|
|
||||||
pb::tagreader::SongMetadata_Type TagReader::GuessFileType(
|
pb::tagreader::SongMetadata_Type TagReader::GuessFileType(
|
||||||
@ -526,6 +531,14 @@ bool TagReader::SaveSongStatisticsToFile(const QString& filename,
|
|||||||
|
|
||||||
frame->setRating(ConvertToPOPMRating(song.rating()));
|
frame->setRating(ConvertToPOPMRating(song.rating()));
|
||||||
frame->setCounter(song.playcount());
|
frame->setCounter(song.playcount());
|
||||||
|
|
||||||
|
} else if (TagLib::Ogg::Vorbis::File* file = dynamic_cast<TagLib::Ogg::Vorbis::File*>(fileref->file())) {
|
||||||
|
if (file->tag()) {
|
||||||
|
file->tag()->addField("FMPS_RATING",
|
||||||
|
QStringToTaglibString(QString::number(song.rating())));
|
||||||
|
file->tag()->addField("FMPS_PLAYCOUNT",
|
||||||
|
QStringToTaglibString(QString::number(song.playcount())));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Nothing to save: stop now
|
// Nothing to save: stop now
|
||||||
return true;
|
return true;
|
||||||
|
@ -160,4 +160,19 @@ TEST_F(SongTest, BothFMPSPOPMRating) {
|
|||||||
EXPECT_FLOAT_EQ(0.42, song.rating());
|
EXPECT_FLOAT_EQ(0.42, song.rating());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SongTest, FMPSOgg) {
|
||||||
|
TemporaryResource r(":/testdata/beep.ogg");
|
||||||
|
{
|
||||||
|
Song song = ReadSongFromFile(r.fileName());
|
||||||
|
song.set_rating(0.20);
|
||||||
|
song.set_playcount(1337);
|
||||||
|
|
||||||
|
WriteSongStatisticsToFile(song, r.fileName());
|
||||||
|
}
|
||||||
|
|
||||||
|
Song new_song = ReadSongFromFile(r.fileName());
|
||||||
|
EXPECT_FLOAT_EQ(0.20, new_song.rating());
|
||||||
|
EXPECT_EQ(1337, new_song.playcount());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
Loading…
x
Reference in New Issue
Block a user