From 0f254b164e0eb814093aa2c84df3ea2536c5715a Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 4 Nov 2014 11:01:58 +0100 Subject: [PATCH] tags: mp3: write IDv2.4 tags only --- NEWS | 1 + src/tags.cpp | 26 ++++++++++---------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/NEWS b/NEWS index a747842a..79a15928 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ ncmpcpp-0.6.1 (????-??-??) * Comment tag is now properly written to mp3 files. +* Only ID3v2.4 tags are now saved to mp3 files. ncmpcpp-0.6 (2014-10-25) diff --git a/src/tags.cpp b/src/tags.cpp index 03a8330e..832351e4 100644 --- a/src/tags.cpp +++ b/src/tags.cpp @@ -117,17 +117,6 @@ void readXiphComments(MPD::MutableSong &s, TagLib::Ogg::XiphComment *tag) readField(fields["COMMENT"], &MPD::MutableSong::setComment); } -void clearID3v1Tags(TagLib::ID3v1::Tag *tag) -{ - tag->setTitle(TagLib::String::null); - tag->setArtist(TagLib::String::null); - tag->setAlbum(TagLib::String::null); - tag->setYear(0); - tag->setTrack(0); - tag->setGenre(TagLib::String::null); - tag->setComment(TagLib::String::null); -} - void writeCommonTags(const MPD::MutableSong &s, TagLib::Tag *tag) { tag->setTitle(ToWString(s.getTitle())); @@ -293,10 +282,15 @@ bool write(MPD::MutableSong &s) if (f.isNull()) return false; - if (auto mp3_file = dynamic_cast(f.file())) + bool saved = false; + if (auto mpeg_file = dynamic_cast(f.file())) { - clearID3v1Tags(mp3_file->ID3v1Tag()); - writeID3v2Tags(s, mp3_file->ID3v2Tag(true)); + writeID3v2Tags(s, mpeg_file->ID3v2Tag(true)); + // write id3v2.4 tags only + if (!mpeg_file->save(TagLib::MPEG::File::ID3v2, true, 4, false)) + return false; + // do not call generic save() as it will duplicate tags + saved = true; } else if (auto ogg_file = dynamic_cast(f.file())) { @@ -309,9 +303,9 @@ bool write(MPD::MutableSong &s) else writeCommonTags(s, f.tag()); - if (!f.save()) + if (!saved && !f.save()) return false; - + if (!s.getNewName().empty()) { std::string new_name;