delete thumbnails with 0 bytes size

This commit is contained in:
geoffrey45
2022-07-31 10:31:41 +03:00
parent cfea978298
commit b522069d8e
2 changed files with 11 additions and 7 deletions
+5 -4
View File
@@ -37,7 +37,6 @@ class RipAlbumImage:
class ValidateAlbumThumbs:
@staticmethod
def remove_obsolete():
"""
@@ -54,6 +53,10 @@ class ValidateAlbumThumbs:
if e is None:
os.remove(entry.path)
break
if os.path.getsize(entry.path) == 0:
os.remove(entry.path)
@staticmethod
def find_lost_thumbnails():
@@ -61,9 +64,7 @@ class ValidateAlbumThumbs:
Re-rip lost album thumbnails
"""
entries = os.scandir(THUMBS_PATH)
entries = [
Thumbnail(entry.name) for entry in entries if entry.is_file()
]
entries = [Thumbnail(entry.name) for entry in entries if entry.is_file()]
albums = helpers.Get.get_all_albums()
thumbs = [(album.hash + ".webp") for album in albums]
+6 -3
View File
@@ -9,7 +9,7 @@ from mutagen.id3 import ID3
from PIL import Image
def return_album_art(filepath: str):
def parse_album_art(filepath: str):
"""
Returns the album art for a given audio file.
"""
@@ -36,9 +36,12 @@ def extract_thumb(filepath: str, webp_path: str) -> bool:
tsize = settings.THUMB_SIZE
if os.path.exists(img_path):
return True
img_size = os.path.getsize(filepath)
album_art = return_album_art(filepath)
if img_size > 0:
return True
album_art = parse_album_art(filepath)
if album_art is not None:
img = Image.open(BytesIO(album_art))