Created
February 12, 2021 20:52
-
-
Save kdelwat/b1288c3f87568e15da51260ffef65683 to your computer and use it in GitHub Desktop.
Replace progressive JPEGs in album art with non-progressive JPEGs, recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import eyed3 | |
import io | |
import os | |
from PIL import Image | |
def is_progressive(img): | |
return "progression" in img.info or "progressive" in img.info | |
def deprogressify(filename): | |
f = eyed3.load(filename) | |
if f is None: | |
return | |
if f.tag is None: | |
f.initTag() | |
cover = f.tag.images[0] | |
img = Image.open(io.BytesIO(cover.image_data)) | |
if not is_progressive(img): | |
return | |
adjusted = io.BytesIO() | |
img.save(adjusted, "JPEG", progressive=False) | |
adjusted.seek(0) | |
existing_images = [x.description for x in f.tag.images] | |
for e in existing_images: | |
f.tag.images.remove(e) | |
f.tag.images.set(3, adjusted.read(), "image/jpeg") | |
f.tag.save() | |
for root, dirs, files in os.walk("C:/Users/cadel/Music/beets"): | |
for file in files: | |
deprogressify(os.path.join(root, file)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment