aboutsummaryrefslogtreecommitdiffstats
path: root/mediagoblin/media_types
diff options
context:
space:
mode:
authorChristopher Allan Webber <cwebber@dustycloud.org>2014-09-16 14:01:43 -0500
committerChristopher Allan Webber <cwebber@dustycloud.org>2014-09-16 14:01:43 -0500
commitf6bad0eb26fa7e092570afe1fb7f38b3d1a1941d (patch)
tree0ca05e7a95cfb30d8b286f3ec72e8c95e212511b /mediagoblin/media_types
parent5b64c92e0816e733c2f88b88ddc0aec070cdc0d3 (diff)
parent1b4e199668ada5c2ec47df7432ab69e315dc0601 (diff)
downloadmediagoblin-f6bad0eb26fa7e092570afe1fb7f38b3d1a1941d.tar.lz
mediagoblin-f6bad0eb26fa7e092570afe1fb7f38b3d1a1941d.tar.xz
mediagoblin-f6bad0eb26fa7e092570afe1fb7f38b3d1a1941d.zip
Merge branch 'master' into merge-python3-port
Has some issues, will iteratively fix! Conflicts: mediagoblin/gmg_commands/__init__.py mediagoblin/gmg_commands/deletemedia.py mediagoblin/gmg_commands/users.py mediagoblin/oauth/views.py mediagoblin/plugins/api/views.py mediagoblin/tests/test_api.py mediagoblin/tests/test_edit.py mediagoblin/tests/test_oauth1.py mediagoblin/tests/test_util.py mediagoblin/tools/mail.py mediagoblin/webfinger/views.py setup.py
Diffstat (limited to 'mediagoblin/media_types')
-rw-r--r--mediagoblin/media_types/audio/config_spec.ini1
-rw-r--r--mediagoblin/media_types/audio/processing.py18
-rw-r--r--mediagoblin/media_types/blog/views.py4
-rw-r--r--mediagoblin/media_types/image/__init__.py6
-rw-r--r--mediagoblin/media_types/raw_image/__init__.py37
-rw-r--r--mediagoblin/media_types/raw_image/models.py21
-rw-r--r--mediagoblin/media_types/raw_image/processing.py82
-rw-r--r--mediagoblin/media_types/video/processing.py11
-rw-r--r--mediagoblin/media_types/video/transcoders.py2
-rw-r--r--mediagoblin/media_types/video/util.py4
10 files changed, 161 insertions, 25 deletions
diff --git a/mediagoblin/media_types/audio/config_spec.ini b/mediagoblin/media_types/audio/config_spec.ini
index 743deaa4..bc1810f7 100644
--- a/mediagoblin/media_types/audio/config_spec.ini
+++ b/mediagoblin/media_types/audio/config_spec.ini
@@ -2,7 +2,6 @@
keep_original = boolean(default=True)
# vorbisenc quality
quality = float(default=0.3)
-create_spectrogram = boolean(default=True)
spectrogram_fft_size = integer(default=4096)
diff --git a/mediagoblin/media_types/audio/processing.py b/mediagoblin/media_types/audio/processing.py
index f12f231e..c4ed4eca 100644
--- a/mediagoblin/media_types/audio/processing.py
+++ b/mediagoblin/media_types/audio/processing.py
@@ -251,32 +251,24 @@ class InitialProcessor(CommonAudioProcessor):
type=int,
help='The width of the spectogram')
- parser.add_argument(
- '--create_spectrogram',
- action='store_true',
- help='Create spectogram and thumbnail, will default to config')
-
return parser
@classmethod
def args_to_request(cls, args):
return request_from_args(
- args, ['create_spectrogram', 'quality', 'fft_size',
+ args, ['quality', 'fft_size',
'thumb_size', 'medium_width'])
def process(self, quality=None, fft_size=None, thumb_size=None,
- create_spectrogram=None, medium_width=None):
+ medium_width=None):
self.common_setup()
- if not create_spectrogram:
- create_spectrogram = self.audio_config['create_spectrogram']
-
self.transcode(quality=quality)
self.copy_original()
- if create_spectrogram:
- self.create_spectrogram(max_width=medium_width, fft_size=fft_size)
- self.generate_thumb(size=thumb_size)
+ self.create_spectrogram(max_width=medium_width, fft_size=fft_size)
+ self.generate_thumb(size=thumb_size)
+
self.delete_queue_file()
diff --git a/mediagoblin/media_types/blog/views.py b/mediagoblin/media_types/blog/views.py
index 3a4dfe6a..0b88037f 100644
--- a/mediagoblin/media_types/blog/views.py
+++ b/mediagoblin/media_types/blog/views.py
@@ -261,8 +261,8 @@ def blog_post_listing(request, page, url_user=None):
"""
Page, listing all the blog posts of a particular blog.
"""
- blog_slug = request.matchdict.get('blog_slug', None)
- blog = get_blog_by_slug(request, blog_slug, author=request.user.id)
+ blog_slug = request.matchdict['blog_slug']
+ blog = get_blog_by_slug(request, blog_slug, author=url_user.id)
if not blog:
return render_404(request)
diff --git a/mediagoblin/media_types/image/__init__.py b/mediagoblin/media_types/image/__init__.py
index f5b49f01..11f90ca5 100644
--- a/mediagoblin/media_types/image/__init__.py
+++ b/mediagoblin/media_types/image/__init__.py
@@ -20,15 +20,12 @@ from mediagoblin.media_types import MediaManagerBase
from mediagoblin.media_types.image.processing import sniff_handler, \
ImageProcessingManager
-
_log = logging.getLogger(__name__)
-ACCEPTED_EXTENSIONS = ["jpg", "jpeg", "png", "gif", "tiff"]
+ACCEPTED_EXTENSIONS = ["jpe", "jpg", "jpeg", "png", "gif", "tiff"]
MEDIA_TYPE = 'mediagoblin.media_types.image'
-def setup_plugin():
- config = pluginapi.get_config(MEDIA_TYPE)
class ImageMediaManager(MediaManagerBase):
human_readable = "Image"
@@ -58,7 +55,6 @@ class ImageMediaManager(MediaManagerBase):
except (KeyError, ValueError):
return None
-
def get_media_type_and_manager(ext):
if ext in ACCEPTED_EXTENSIONS:
return MEDIA_TYPE, ImageMediaManager
diff --git a/mediagoblin/media_types/raw_image/__init__.py b/mediagoblin/media_types/raw_image/__init__.py
new file mode 100644
index 00000000..046a9b2a
--- /dev/null
+++ b/mediagoblin/media_types/raw_image/__init__.py
@@ -0,0 +1,37 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2014 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from mediagoblin.media_types.image import ImageMediaManager
+from mediagoblin.media_types.raw_image.processing import (
+ ACCEPTED_EXTENSIONS, MEDIA_TYPE,
+ RawImageProcessingManager, sniff_handler)
+
+
+class RawImageMediaManager(ImageMediaManager):
+ human_readable = "Raw image"
+
+
+def get_media_type_and_manager(ext):
+ if ext in ACCEPTED_EXTENSIONS:
+ return MEDIA_TYPE, RawImageMediaManager
+
+
+hooks = {
+ 'get_media_type_and_manager': get_media_type_and_manager,
+ 'sniff_handler': sniff_handler,
+ ('media_manager', MEDIA_TYPE): lambda: RawImageMediaManager,
+ ('reprocess_manager', MEDIA_TYPE): lambda: RawImageProcessingManager,
+}
diff --git a/mediagoblin/media_types/raw_image/models.py b/mediagoblin/media_types/raw_image/models.py
new file mode 100644
index 00000000..d3d68b93
--- /dev/null
+++ b/mediagoblin/media_types/raw_image/models.py
@@ -0,0 +1,21 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2014 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from mediagoblin.media_types.image.models import (
+ BACKREF_NAME, DATA_MODEL)
+
+
+MODELS = None
diff --git a/mediagoblin/media_types/raw_image/processing.py b/mediagoblin/media_types/raw_image/processing.py
new file mode 100644
index 00000000..5ff54cf3
--- /dev/null
+++ b/mediagoblin/media_types/raw_image/processing.py
@@ -0,0 +1,82 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2014 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+import logging
+
+# This needs to handle the case where it's missing
+import pyexiv2
+
+from mediagoblin.media_types.image.processing import (
+ InitialProcessor, Resizer)
+from mediagoblin.processing import (
+ FilenameBuilder, ProcessingManager)
+
+
+_log = logging.getLogger(__name__)
+
+MEDIA_TYPE = 'mediagoblin.media_types.raw_image'
+ACCEPTED_EXTENSIONS = ['nef', 'cr2']
+
+
+# The entire function have to be copied
+
+def sniff_handler(media_file, filename):
+ _log.info('Sniffing {0}'.format(MEDIA_TYPE))
+ name, ext = os.path.splitext(filename)
+ clean_ext = ext[1:].lower() # Strip the . from ext and make lowercase
+
+ if clean_ext in ACCEPTED_EXTENSIONS:
+ _log.info('Found file extension in supported filetypes')
+ return MEDIA_TYPE
+ else:
+ _log.debug('Media present, extension not found in {0}'.format(
+ ACCEPTED_EXTENSIONS))
+
+ return None
+
+
+class InitialRawProcessor(InitialProcessor):
+ def common_setup(self):
+ """
+ Pull out a full-size JPEG-preview
+ """
+ super(self.__class__, self).common_setup()
+
+ self._original_raw = self.process_filename
+
+ # Read EXIF data
+ md = pyexiv2.ImageMetadata(self._original_raw)
+ md.read()
+ self.process_filename = os.path.join(self.conversions_subdir,
+ self.entry.queued_media_file[-1])
+
+ # Extract the biggest preview and write it as our working image
+ md.previews[-1].write_to_file(
+ self.process_filename.encode('utf-8'))
+ self.process_filename += '.jpg'
+ _log.debug(u'Wrote new file from {0} to preview (jpg) {1}'.format(
+ self._original_raw, self.process_filename))
+
+ # Override the namebuilder with our new jpg-based name
+ self.name_builder = FilenameBuilder(self.process_filename)
+
+
+class RawImageProcessingManager(ProcessingManager):
+ def __init__(self):
+ super(self.__class__, self).__init__()
+ self.add_processor(InitialRawProcessor)
+ self.add_processor(Resizer)
diff --git a/mediagoblin/media_types/video/processing.py b/mediagoblin/media_types/video/processing.py
index abd5f36e..a7716592 100644
--- a/mediagoblin/media_types/video/processing.py
+++ b/mediagoblin/media_types/video/processing.py
@@ -44,7 +44,16 @@ class VideoTranscodingFail(BaseProcessingFail):
general_message = _(u'Video transcoding failed')
+EXCLUDED_EXTS = ["nef", "cr2"]
+
def sniff_handler(media_file, filename):
+ name, ext = os.path.splitext(filename)
+ clean_ext = ext.lower()[1:]
+
+ if clean_ext in EXCLUDED_EXTS:
+ # We don't handle this filetype, though gstreamer might think we can
+ return None
+
transcoder = transcoders.VideoTranscoder()
data = transcoder.discover(media_file.name)
@@ -109,7 +118,7 @@ def store_metadata(media_entry, metadata):
dt.get_minute(), dt.get_second(),
dt.get_microsecond()).isoformat()
- metadata['tags'] = tags
+ stored_metadata['tags'] = tags
# Only save this field if there's something to save
if len(stored_metadata):
diff --git a/mediagoblin/media_types/video/transcoders.py b/mediagoblin/media_types/video/transcoders.py
index 9d6b7655..3a3fa97f 100644
--- a/mediagoblin/media_types/video/transcoders.py
+++ b/mediagoblin/media_types/video/transcoders.py
@@ -186,7 +186,7 @@ from playbin')
self.buffer_probes = {}
pipeline = ''.join([
- 'filesrc location="%s" ! decodebin ! ' % self.source_path,
+ 'filesrc location="%s" ! decodebin2 ! ' % self.source_path,
'ffmpegcolorspace ! videoscale ! ',
'video/x-raw-rgb,depth=24,bpp=24,pixel-aspect-ratio=1/1',
',width={0}'.format(self.width) if self.width else '',
diff --git a/mediagoblin/media_types/video/util.py b/mediagoblin/media_types/video/util.py
index beb10129..29b7f410 100644
--- a/mediagoblin/media_types/video/util.py
+++ b/mediagoblin/media_types/video/util.py
@@ -38,11 +38,11 @@ def skip_transcode(metadata, size):
if not metadata['mimetype'] in config['mime_types']:
return False
- if config['container_formats'] and metadata['tags'].get('audio-codec'):
+ if config['container_formats'] and metadata['tags'].get('container-format'):
if not metadata['tags']['container-format'] in config['container_formats']:
return False
- if config['video_codecs'] and metadata['tags'].get('audio-codec'):
+ if config['video_codecs'] and metadata['tags'].get('video-codec'):
if not metadata['tags']['video-codec'] in config['video_codecs']:
return False