Added audio file conversions display form
authorThierry Florac <thierry.florac@onf.fr>
Wed, 09 Sep 2015 11:20:57 +0200
changeset 13 370b8d6fc9e6
parent 12 240f2efa4a1f
child 14 61775c0158f3
Added audio file conversions display form
src/pyams_media/zmi/media.py
src/pyams_media/zmi/templates/audio-conversions.pt
src/pyams_media/zmi/templates/media-conversions.pt
src/pyams_media/zmi/templates/video-conversions.pt
src/pyams_media/zmi/templates/video-thumbnail.pt
--- a/src/pyams_media/zmi/media.py	Tue Sep 08 17:12:41 2015 +0200
+++ b/src/pyams_media/zmi/media.py	Wed Sep 09 11:20:57 2015 +0200
@@ -9,7 +9,7 @@
 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
 # FOR A PARTICULAR PURPOSE.
 #
-from pyams_file.interfaces import IMediaFile, IVideo, IThumbnail
+from pyams_file.interfaces import IMediaFile, IVideo, IThumbnail, IAudio
 from pyams_form.interfaces.form import IWidgetsPrefixViewletsManager
 from pyams_media.ffbase import FFmpeg
 from pyams_media.ffdocument import FFDocument
@@ -39,23 +39,27 @@
 from pyams_media import _
 
 
-@viewlet_config(name='media.conversions.action', context=IVideo, layer=IPyAMSLayer, view=Interface,
+#
+# Video conversions
+#
+
+@viewlet_config(name='video.conversions.action', context=IVideo, layer=IPyAMSLayer, view=Interface,
                 manager=IContextActions, permission='manage', weight=15)
-class MediaConversionsAction(ToolbarMenuItem):
-    """Media conversions action"""
+class VideoConversionsAction(ToolbarMenuItem):
+    """Video conversions action"""
 
-    label = _("Media conversions...")
+    label = _("Video conversions...")
     label_css_class = 'fa fa-fw fa-compress'
 
-    url = 'media-conversions.html'
+    url = 'video-conversions.html'
     modal_target = True
 
 
-@pagelet_config(name='media-conversions.html', context=IVideo, layer=IPyAMSLayer, permission='manage')
-class MediaConversionsDisplayForm(AdminDialogDisplayForm):
-    """Media conversions display form"""
+@pagelet_config(name='video-conversions.html', context=IVideo, layer=IPyAMSLayer, permission='manage')
+class VideoConversionsDisplayForm(AdminDialogDisplayForm):
+    """Video conversions display form"""
 
-    legend = _("Selected media conversions")
+    legend = _("Selected video conversions")
     icon_css_class = 'fa fa-fw fa-compress'
 
     fields = field.Fields(Interface)
@@ -65,11 +69,11 @@
         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"""
+@viewlet_config(name='video-conversions-prefix', context=IVideo, layer=IAdminLayer,
+                view=VideoConversionsDisplayForm, manager=IWidgetsPrefixViewletsManager)
+@template_config(template='templates/video-conversions.pt')
+class VideoConversionsViewletsPrefix(Viewlet):
+    """Video conversions display form viewlets prefix"""
 
     @property
     def formats(self):
@@ -96,3 +100,54 @@
         name = 'video{width}.{extension}'.format(width='-{0}'.format(frame_size) if frame_size else '',
                                                  extension=converter.format)
         return name in conversions
+
+
+#
+# Audio conversions
+#
+
+@viewlet_config(name='audio.conversions.action', context=IAudio, layer=IPyAMSLayer, view=Interface,
+                manager=IContextActions, permission='manage', weight=15)
+class AudioConversionsAction(ToolbarMenuItem):
+    """Audio conversions action"""
+
+    label = _("Audio conversions...")
+    label_css_class = 'fa fa-fw fa-compress'
+
+    url = 'audio-conversions.html'
+    modal_target = True
+
+
+@pagelet_config(name='audio-conversions.html', context=IAudio, layer=IPyAMSLayer, permission='manage')
+class AudioConversionsDisplayForm(AdminDialogDisplayForm):
+    """Audio conversions display form"""
+
+    legend = _("Selected audio 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='audio-conversions-prefix', context=IAudio, layer=IAdminLayer,
+                view=AudioConversionsDisplayForm, manager=IWidgetsPrefixViewletsManager)
+@template_config(template='templates/audio-conversions.pt')
+class AudioConversionsViewletsPrefix(Viewlet):
+    """Audio conversions display form viewlets prefix"""
+
+    @property
+    def converters(self):
+        utility = query_utility(IMediaConversionUtility)
+        if utility is not None:
+            for converter_name in utility.audio_formats:
+                converter = query_utility(IMediaConverter, name=converter_name)
+                if converter is not None:
+                    yield converter_name, converter
+
+    def has_conversion(self, converter):
+        conversions = IMediaConversions(self.context)
+        name = 'audio.{extension}'.format(extension=converter.format)
+        return name in conversions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_media/zmi/templates/audio-conversions.pt	Wed Sep 09 11:20:57 2015 +0200
@@ -0,0 +1,21 @@
+<table i18n:domain="pyams_media">
+	<tr>
+		<th>&nbsp;</th>
+		<th class="text-center padding-x-10">
+			<i18n:var translate="">Status</i18n:var><br />
+		</th>
+	</tr>
+	<tal:loop repeat="converter_util view.converters">
+		<tr tal:define="converter_name converter_util[0];
+						converter converter_util[1];">
+			<td tal:content="converter.label" i18n:translate="" class="padding-right-20"></td>
+			<td tal:define="converted view.has_conversion(converter)"
+				class="text-align-center">
+				<span tal:condition="converted"
+					  class="txt-color-green" i18n:translate="">OK</span>
+				<span tal:condition="not converted"
+					  class="txt-color-orange" i18n:translate="">Waiting...</span>
+			</td>
+		</tr>
+	</tal:loop>
+</table>
--- a/src/pyams_media/zmi/templates/media-conversions.pt	Tue Sep 08 17:12:41 2015 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-<table class="" i18n:domain="pyams_media"
-		tal:define="original_size view.original_frame_size">
-	<tr>
-		<th>&nbsp;</th>
-		<th class="text-center padding-x-10">
-			<i18n:var translate="">Original size</i18n:var><br />
-			(<tal:var content="'{0[0]}x{0[1]}'.format(original_size)" />)
-		</th>
-		<tal:loop repeat="format view.formats">
-			<th class="text-center padding-x-10" tal:define="format_name format[0];">
-				<tal:var content="format_name" /><br />
-				(<tal:var content="'{0[0]}x{0[1]}'.format(format[1])" />)
-			</th>
-		</tal:loop>
-	</tr>
-	<tal:loop repeat="converter_util view.converters">
-		<tr tal:define="converter_name converter_util[0];
-						converter converter_util[1];">
-			<td tal:content="converter.label" i18n:translate=""></td>
-			<td tal:define="converted view.has_conversion(converter, None)"
-				class="text-align-center">
-				<span tal:condition="converted"
-					  class="txt-color-green" i18n:translate="">OK</span>
-				<span tal:condition="not converted"
-					  class="txt-color-orange" i18n:translate="">Waiting...</span>
-			</td>
-			<tal:loop repeat="format view.formats">
-				<td class="text-center padding-x-10"
-					tal:define="frame_width format[1][0];
-								maybe frame_width < original_size[0];
-								converted view.has_conversion(converter, format);">
-					<span tal:condition="not maybe">N/A</span>
-					<tal:if condition="maybe">
-						<span tal:condition="converted"
-							  class="txt-color-green" i18n:translate="">OK</span>
-						<span tal:condition="not converted"
-							  class="txt-color-orange" i18n:translate="">Waiting...</span>
-					</tal:if>
-				</td>
-			</tal:loop>
-		</tr>
-	</tal:loop>
-</table>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_media/zmi/templates/video-conversions.pt	Wed Sep 09 11:20:57 2015 +0200
@@ -0,0 +1,43 @@
+<table i18n:domain="pyams_media"
+	   tal:define="original_size view.original_frame_size">
+	<tr>
+		<th>&nbsp;</th>
+		<th class="text-center padding-x-10">
+			<i18n:var translate="">Original size</i18n:var><br />
+			(<tal:var content="'{0[0]}x{0[1]}'.format(original_size)" />)
+		</th>
+		<tal:loop repeat="format view.formats">
+			<th class="text-center padding-x-10" tal:define="format_name format[0];">
+				<tal:var content="format_name" /><br />
+				(<tal:var content="'{0[0]}x{0[1]}'.format(format[1])" />)
+			</th>
+		</tal:loop>
+	</tr>
+	<tal:loop repeat="converter_util view.converters">
+		<tr tal:define="converter_name converter_util[0];
+						converter converter_util[1];">
+			<td tal:content="converter.label" i18n:translate="" class="padding-right-20"></td>
+			<td tal:define="converted view.has_conversion(converter, None)"
+				class="text-align-center">
+				<span tal:condition="converted"
+					  class="txt-color-green" i18n:translate="">OK</span>
+				<span tal:condition="not converted"
+					  class="txt-color-orange" i18n:translate="">Waiting...</span>
+			</td>
+			<tal:loop repeat="format view.formats">
+				<td class="text-center padding-x-10"
+					tal:define="frame_width format[1][0];
+								maybe frame_width < original_size[0];
+								converted view.has_conversion(converter, format);">
+					<span tal:condition="not maybe">N/A</span>
+					<tal:if condition="maybe">
+						<span tal:condition="converted"
+							  class="txt-color-green" i18n:translate="">OK</span>
+						<span tal:condition="not converted"
+							  class="txt-color-orange" i18n:translate="">Waiting...</span>
+					</tal:if>
+				</td>
+			</tal:loop>
+		</tr>
+	</tal:loop>
+</table>
--- a/src/pyams_media/zmi/templates/video-thumbnail.pt	Tue Sep 08 17:12:41 2015 +0200
+++ b/src/pyams_media/zmi/templates/video-thumbnail.pt	Wed Sep 09 11:20:57 2015 +0200
@@ -1,11 +1,10 @@
 <div class="flowplayer"
-	 data-ams-plugins="flowplayer pyams_media"
+	 data-ams-plugins="flowplayer"
 	 data-ams-plugin-flowplayer-src="/--static--/pyams_media/flowplayer/flowplayer{MyAMS.devext}.js"
 	 data-ams-plugin-flowplayer-css="/--static--/pyams_media/flowplayer/skin/functional{MyAMS.devext}.css"
 	 data-ams-plugin-flowplayer-async="false"
-	 data-ams-plugin-pyams_media-src="/--static--/pyams_media/js/pyams_media{MyAMS.devext}.js"
-	 data-ams-plugin-pyams_media-callback="PyAMS_media.initPlayer"
-	 data-ams-plugin-pyams_media-async="false"
+	 data-ams-callback="PyAMS_media.initPlayer"
+	 data-ams-callback-source="/--static--/pyams_media/js/pyams_media{MyAMS.devext}.js"
 	 data-ams-flowplayer-events='{"pause": "PyAMS_media.getPlayerTime"}'>
 	<video
 		tal:define="href extension:absolute_url(context);