# HG changeset patch # User Thierry Florac # Date 1441722093 -7200 # Node ID 5410acbcfb775c4b9d5a103e1d7a6f0759aad1a6 # Parent 1ade73c9f2c0352c6aff178445e961a8edcd470c Added small videos conversions dashboard diff -r 1ade73c9f2c0 -r 5410acbcfb77 src/pyams_media/zmi/media.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_media/zmi/media.py Tue Sep 08 16:21:33 2015 +0200 @@ -0,0 +1,98 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# +from pyams_file.interfaces import IMediaFile, IVideo, IThumbnail +from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager +from pyams_media.ffbase import FFmpeg +from pyams_media.ffdocument import FFDocument +from pyams_media.interfaces import IMediaConversionUtility, VIDEO_FRAME_SIZE, IMediaConverter, IMediaConversions +from pyams_pagelet.pagelet import pagelet_config +from pyams_skin.interfaces.viewlet import IContextActions +from pyams_skin.layer import IPyAMSLayer +from pyams_skin.viewlet.toolbar import ToolbarMenuItem +from pyams_template.template import template_config +from pyams_utils.property import cached_property +from pyams_utils.registry import query_utility +from pyams_viewlet.viewlet import viewlet_config, Viewlet +from pyams_zmi.form import AdminDialogDisplayForm +from pyams_zmi.layer import IAdminLayer + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces + +# import packages +from z3c.form import field +from zope.interface import Interface + +from pyams_media import _ + + +@viewlet_config(name='media.conversions.action', context=IVideo, layer=IPyAMSLayer, view=Interface, + manager=IContextActions, permission='manage', weight=15) +class MediaConversionsAction(ToolbarMenuItem): + """Media conversions action""" + + label = _("Media conversions...") + label_css_class = 'fa fa-fw fa-compress' + + url = 'media-conversions.html' + modal_target = True + + +@pagelet_config(name='media-conversions.html', context=IVideo, layer=IPyAMSLayer, permission='manage') +class MediaConversionsDisplayForm(AdminDialogDisplayForm): + """Media conversions display form""" + + legend = _("Selected media conversions") + icon_css_class = 'fa fa-fw fa-compress' + + fields = field.Fields(Interface) + + @property + def title(self): + return self.context.title or self.context.filename + + +@viewlet_config(name='media-conversions-prefix', context=IVideo, layer=IAdminLayer, + view=MediaConversionsDisplayForm, manager=IWidgetsPrefixViewletsManager) +@template_config(template='templates/media-conversions.pt') +class MediaConversionsViewletsPrefix(Viewlet): + """Media conversions display form viewlets prefix""" + + @property + def formats(self): + utility = query_utility(IMediaConversionUtility) + if utility is not None: + for format in utility.video_frame_size: + yield format, VIDEO_FRAME_SIZE.get(format) + + @property + def converters(self): + utility = query_utility(IMediaConversionUtility) + if utility is not None: + for converter_name in utility.video_formats: + converter = query_utility(IMediaConverter, name=converter_name) + if converter is not None: + yield converter_name, converter + + @property + def original_frame_size(self): + return IThumbnail(self.context).get_image_size() + + def has_conversion(self, converter, frame_size): + conversions = IMediaConversions(self.context) + name = 'video{width}.{extension}'.format(width='-{0}'.format(frame_size) if frame_size else '', + extension=converter.format) + return name in conversions diff -r 1ade73c9f2c0 -r 5410acbcfb77 src/pyams_media/zmi/templates/media-conversions.pt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_media/zmi/templates/media-conversions.pt Tue Sep 08 16:21:33 2015 +0200 @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + +
  + Original size
+ () +
+
+ () +
+ OK + Waiting... + + N/A + + OK + Waiting... + +