_log = logging.getLogger(__name__)
+
class AsciiToImage(object):
'''
Converter of ASCII art into image files, preserving whitespace
import logging
from mediagoblin import mg_globals as mgg
-from mediagoblin.processing import create_pub_filepath, THUMB_SIZE
+from mediagoblin.processing import create_pub_filepath
from mediagoblin.media_types.ascii import asciitoimage
_log = logging.getLogger(__name__)
SUPPORTED_EXTENSIONS = ['txt', 'asc', 'nfo']
+
def sniff_handler(media_file, **kw):
if kw.get('media') is not None:
name, ext = os.path.splitext(kw['media'].filename)
return False
+
def process_ascii(entry):
'''
Code to process a txt file
queued_file.read())
with file(tmp_thumb_filename, 'w') as thumb_file:
- thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
+ thumb.thumbnail(
+ (mgg.global_config['media:thumb']['max_width'],
+ mgg.global_config['media:thumb']['max_height']),
+ Image.ANTIALIAS)
thumb.save(thumb_file)
_log.debug('Copying local file to public storage')
as original_file:
original_file.write(queued_file.read())
-
queued_file.seek(0) # Rewind *again*
unicode_filepath = create_pub_filepath(entry, 'ascii-portable.txt')
_log = logging.getLogger(__name__)
-CPU_COUNT = 2 # Just assuming for now
+CPU_COUNT = 2 # Just assuming for now
# IMPORT MULTIPROCESSING
try:
import numpy
+
class AudioThumbnailer(object):
def __init__(self):
_log.info('Initializing {0}'.format(self.__class__.__name__))
# Set up pipeline
self.pipeline = gst.parse_launch(
- 'filesrc location="{src}" ! '
+ 'filesrc location="{src}" ! '
'decodebin2 ! queue ! audiorate tolerance={tolerance} ! '
'audioconvert ! audio/x-raw-float,channels=2 ! '
'{mux_string} ! '
from mediagoblin import mg_globals as mgg
from mediagoblin.processing import BadMediaFail, \
- create_pub_filepath, THUMB_SIZE, MEDIUM_SIZE
+ create_pub_filepath
from mediagoblin.tools.exif import exif_fix_image_orientation, \
extract_exif, clean_exif, get_gps_data, get_useful
SUPPORTED_FILETYPES = ['png', 'gif', 'jpg', 'jpeg']
+
def sniff_handler(media_file, **kw):
if kw.get('media') is not None: # That's a double negative!
name, ext = os.path.splitext(kw['media'].filename)
return False
+
def process_image(entry):
"""
Code to process an image
thumb = exif_fix_image_orientation(thumb, exif_tags)
- thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
+ thumb.thumbnail(
+ (mgg.global_config['media:thumb']['max_width'],
+ mgg.global_config['media:thumb']['max_height']),
+ Image.ANTIALIAS)
# Copy the thumb to the conversion subdir, then remotely.
thumb_filename = 'thumbnail' + extension
# Fix orientation
medium = exif_fix_image_orientation(medium, exif_tags)
- if medium.size[0] > MEDIUM_SIZE[0] or medium.size[1] > MEDIUM_SIZE[1]:
- medium.thumbnail(MEDIUM_SIZE, Image.ANTIALIAS)
+ if medium.size[0] > mgg.global_config['media:medium']['max_width'] \
+ or medium.size[1] > mgg.global_config['media:medium']['max_height']:
+ medium.thumbnail(
+ (mgg.global_config['media:medium']['max_width'],
+ mgg.global_config['media:medium']['max_height']),
+ Image.ANTIALIAS)
medium_filename = 'medium' + extension
medium_filepath = create_pub_filepath(entry, medium_filename)
with queued_file:
#create_pub_filepath(entry, queued_filepath[-1])
- original_filepath = create_pub_filepath(entry, basename + extension)
+ original_filepath = create_pub_filepath(entry, basename + extension)
with mgg.public_store.get_file(original_filepath, 'wb') \
as original_file:
import os
from mediagoblin import mg_globals as mgg
-from mediagoblin.processing import mark_entry_failed, \
- THUMB_SIZE, MEDIUM_SIZE, create_pub_filepath
+from mediagoblin.processing import create_pub_filepath
from . import transcoders
logging.basicConfig()
_log = logging.getLogger(__name__)
_log.setLevel(logging.DEBUG)
+
def sniff_handler(media_file, **kw):
transcoder = transcoders.VideoTranscoder()
data = transcoder.discover(media_file.name)
return False
+
def process_video(entry):
"""
Process a video entry, transcode the queued media files (originals) and
entry,
'{original}-640p.webm'.format(
original=os.path.splitext(
- queued_filepath[-1])[0] # Select the file name without .ext
+ queued_filepath[-1])[0] # Select the file name without .ext
))
thumbnail_filepath = create_pub_filepath(
entry, 'thumbnail.jpg')
-
# Create a temporary file for the video destination
tmp_dst = tempfile.NamedTemporaryFile()
import sys
import logging
-import pdb
import urllib
_log = logging.getLogger(__name__)
return 0
try:
- return pipeline.query_duration(gst.FORMAT_TIME)[0]
+ return pipeline.query_duration(gst.FORMAT_TIME)[0]
except gst.QueryError:
return self._get_duration(pipeline, retries + 1)
self.bus.disconnect(self.watch_id)
self.bus = None
-
def __halt_final(self):
_log.info('Done')
if self.errors:
_log.error(','.join(self.errors))
-
+
self.loop.quit()
self.ffmpegcolorspace = gst.element_factory_make(
'ffmpegcolorspace', 'ffmpegcolorspace')
self.pipeline.add(self.ffmpegcolorspace)
-
+
self.videoscale = gst.element_factory_make('ffvideoscale', 'videoscale')
#self.videoscale.set_property('method', 2) # I'm not sure this works
#self.videoscale.set_property('add-borders', 0)
# Setup the message bus and connect _on_message to the pipeline
self._setup_bus()
-
def _on_dynamic_pad(self, dbin, pad, islast):
'''
Callback called when ``decodebin2`` has a pad that we can connect to
t = message.type
- if t == gst.MESSAGE_EOS:
+ if message.type == gst.MESSAGE_EOS:
self._discover_dst_and_stop()
_log.info('Done')
- elif t == gst.MESSAGE_ELEMENT:
+ elif message.type == gst.MESSAGE_ELEMENT:
if message.structure.get_name() == 'progress':
data = dict(message.structure)
self.dst_discoverer.discover()
-
def __dst_discovered(self, data, is_media):
self.dst_data = data
transcoder.transcode(*args, progress_callback=cb)
elif options.action == 'discover':
print transcoder.discover(*args).__dict__
-
_log = logging.getLogger(__name__)
-# This might fail if this module is loaded before the global_config
-# is parsed although this far it has not.
-THUMB_SIZE = (mgg.global_config['media:thumb']['max_width'],
- mgg.global_config['media:thumb']['max_height'])
-
-MEDIUM_SIZE = (mgg.global_config['media:medium']['max_width'],
- mgg.global_config['media:medium']['max_height'])
-
def create_pub_filepath(entry, filename):
return mgg.public_store.get_unique_filepath(