# HG changeset patch # User Thierry Florac # Date 1496820495 -7200 # Node ID 509aefe2f45c759a2f9eb0715e05987b2fcc43b9 # Parent 0ee62085ea827a9d09a44f102ba14555ad974de2 Add check to know if content_type is defined as bytes or string diff -r 0ee62085ea82 -r 509aefe2f45c src/pyams_media/media.py --- a/src/pyams_media/media.py Tue May 16 11:16:15 2017 +0200 +++ b/src/pyams_media/media.py Wed Jun 07 09:28:15 2017 +0200 @@ -52,9 +52,12 @@ @adapter_config(context=IFile, provides=IMediaInfo) def MediaInfoFactory(context): """Media info adapter""" - if not (context.content_type.startswith(b'audio/') or - context.content_type.startswith(b'video/') or - context.content_type in (CUSTOM_AUDIO_TYPES + CUSTOM_VIDEO_TYPES)): + content_type = context.content_type + if isinstance(content_type, bytes): + content_type = content_type.decode() + if not (content_type.startswith('audio/') or + content_type.startswith('video/') or + content_type in (CUSTOM_AUDIO_TYPES + CUSTOM_VIDEO_TYPES)): return None annotations = IAnnotations(context) info = annotations.get(MEDIA_INFO_KEY) @@ -161,7 +164,9 @@ # Don't convert images or already converted files! if IMediaConversion.providedBy(media): return - content_type = media.content_type.decode() if media.content_type else None + content_type = media.content_type + if isinstance(content_type, bytes): + content_type = content_type.decode() if (not content_type) or content_type.startswith('image/'): return # Try to use FFMpeg if content type is unknown... diff -r 0ee62085ea82 -r 509aefe2f45c src/pyams_media/utility.py --- a/src/pyams_media/utility.py Tue May 16 11:16:15 2017 +0200 +++ b/src/pyams_media/utility.py Wed Jun 07 09:28:15 2017 +0200 @@ -50,7 +50,9 @@ def check_media_conversion(self, media): """Check if conversion is needed for given media""" - content_type = media.content_type.decode() if media.content_type else None + content_type = media.content_type + if isinstance(content_type, bytes): + content_type = content_type.decode() if self.audio_formats and \ (content_type.startswith('audio/') or (content_type in CUSTOM_AUDIO_TYPES)): requested_formats = self.audio_formats