aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/process_media/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'mediagoblin/process_media/__init__.py')
-rw-r--r--mediagoblin/process_media/__init__.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/mediagoblin/process_media/__init__.py b/mediagoblin/process_media/__init__.py
index 531eb16d..0dce1418 100644
--- a/mediagoblin/process_media/__init__.py
+++ b/mediagoblin/process_media/__init__.py
@@ -18,22 +18,29 @@ import Image
from mediagoblin.db.util import ObjectId
from celery.task import task
-from mediagoblin import globals as mg_globals
+from mediagoblin import mg_globals as mgg
THUMB_SIZE = 200, 200
+def create_pub_filepath(entry, filename):
+ return mgg.public_store.get_unique_filepath(
+ ['media_entries',
+ unicode(entry['_id']),
+ filename])
+
+
@task
def process_media_initial(media_id):
- workbench = mg_globals.workbench_manager.create_workbench()
+ workbench = mgg.workbench_manager.create_workbench()
- entry = mg_globals.database.MediaEntry.one(
+ entry = mgg.database.MediaEntry.one(
{'_id': ObjectId(media_id)})
queued_filepath = entry['queued_media_file']
- queued_filename = mg_globals.workbench_manager.localized_file(
- workbench, mg_globals.queue_store, queued_filepath,
+ queued_filename = workbench.localized_file(
+ mgg.queue_store, queued_filepath,
'source')
queued_file = file(queued_filename, 'r')
@@ -41,13 +48,13 @@ def process_media_initial(media_id):
with queued_file:
thumb = Image.open(queued_file)
thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
+ # ensure color mode is compatible with jpg
+ if thumb.mode != "RGB":
+ thumb = thumb.convert("RGB")
- thumb_filepath = mg_globals.public_store.get_unique_filepath(
- ['media_entries',
- unicode(entry['_id']),
- 'thumbnail.jpg'])
+ thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg')
- thumb_file = mg_globals.public_store.get_file(thumb_filepath, 'w')
+ thumb_file = mgg.public_store.get_file(thumb_filepath, 'w')
with thumb_file:
thumb.save(thumb_file, "JPEG")
@@ -56,15 +63,13 @@ def process_media_initial(media_id):
queued_file = file(queued_filename, 'rb')
with queued_file:
- main_filepath = mg_globals.public_store.get_unique_filepath(
- ['media_entries',
- unicode(entry['_id']),
- queued_filepath[-1]])
+ main_filepath = create_pub_filepath(entry, queued_filepath[-1])
- with mg_globals.public_store.get_file(main_filepath, 'wb') as main_file:
+ with mgg.public_store.get_file(main_filepath, 'wb') as main_file:
main_file.write(queued_file.read())
- mg_globals.queue_store.delete_file(queued_filepath)
+ mgg.queue_store.delete_file(queued_filepath)
+ entry['queued_media_file'] = []
media_files_dict = entry.setdefault('media_files', {})
media_files_dict['thumb'] = thumb_filepath
media_files_dict['main'] = main_filepath
@@ -72,4 +77,4 @@ def process_media_initial(media_id):
entry.save()
# clean up workbench
- mg_globals.workbench_manager.destroy_workbench(workbench)
+ workbench.destroy_self()