1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011 Free Software Foundation, Inc
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 from celery
.task
import task
21 from mediagoblin
.globals import database
, queue_store
, public_store
28 def process_media_initial(media_id
):
29 entry
= database
.MediaEntry
.one(
30 {'_id': mongokit
.ObjectId(media_id
)})
32 queued_filepath
= entry
['queue_files'].pop()
33 queued_file
= queue_store
.get_file(queued_filepath
, 'r')
36 thumb
= Image(queued_file
)
37 thumb
.thumbnail(THUMB_SIZE
, Image
.ANTIALIAS
)
39 thumb_filepath
= public_store
.get_unique_filepath(
41 unicode(entry
['_id']),
44 with public_store
.get_file(thumb_filepath
, 'w') as thumb_file
:
45 thumb
.save(thumb_file
, "JPEG")
47 queue_store
.delete(queued_filepath
)
48 entry
.setdefault('media_files', []).append(thumb_filepath
)
49 entry
.state
= 'processed'