images: use jpg extensions for jpeg files everywhere

fix #2254
This commit is contained in:
nathdwek@laptop 2016-11-07 16:03:05 +01:00
parent a0877dc092
commit 92ee141662
3 changed files with 35 additions and 1 deletions

View file

@ -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))

View file

@ -59,6 +59,7 @@ import enum
from beets import logging
from beets.util import displayable_path, syspath, as_string
from beets.util.collections import IdentityUnlessDict
import six
@ -81,6 +82,8 @@ TYPES = {
'aiff': 'AIFF',
}
PREFERRED_IMAGE_EXTENSIONS = IdentityUnlessDict({'jpeg': 'jpg'})
# Exceptions.
@ -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.
"""

27
beets/util/collections.py Normal file
View file

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# This file is part of beets.
# Copyright 2016, Adrian Sampson.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
"""Custom collections classes
"""
class IdentityUnlessDict(dict):
"""A dictionary which is "transparent" (maps keys to themselves) for all
keys not in it.
"""
def __getitem__(self, key):
try:
return dict.__getitem__(self, key)
except KeyError:
return key