Skip to content

Commit

Permalink
images: use jpg extensions for jpeg files everywhere
Browse files Browse the repository at this point in the history
fix #2254
  • Loading branch information
nathdwek@laptop committed Nov 7, 2016
1 parent 4f6e0d1 commit 767519d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion beets/art.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def extract(log, outpath, item):
return

# Add an extension to the filename.
ext = imghdr.what(None, h=art)
ext = mediafile.image_extension(art)
if not ext:
log.warning(u'Unknown image type in {0}.',
displayable_path(item.path))
Expand Down
7 changes: 7 additions & 0 deletions beets/mediafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@

from beets import logging
from beets.util import displayable_path, syspath, as_string
from beets.util.collections import IdentityUnlessDict
import six


Expand All @@ -81,6 +82,8 @@
'aiff': 'AIFF',
}

PREFERRED_IMAGE_EXTENSIONS = IdentityUnlessDict({'jpeg': 'jpg'})


# Exceptions.

Expand Down Expand Up @@ -351,6 +354,10 @@ def image_mime_type(data):
return 'image/x-{0}'.format(kind)


def image_extension(data):
return PREFERRED_IMAGE_EXTENSIONS[_imghdr_what_wrapper(data)]


class ImageType(enum.Enum):
"""Indicates the kind of an `Image` stored in a file's tag.
"""
Expand Down
6 changes: 6 additions & 0 deletions beets/util/collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class IdentityUnlessDict(dict):
def __getitem__(self, key):
try:
return dict.__getitem__(self, key)
except KeyError:
return key

0 comments on commit 767519d

Please sign in to comment.