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 4f081e6
Show file tree
Hide file tree
Showing 3 changed files with 35 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
27 changes: 27 additions & 0 deletions beets/util/collections.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4f081e6

Please sign in to comment.