Media type refractors, pep8, lint
- Removed THUMB_SIZE, MEDIUM_SIZE constants, depend on configuration values instead. - pep8 refractoring
This commit is contained in:
parent
a9d84d4cb7
commit
c56d4b55a1
@ -23,6 +23,7 @@ import os
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class AsciiToImage(object):
|
||||
'''
|
||||
Converter of ASCII art into image files, preserving whitespace
|
||||
|
@ -19,13 +19,14 @@ import Image
|
||||
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)
|
||||
@ -36,6 +37,7 @@ def sniff_handler(media_file, **kw):
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def process_ascii(entry):
|
||||
'''
|
||||
Code to process a txt file
|
||||
@ -81,7 +83,10 @@ def process_ascii(entry):
|
||||
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')
|
||||
@ -96,7 +101,6 @@ def process_ascii(entry):
|
||||
as original_file:
|
||||
original_file.write(queued_file.read())
|
||||
|
||||
|
||||
queued_file.seek(0) # Rewind *again*
|
||||
|
||||
unicode_filepath = create_pub_filepath(entry, 'ascii-portable.txt')
|
||||
|
@ -24,7 +24,7 @@ from mediagoblin.media_types.audio import audioprocessing
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
|
||||
CPU_COUNT = 2 # Just assuming for now
|
||||
CPU_COUNT = 2 # Just assuming for now
|
||||
|
||||
# IMPORT MULTIPROCESSING
|
||||
try:
|
||||
@ -60,6 +60,7 @@ except ImportError:
|
||||
|
||||
import numpy
|
||||
|
||||
|
||||
class AudioThumbnailer(object):
|
||||
def __init__(self):
|
||||
_log.info('Initializing {0}'.format(self.__class__.__name__))
|
||||
@ -178,7 +179,7 @@ class AudioTranscoder(object):
|
||||
|
||||
# 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} ! '
|
||||
|
@ -20,7 +20,7 @@ import logging
|
||||
|
||||
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
|
||||
|
||||
@ -28,6 +28,7 @@ _log = logging.getLogger(__name__)
|
||||
|
||||
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)
|
||||
@ -50,6 +51,7 @@ def sniff_handler(media_file, **kw):
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def process_image(entry):
|
||||
"""
|
||||
Code to process an image
|
||||
@ -80,7 +82,10 @@ def process_image(entry):
|
||||
|
||||
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
|
||||
@ -103,8 +108,12 @@ def process_image(entry):
|
||||
# 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)
|
||||
@ -124,7 +133,7 @@ def process_image(entry):
|
||||
|
||||
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:
|
||||
|
@ -19,8 +19,7 @@ import logging
|
||||
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()
|
||||
@ -28,6 +27,7 @@ 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)
|
||||
@ -44,6 +44,7 @@ def sniff_handler(media_file, **kw):
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def process_video(entry):
|
||||
"""
|
||||
Process a video entry, transcode the queued media files (originals) and
|
||||
@ -62,13 +63,12 @@ def process_video(entry):
|
||||
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()
|
||||
|
||||
|
@ -21,7 +21,6 @@ os.putenv('GST_DEBUG_DUMP_DOT_DIR', '/tmp')
|
||||
|
||||
import sys
|
||||
import logging
|
||||
import pdb
|
||||
import urllib
|
||||
|
||||
_log = logging.getLogger(__name__)
|
||||
@ -267,7 +266,7 @@ class VideoThumbnailer:
|
||||
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)
|
||||
|
||||
@ -317,12 +316,11 @@ class VideoThumbnailer:
|
||||
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()
|
||||
|
||||
|
||||
@ -454,7 +452,7 @@ class VideoTranscoder:
|
||||
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)
|
||||
@ -548,7 +546,6 @@ class VideoTranscoder:
|
||||
# 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
|
||||
@ -593,11 +590,11 @@ class VideoTranscoder:
|
||||
|
||||
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)
|
||||
|
||||
@ -619,7 +616,6 @@ class VideoTranscoder:
|
||||
|
||||
self.dst_discoverer.discover()
|
||||
|
||||
|
||||
def __dst_discovered(self, data, is_media):
|
||||
self.dst_data = data
|
||||
|
||||
@ -694,4 +690,3 @@ if __name__ == '__main__':
|
||||
transcoder.transcode(*args, progress_callback=cb)
|
||||
elif options.action == 'discover':
|
||||
print transcoder.discover(*args).__dict__
|
||||
|
||||
|
@ -27,14 +27,6 @@ from mediagoblin.media_types import get_media_manager
|
||||
|
||||
_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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user