Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PICARD-187: Support for manually removing cover art #2377

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ShubhamBhut
Copy link
Contributor

PICARD-187: Support for manually removing cover art

finishing PICARD-187

Summary

  • This is a…
    • Bug fix
    • Feature addition
    • Refactoring
    • Minor / simple change (like a typo)
    • Other
  • Describe this change in 1-2 sentences:

Problem

Solution

Add support in all formats to allow to delete cover art tags, and modify ImageList to allow to remove desired image from ImageList

Action

@ShubhamBhut
Copy link
Contributor Author

I wasn't sure whether the extra test functions (for each format) will be required or not, so they are not added. However I have manually tested with all the audio files in test/data/

@@ -659,6 +659,11 @@ def _remove_deleted_tags(self, metadata, tags):
except KeyError:
pass

if self.metadata.images._deleted:
for key, frame in list(tags.items()):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is list() needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem to be needed. I will remove it.

@@ -358,6 +358,17 @@ def _remove_deleted_tags(self, metadata, tags):
del tags[tag]
del tags[real_name]

def _clear_cover_art(self, file):
is_flac = self._File == mutagen.flac.FLAC
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think is_flac is needed here, this is used only once.

@zas
Copy link
Collaborator

zas commented Mar 25, 2024

@ShubhamBhut I saw your messages about this PR on IRC, please discuss issues here instead

@ShubhamBhut
Copy link
Contributor Author

@ShubhamBhut I saw your messages about this PR on IRC, please discuss issues here instead

Ok. I think I rushed a little and missed an important part :
Basically, as I mentioned, the thumbnail is not updating in case of tag removal. I tried clearing pixmap_cache, and setting self.cover_art with a newly created CoverArtThumbnail but they didn't work. I think set_item() should have updated the image change. To be honest, now I am a bit lost on what part of the code is responsible for still displaying the deleted image in the thumbnail.

@zas
Copy link
Collaborator

zas commented Mar 25, 2024

To be honest, now I am a bit lost on what part of the code is responsible for still displaying the deleted image in the thumbnail.

Keep in mind the displayed image is just a visual thing, a pixmap, so it has to be updated after the actual image was removed from metadata, but some care is needed because the same image might be used multiple times (in various tracks, or albums).

Have a look at https://github.com/metabrainz/picard/blob/7d97ff12043b80d8e9bad80423e6d8d2effacd71/picard/util/imagelist.py#L273C1-L286

@ShubhamBhut ShubhamBhut force-pushed the PICARD-187 branch 2 times, most recently from 7ebc65d to f16ed33 Compare March 29, 2024 06:51
@ShubhamBhut
Copy link
Contributor Author

Apologies for such late follow up, I tried a lot of different implementations. Now deletion seems to be done perfectly. But the thumbnail update still remains. For some reason, self.cover_art.set_metadata(metadata), sets the metadata correctly but it is overwritten by something else and the thumbnail goes back to the (deleted) cover art image.

@@ -545,6 +550,43 @@ def load_remote_image(self, url, data):
log.warning("Can't load image: %s", e)
return

def delete_cover_art(self):
if not self.item or not self.item.metadata.images:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an important flaw here:

  • if an album was just loaded, and no image was downloaded (it has only embedded artwork), actual metadata that contains images is self.item.orig_metadata and self.item.metadata is empty.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bit tricky to solve I think. If we remove cover art the right thing is to actually update item.metadata. item.orig_metadata should not be touched here, as it is the original data.

Now I think what happens is that once all images have been removed from item.metadata the cover art box assumes there are no new images and falls back to show the images from orig_metadata (this happens in CoverArtBox.update_metadata.

The correct thing then would be to not do this fallback if self.item.metadata.images.delete == True.

picard/ui/coverartbox.py Outdated Show resolved Hide resolved
picard/util/imagelist.py Show resolved Hide resolved
picard/ui/coverartbox.py Show resolved Hide resolved
picard/ui/coverartbox.py Outdated Show resolved Hide resolved
picard/util/imagelist.py Outdated Show resolved Hide resolved
Copy link
Member

@phw phw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment on how I think the cover art box display issue needs to be solved. Otherwise this is looking good now.

It's really one of the issues that looks simple first but is rather tricky to get right.

@@ -545,6 +550,43 @@ def load_remote_image(self, url, data):
log.warning("Can't load image: %s", e)
return

def delete_cover_art(self):
if not self.item or not self.item.metadata.images:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bit tricky to solve I think. If we remove cover art the right thing is to actually update item.metadata. item.orig_metadata should not be touched here, as it is the original data.

Now I think what happens is that once all images have been removed from item.metadata the cover art box assumes there are no new images and falls back to show the images from orig_metadata (this happens in CoverArtBox.update_metadata.

The correct thing then would be to not do this fallback if self.item.metadata.images.delete == True.

@@ -33,6 +33,7 @@ def __init__(self, iterable=()):
self._images = list(iterable)
self._hash_dict = {}
self._changed = True
self._deleted = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add a deleted property to the class to access this internal variable. Then other code does not need to access a variable that is supposed to be internal to the imagelist implementation.

@property
def deleted(self):
    return self._deleted

@rdswift
Copy link
Collaborator

rdswift commented Apr 18, 2024

Added PICARD-2865 to cover updating the documentation.

@rdswift
Copy link
Collaborator

rdswift commented Apr 18, 2024

@ShubhamBhut, you should probably update the PICARD-187 ticket to show it being assigned to you so nobody else accidentally starts working on it.

if not metadata or not metadata.images:
return

debug_info = "Deleting %r from %r"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be "Deleted %r from %r", since it isn't logged until the deletion is complete?

image_delete(item, selected_image)
item.update()
else:
debug_info = "Dropping %r to %r is not handled"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency in terminology, would it be more appropriate to change this to something like "Unable to delete %r from %r"?

PICARD-187: Support for manually removing cover art

finishing PICARD-187
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants