src/pyams_media/media.py
changeset 41 509aefe2f45c
parent 22 b5da674fd06c
child 46 55d5fde71e8f
--- 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...