diff options
author | Andrzej Rybczak <electricityispower@gmail.com> | 2012-10-02 20:33:27 +0200 |
---|---|---|
committer | Andrzej Rybczak <electricityispower@gmail.com> | 2012-10-02 21:16:36 +0200 |
commit | a0ccf53f18aa3cc79560a7cc59cf42c8cc0710b5 (patch) | |
tree | 2bd46df9386262ded2c5a90bae158ab0ccf3a07f /extras/artist_to_albumartist.cpp | |
parent | 49d1d5672205c963e6fc0bdfc7244140f867178a (diff) |
extras: fix script
Diffstat (limited to 'extras/artist_to_albumartist.cpp')
-rw-r--r-- | extras/artist_to_albumartist.cpp | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/extras/artist_to_albumartist.cpp b/extras/artist_to_albumartist.cpp index ae87435f..200f0e24 100644 --- a/extras/artist_to_albumartist.cpp +++ b/extras/artist_to_albumartist.cpp @@ -31,12 +31,20 @@ enum class CopyResult { Success, NoArtist, AlbumArtistAlreadyInPlace }; +bool is_framelist_empty(const TagLib::ID3v2::FrameList &list) +{ + for (auto it = list.begin(); it != list.end(); ++it) + if ((*it)->toString() != TagLib::String::null) + return false; + return true; +} + CopyResult copy_album_artist(TagLib::ID3v2::Tag *tag) { typedef TagLib::ID3v2::TextIdentificationFrame TextFrame; TagLib::ByteVector album_artist = "TPE2"; - if (!tag->frameList(album_artist).isEmpty()) + if (!is_framelist_empty(tag->frameList(album_artist))) return CopyResult::AlbumArtistAlreadyInPlace; auto artists = tag->frameList("TPE1"); @@ -45,8 +53,10 @@ CopyResult copy_album_artist(TagLib::ID3v2::Tag *tag) for (auto it = artists.begin(); it != artists.end(); ++it) { + // this cast should always succeed. + auto &textIt = dynamic_cast<TextFrame &>(**it); auto frame = new TextFrame(album_artist, TagLib::String::UTF8); - frame->setText((*it)->toString()); + frame->setText(textIt.fieldList()); tag->addFrame(frame); } @@ -63,7 +73,7 @@ CopyResult copy_album_artist(TagLib::Ogg::XiphComment *tag) return CopyResult::NoArtist; for (auto it = artists.begin(); it != artists.end(); ++it) - tag->addField("ALBUMARTIST", *it, true); + tag->addField("ALBUMARTIST", *it, false); return CopyResult::Success; } @@ -129,8 +139,12 @@ int main(int argc, char **argv) if (argc < 2) { std::cout << "This little script copies Artist tag (if present) to\n"; - std::cout << "AlbumArtist (if not present) for given mp3/ogg/flac files.\n\n"; + std::cout << "AlbumArtist (if not present) for given mp3/ogg/flac files.\n"; + std::cout << "\n"; std::cout << "Usage: " << argv[0] << " [--dry-run] files\n"; + std::cout << "\n"; + std::cout << "Note: to run it recursively for all your files, you can use:\n"; + std::cout << "$ find DIRECTORY \\( -name \"*.flac\" -o -name \"*.mp3\" -o -name \"*.ogg\" \\) -exec ./artist_to_albumartist [--dry-run] {} \\;\n"; } else { |