return hasattr(self, i)
-def sniff_media(media):
+def sniff_media(media_file, filename):
'''
Iterate through the enabled media types and find those suited
for a certain file.
'''
try:
- return get_media_type_and_manager(media.filename)
+ return get_media_type_and_manager(filename)
except FileTypeNotSupported:
_log.info('No media handler found by file extension. Doing it the expensive way...')
# Create a temporary file for sniffers suchs as GStreamer-based
# Audio video
- media_file = tempfile.NamedTemporaryFile()
- media_file.write(media.stream.read())
- media.stream.seek(0)
+ tmp_media_file = tempfile.NamedTemporaryFile()
+ tmp_media_file.write(media_file.read())
+ tmp_media_file.seek(0)
- media_type = hook_handle('sniff_handler', media_file, media=media)
+ media_type = hook_handle('sniff_handler', tmp_media_file, filename)
if media_type:
_log.info('{0} accepts the file'.format(media_type))
return media_type, hook_handle(('media_manager', media_type))
MEDIA_TYPE = 'mediagoblin.media_types.ascii'
-def sniff_handler(media_file, **kw):
+def sniff_handler(media_file, filename):
_log.info('Sniffing {0}'.format(MEDIA_TYPE))
- if kw.get('media') is not None:
- name, ext = os.path.splitext(kw['media'].filename)
- clean_ext = ext[1:].lower()
- if clean_ext in SUPPORTED_EXTENSIONS:
- return MEDIA_TYPE
+ name, ext = os.path.splitext(filename)
+ clean_ext = ext[1:].lower()
+
+ if clean_ext in SUPPORTED_EXTENSIONS:
+ return MEDIA_TYPE
return None
MEDIA_TYPE = 'mediagoblin.media_types.audio'
-def sniff_handler(media_file, **kw):
+def sniff_handler(media_file, filename):
_log.info('Sniffing {0}'.format(MEDIA_TYPE))
try:
transcoder = AudioTranscoder()
SUPPORTED_FILETYPES = ['png', 'gif', 'jpg', 'jpeg', 'tiff']
-def sniff_handler(media_file, **kw):
+def sniff_handler(media_file, filename):
_log.info('Sniffing {0}'.format(MEDIA_TYPE))
- if kw.get('media') is not None: # That's a double negative!
- name, ext = os.path.splitext(kw['media'].filename)
- clean_ext = ext[1:].lower() # Strip the . from ext and make lowercase
-
- if clean_ext in SUPPORTED_FILETYPES:
- _log.info('Found file extension in supported filetypes')
- return MEDIA_TYPE
- else:
- _log.debug('Media present, extension not found in {0}'.format(
- SUPPORTED_FILETYPES))
+ name, ext = os.path.splitext(filename)
+ clean_ext = ext[1:].lower() # Strip the . from ext and make lowercase
+
+ if clean_ext in SUPPORTED_FILETYPES:
+ _log.info('Found file extension in supported filetypes')
+ return MEDIA_TYPE
else:
- _log.warning('Need additional information (keyword argument \'media\')'
- ' to be able to handle sniffing')
+ _log.debug('Media present, extension not found in {0}'.format(
+ SUPPORTED_FILETYPES))
return None
return False
return True
-def sniff_handler(media_file, **kw):
+def sniff_handler(media_file, filename):
_log.info('Sniffing {0}'.format(MEDIA_TYPE))
if not check_prerequisites():
return None
- if kw.get('media') is not None:
- name, ext = os.path.splitext(kw['media'].filename)
- clean_ext = ext[1:].lower()
- if clean_ext in supported_extensions():
- return MEDIA_TYPE
+ name, ext = os.path.splitext(filename)
+ clean_ext = ext[1:].lower()
- return None
+ if clean_ext in supported_extensions():
+ return MEDIA_TYPE
def create_pdf_thumb(original, thumb_filename, width, height):
# Note: pdftocairo adds '.png', remove it
'blender_render.py'))
-def sniff_handler(media_file, **kw):
+def sniff_handler(media_file, filename):
_log.info('Sniffing {0}'.format(MEDIA_TYPE))
- if kw.get('media') is not None:
- name, ext = os.path.splitext(kw['media'].filename)
- clean_ext = ext[1:].lower()
- if clean_ext in SUPPORTED_FILETYPES:
- _log.info('Found file extension in supported filetypes')
- return MEDIA_TYPE
- else:
- _log.debug('Media present, extension not found in {0}'.format(
- SUPPORTED_FILETYPES))
+ name, ext = os.path.splitext(filename)
+ clean_ext = ext[1:].lower()
+
+ if clean_ext in SUPPORTED_FILETYPES:
+ _log.info('Found file extension in supported filetypes')
+ return MEDIA_TYPE
else:
- _log.warning('Need additional information (keyword argument \'media\')'
- ' to be able to handle sniffing')
+ _log.debug('Media present, extension not found in {0}'.format(
+ SUPPORTED_FILETYPES))
return None
general_message = _(u'Video transcoding failed')
-def sniff_handler(media_file, **kw):
+def sniff_handler(media_file, filename):
transcoder = transcoders.VideoTranscoder()
data = transcoder.discover(media_file.name)
_log.debug('Discovered: {0}'.format(data))
if not data:
- _log.error('Could not discover {0}'.format(
- kw.get('media')))
+ _log.error('Could not discover {0}'.format(filename))
return None
if data['is_video'] is True:
# Sniff the submitted media to determine which
# media plugin should handle processing
- media_type, media_manager = sniff_media(submitted_file)
+ media_type, media_manager = sniff_media(submitted_file, filename)
# create entry and save in database
entry = new_upload_entry(user)
queue_file = prepare_queue_task(mg_app, entry, filename)
with queue_file:
- queue_file.write(submitted_file.stream.read())
+ queue_file.write(submitted_file.read())
# Get file size and round to 2 decimal places
file_size = mg_app.queue_store.get_file_size(