1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2014 MediaGoblin contributors. See AUTHORS.
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/>.
20 # This needs to handle the case where it's missing
23 from mediagoblin
.media_types
.image
.processing
import (
24 InitialProcessor
, Resizer
)
25 from mediagoblin
.processing
import (
26 FilenameBuilder
, ProcessingManager
)
29 _log
= logging
.getLogger(__name__
)
31 MEDIA_TYPE
= 'mediagoblin.media_types.raw_image'
32 ACCEPTED_EXTENSIONS
= ['nef', 'cr2']
35 # The entire function have to be copied
37 def sniff_handler(media_file
, filename
):
38 _log
.info('Sniffing {0}'.format(MEDIA_TYPE
))
39 name
, ext
= os
.path
.splitext(filename
)
40 clean_ext
= ext
[1:].lower() # Strip the . from ext and make lowercase
42 if clean_ext
in ACCEPTED_EXTENSIONS
:
43 _log
.info('Found file extension in supported filetypes')
46 _log
.debug('Media present, extension not found in {0}'.format(
52 class InitialRawProcessor(InitialProcessor
):
53 def common_setup(self
):
55 Pull out a full-size JPEG-preview
57 super(InitialRawProcessor
, self
).common_setup()
59 self
._original
_raw
= self
.process_filename
62 md
= pyexiv2
.ImageMetadata(self
._original
_raw
)
64 self
.process_filename
= os
.path
.join(self
.conversions_subdir
,
65 self
.entry
.queued_media_file
[-1])
67 # Extract the biggest preview and write it as our working image
68 md
.previews
[-1].write_to_file(
69 self
.process_filename
.encode('utf-8'))
70 self
.process_filename
+= '.jpg'
71 _log
.debug(u
'Wrote new file from {0} to preview (jpg) {1}'.format(
72 self
._original
_raw
, self
.process_filename
))
74 # Override the namebuilder with our new jpg-based name
75 self
.name_builder
= FilenameBuilder(self
.process_filename
)
78 class RawImageProcessingManager(ProcessingManager
):
80 super(RawImageProcessingManager
, self
).__init
__()
81 self
.add_processor(InitialRawProcessor
)
82 self
.add_processor(Resizer
)
84 def workflow(self
, entry
, manager
, feed_url
, reprocess_action
,
86 ProcessMedia().apply_async(
87 [entry
.id, feed_url
, reprocess_action
, reprocess_info
], {},
88 task_id
=entry
.queued_task_id
)