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

Remove all images for a show, using the ImageClass(). #3503

Merged
merged 20 commits into from
Dec 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions medusa/image_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,29 @@ def which_type(self, image_path):
logger.log('Image has size ratio of {img_ratio}, unknown type'.format(img_ratio=img_ratio), logger.WARNING)
return

def remove_all_images(self, series):
"""Remove all poster, banner, fanart images."""
# check if the images are already cached or not
image_paths = {
self.POSTER: self.poster_path(series.indexerid),
self.BANNER: self.banner_path(series.indexerid),
self.POSTER_THUMB: self.poster_thumb_path(series.indexerid),
self.BANNER_THUMB: self.banner_thumb_path(series.indexerid),
self.FANART: self.fanart_path(series.indexerid)
}

removed_images = []

for image_type in image_paths:
if image_paths[image_type]:
if os.path.isfile(image_paths[image_type]):
os.remove(image_paths[image_type])
removed_images.append(image_type)

if removed_images:
logger.log('Removed images: {image_types} for series {series_name}'.format(
image_types=', '.join(removed_images), series_name=series.name), logger.INFO)

def _cache_image_from_file(self, image_path, img_type, indexer_id):
"""
Take the image provided and copy it to the cache folder.
Expand Down
1 change: 1 addition & 0 deletions medusa/server/web/home/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,7 @@ def updateShow(self, show=None):

# force the update
try:
show_obj.remove_images()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See one line change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Point is, that this is an object oriented approach. As the logic to delete the files in now in the ImageClass, where it should be. To make it more clean, we could even replace some of logic for cleaning up the images after a show delete, using this method.

app.show_queue_scheduler.action.updateShow(show_obj)
except CantUpdateShowException as e:
ui.notifications.error('Unable to update this show.', ex(e))
Expand Down
4 changes: 4 additions & 0 deletions medusa/tv/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2316,6 +2316,10 @@ def delete(self, remove_files):
except CantRemoveShowException:
pass

def remove_images(self):
"""Remove images from cache."""
image_cache.ImageCache().remove_all_images(self)

def get_asset(self, asset_type):
"""Get the specified asset for this series."""
asset_type = asset_type.lower()
Expand Down