+static int __remove_APIC(TagLib::ID3v2::Tag* tag, int index)
+{
+ metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. ID3v2 tag was not created. Can not proceed metadata updating");
+
+ TagLib::ID3v2::FrameList lst = tag->frameListMap()["APIC"];
+ metadata_editor_retvm_if(lst.isEmpty(), METADATA_EDITOR_ERROR_OPERATION_FAILED, "No pictures in file");
+
+ if ((index < 0) || ((uint)index >= lst.size())) {
+ metadata_editor_error("Index of picture is out of range");
+ return METADATA_EDITOR_ERROR_INVALID_PARAMETER;
+ }
+
+ tag->removeFrame(lst[index]);
+
+ return METADATA_EDITOR_ERROR_NONE;
+}
+static int __remove_mp3_picture(metadata_editor_s* metadata, int index)
+{
+ return __remove_APIC(dynamic_cast<TagLib::MPEG::File*>(metadata->file)->ID3v2Tag(true), index);
+}
+
+static int __remove_mp4_picture(metadata_editor_s* metadata, int index)
+{
+ auto tag = dynamic_cast<TagLib::MP4::Tag*>(metadata->file->tag());
+ metadata_editor_retvm_if(tag == NULL, METADATA_EDITOR_ERROR_OPERATION_FAILED, "Error. tag not exist.");
+
+ if (!(tag->contains("covr"))) {
+ metadata_editor_error("No item <covr> in file. No pictures in file");
+ return METADATA_EDITOR_ERROR_OPERATION_FAILED;
+ }
+
+ TagLib::MP4::CoverArtList lst = tag->item("covr").toCoverArtList();
+
+ // Check if the index is in range of CoverArtList Item
+ if ((index < 0) || ((uint)index >= lst.size())) {
+ metadata_editor_error("Index of picture is out of range");
+ return METADATA_EDITOR_ERROR_INVALID_PARAMETER;
+ }
+
+ metadata_editor_info("The picture number %d will be deleted", index);
+ int i = 0;
+ for (TagLib::MP4::CoverArtList::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) {
+ if (i != index) continue;
+ lst.erase(picIt);
+ break;
+ }
+
+ tag->setItem("covr", lst); //?? FIX ME!
+
+ return METADATA_EDITOR_ERROR_NONE;
+}
+
+#if 0
+static int __remove_flac_picture(metadata_editor_s* metadata, int index)
+{
+ TagLib::FLAC::File* _file = (TagLib::FLAC::File*) metadata->file;
+ TagLib::List<TagLib::FLAC::Picture*> lst = _file->pictureList();
+
+ if (lst.isEmpty()) {
+ metadata_editor_error("No pictures in file. Nothing to delete");
+ return METADATA_EDITOR_ERROR_OPERATION_FAILED;
+ }
+
+ // Check if the index is in range of CoverArtList Item
+ if ((index < 0) || ((uint)index >= lst.size())) {
+ metadata_editor_error("Index of picture is out of range");
+ return METADATA_EDITOR_ERROR_INVALID_PARAMETER;
+ }
+
+ metadata_editor_info("The picture number %d will be deleted", index);
+ int i = 0;
+ for (TagLib::List<TagLib::FLAC::Picture*>::Iterator picIt = lst.begin(); picIt != lst.end(); ++picIt, ++i) {
+ if (i != index) continue;
+ _file->removePicture(*picIt, true);
+ break;
+ }
+
+ return METADATA_EDITOR_ERROR_NONE;
+}
+
+static int __remove_wav_picture(metadata_editor_s* metadata, int index)
+{
+ return __remove_APIC(dynamic_cast<TagLib::ID3v2::Tag*>(metadata->file->tag()), index);
+}
+#endif
+