diff options
author | StefanBruens <stefan.bruens@rwth-aachen.de> | 2019-05-31 13:21:16 +0200 |
---|---|---|
committer | Stephen F. Booth <me@sbooth.org> | 2019-05-31 15:51:16 +0430 |
commit | ba7adc2bc261ed634c2a964185bcffb9365ad2f4 (patch) | |
tree | 7853fba6f5dfc3287ac82718177e08c237b86c01 | |
parent | 79bb1428c0482966cdafd9b6e1127e98b4637fbf (diff) |
Respect atom type when converting rate tag (#896)
* Respect atom type when converting rate tag
TagLib prior to #818 (commit ff28cf276c60) read and wrote the "rate" tag as
text, and switched to reading it as integer value even when the atom class
is a text type. This breaks reading existing files, and can be avoided by
taking the atom type into account.
This fixes issue #885.
* Respect MP4::Item type when writing the rate tag
TagLib prior to #818 (commit ff28cf276c60) read and wrote the "rate" tag
as text, and switched to writing the integer value of the MP4::Item.
This breaks writing from applications which supply the value as
StringList, which was the previously implemented API. Applications using
an MP4::Item(UInt) are still supported without changes on the application
side.
This is the complementary writing part for issue #885.
-rw-r--r-- | taglib/mp4/mp4tag.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/taglib/mp4/mp4tag.cpp b/taglib/mp4/mp4tag.cpp index a3636a9d..9b137cd9 100644 --- a/taglib/mp4/mp4tag.cpp +++ b/taglib/mp4/mp4tag.cpp @@ -74,9 +74,20 @@ MP4::Tag::Tag(TagLib::File *file, MP4::Atoms *atoms) : atom->name == "hdvd" || atom->name == "shwm") { parseBool(atom); } - else if(atom->name == "tmpo" || atom->name == "rate" || atom->name == "\251mvi" || atom->name == "\251mvc") { + else if(atom->name == "tmpo" || atom->name == "\251mvi" || atom->name == "\251mvc") { parseInt(atom); } + else if(atom->name == "rate") { + AtomDataList data = parseData2(atom); + if(!data.isEmpty()) { + AtomData val = data[0]; + if (val.type == TypeUTF8) { + addItem(atom->name, StringList(String(val.data, String::UTF8))); + } else { + addItem(atom->name, (int)(val.data.toShort())); + } + } + } else if(atom->name == "tvsn" || atom->name == "tves" || atom->name == "cnID" || atom->name == "sfID" || atom->name == "atID" || atom->name == "geID" || atom->name == "cmID") { @@ -480,9 +491,19 @@ MP4::Tag::save() name == "shwm") { data.append(renderBool(name.data(String::Latin1), it->second)); } - else if(name == "tmpo" || name == "rate" || name == "\251mvi" || name == "\251mvc") { + else if(name == "tmpo" || name == "\251mvi" || name == "\251mvc") { data.append(renderInt(name.data(String::Latin1), it->second)); } + else if (name == "rate") { + const MP4::Item& item = it->second; + StringList value = item.toStringList(); + if (value.isEmpty()) { + data.append(renderInt(name.data(String::Latin1), item)); + } + else { + data.append(renderText(name.data(String::Latin1), item)); + } + } else if(name == "tvsn" || name == "tves" || name == "cnID" || name == "sfID" || name == "atID" || name == "geID" || name == "cmID") { |