From ef1992570b9d22e1a09a7956f687c1078c3f5ddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Wed, 1 Jul 2015 15:02:52 +0200 Subject: [PATCH] Define some original year tag keys as constants and enclose some if bodies with {}. --- ext/libclementine-tagreader/tagreader.cpp | 36 ++++++++++++++++------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/ext/libclementine-tagreader/tagreader.cpp b/ext/libclementine-tagreader/tagreader.cpp index bd5e07cc9..b32d3ee66 100644 --- a/ext/libclementine-tagreader/tagreader.cpp +++ b/ext/libclementine-tagreader/tagreader.cpp @@ -107,6 +107,14 @@ const char* TagReader::kMP4_FMPS_Playcount_ID = const char* TagReader::kMP4_FMPS_Score_ID = "----:com.apple.iTunes:FMPS_Rating_Amarok_Score"; +namespace { +// Tags containing the year the album was originally released (in contrast to +// other tags that contain the release year of the current edition) +const char* kMP4_OriginalYear_ID = "----:com.apple.iTunes:ORIGINAL YEAR"; +const char* kASF_OriginalDate_ID = "WM/OriginalReleaseTime"; +const char* kASF_OriginalYear_ID = "WM/OriginalReleaseYear"; +} + TagReader::TagReader() : factory_(new TagLibFileRefFactory), network_(new QNetworkAccessManager), @@ -190,12 +198,13 @@ void TagReader::ReadFile(const QString& filename, compilation = TStringToQString(map["TCMP"].front()->toString()).trimmed(); - if (!map["TDOR"].isEmpty()) + if (!map["TDOR"].isEmpty()) { song->set_originalyear( map["TDOR"].front()->toString().substr(0, 4).toInt()); - else if (!map["TORY"].isEmpty()) + } else if (!map["TORY"].isEmpty()) { song->set_originalyear( map["TORY"].front()->toString().substr(0, 4).toInt()); + } if (!map["USLT"].isEmpty()) { Decode(map["USLT"].front()->toString(), nullptr, @@ -321,10 +330,13 @@ void TagReader::ReadFile(const QString& filename, song->mutable_grouping()); } - if (items.contains("----:com.apple.iTunes:ORIGINAL YEAR")) + if (items.contains(kMP4_OriginalYear_ID)) { song->set_originalyear( - TStringToQString(items["----:com.apple.iTunes:ORIGINAL YEAR"] - .toStringList().toString('\n')).left(4).toInt()); + TStringToQString( + items[kMP4_OriginalYear_ID].toStringList().toString('\n')) + .left(4) + .toInt()); + } Decode(mp4_tag->comment(), nullptr, song->mutable_comment()); } @@ -367,18 +379,20 @@ void TagReader::ReadFile(const QString& filename, } } - if (attributes_map.contains("WM/OriginalReleaseTime")) { + if (attributes_map.contains(kASF_OriginalDate_ID)) { const TagLib::ASF::AttributeList& attributes = - attributes_map["WM/OriginalReleaseTime"]; - if (!attributes.isEmpty()) + attributes_map[kASF_OriginalDate_ID]; + if (!attributes.isEmpty()) { song->set_originalyear( TStringToQString(attributes.front().toString()).left(4).toInt()); - } else if (attributes_map.contains("WM/OriginalReleaseYear")) { + } + } else if (attributes_map.contains(kASF_OriginalYear_ID)) { const TagLib::ASF::AttributeList& attributes = - attributes_map["WM/OriginalReleaseYear"]; - if (!attributes.isEmpty()) + attributes_map[kASF_OriginalYear_ID]; + if (!attributes.isEmpty()) { song->set_originalyear( TStringToQString(attributes.front().toString()).left(4).toInt()); + } } } #endif