Source code for pyams_media.interfaces

#
# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
# 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.
#

__docformat__ = 'restructuredtext'


# import standard library
from collections import OrderedDict

# import interfaces

# import packages
from zope.interface import Interface, Attribute
from zope.schema import List, Choice, Int
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm

from pyams_media import _


#
# Medias interfaces
#

CONVERTER_NAME = 'Medias converter'
CONVERTER_STARTER_KEY = 'pyams_media.start_handler'
CONVERTER_HANDLER_KEY = 'pyams_media.tcp_handler'
CONVERTER_AUTH_KEY = 'pyams_media.allow_auth'
CONVERTER_CLIENTS_KEY = 'pyams_media.allow_clients'

CUSTOM_AUDIO_TYPES = (b'application/ogg',)
CUSTOM_VIDEO_TYPES = ()


[docs]class IMediaInfo(Interface): """Media file info interface""" infos = Attribute("Complete media info dictionary")
# # Media converter utility interfaces #
[docs]class IMediaConverter(Interface): """Media converter interface""" label = Attribute("Media converter label") format = Attribute("Media converter target format") def convert(self, media): """Convert media to format handled by given converter"""
[docs]class IMediaVideoConverter(IMediaConverter): """Media video converter"""
[docs]class IVideoType(Interface): """Video content-type interface""" video_type = Attribute("Video content type")
[docs]class IMediaAudioConverter(IMediaConverter): """Media audio converter"""
[docs]class IAudioType(Interface): """Audio content-type interface""" audio_type = Attribute("Audio content type")
# # Media conversions adapter interfaces # MEDIA_CONVERSIONS_KEY = 'pyams_media.media.conversions' MEDIA_CONVERSION_CMDLINE_KEY = 'pyams_media.media.conversion.cmdline'
[docs]class IMediaConversions(Interface): """Media conversions interface""" def add_conversion(self, conversion, format, extension=None, width=None): """Add given conversion to media""" def get_conversions(self, with_source=False, order=None): """Get current list of media conversions""" def get_conversion_width(self, name): """Get conversion width for given frame size""" def has_conversion(self, formats): """Check if one of given formats is available in conversions"""
[docs]class IMediaConversion(Interface): """Marker interface for already converted media files"""
# # Media conversion utility configuration interface # VIDEO_FRAME_SIZE = {'sqcif': (128, 96), 'qqvga': (160, 120), 'qcif': (176, 144), 'cga': (320, 200), 'qvga': (320, 240), 'cif': (352, 288), 'vga': (640, 480), '4cif': (704, 576), 'svga': (800, 600), 'wvga': (852, 480), 'hd480': (852, 480), 'hd720': (1280, 720), 'xga': (1024, 768), 'sxga': (1280, 1024), 'wxga': (1366, 768), 'uxga': (1600, 1200), 'wsxga': (1600, 1024), 'hd1080': (1920, 1080), 'wuxga': (1920, 1200), 'qxga': (2048, 1536), 'wqxga': (2560, 1600), 'qsxga': (2560, 2048), 'wqsxga': (3200, 2048), 'wquxga': (3840, 2400), 'hsxga': (5120, 4096), 'whsxga': (6400, 4096), 'whuxga': (7680, 4800)} VIDEO_FRAME_SIZE_NAMES = OrderedDict((('sqcif', "sqcif (128x96)"), ('qqvga', "qqvga (160x120)"), ('qcif', "qcif (176x144)"), ('cga', "cga (320x200)"), ('qvga', "qvga (320x240)"), ('cif', "cif (352x288)"), ('vga', "vga (640x480)"), ('4cif', "4cif (704x576)"), ('svga', "svga (800x600)"), ('wvga', "wvga (852x480)"), ('hd480', "hd480 (852x480)"), ('hd720', "hd720 (1280x720)"), ('xga', "xga (1024x768)"), ('sxga', "sxga (1280x1024)"), ('wxga', "wxga (1366x768)"), ('uxga', "uxga (1600x1200)"), ('wsxga', "wsxga (1600x1024)"), ('hd1080', "hd1080 (1920x1080)"), ('wuxga', "wuxga (1920x1200)"), ('qxga', "qxga (2048x1536)"), ('wqxga', "wqxga (2560x1600)"), ('qsxga', "qsxga (2560x2048)"), ('wqsxga', "wqsxga (3200x2048)"), ('wquxga', "wquxga (3840x2400)"), ('hsxga', "hsxga (5120x4096)"), ('whsxga', "whsxga (6400x4096)"), ('whuxga', "whuxga (7680x4800)"))) VIDEO_FRAME_SIZE_VOCABULARY = SimpleVocabulary([SimpleTerm(v, title=t) for v, t in VIDEO_FRAME_SIZE_NAMES.items()])
[docs]class IMediaConversionUtility(Interface): """Media conversion client interface""" zodb_name = Choice(title=_("ZODB connection name"), description=_("Name of ZODB connection defining converter connection"), required=False, default='', vocabulary="PyAMS ZODB connections") # Video conversions attributes video_formats = List(title=_("Video formats conversions"), description=_("Published video files will be automatically converted to this format"), value_type=Choice(vocabulary="PyAMS media video converters"), required=False) video_frame_size = List(title=_("Video frames size"), description=_("Leave empty to keep original frame size..."), required=True, value_type=Choice(vocabulary=VIDEO_FRAME_SIZE_VOCABULARY)) video_bitrate = Int(title=_("Video bitrate"), description=_("In kilo-bytes per second. Leave empty to keep original value"), required=False) video_quantisation = Int(title=_("Video quantisation scale"), description=_("Lower value indicates higher quality"), required=False, default=1) video_audio_sampling = Int(title=_("Video audio frequency"), description=_("A common value is 22050. Leave empty to keep original value."), required=False) video_audio_bitrate = Int(title=_("Video audio bitrate"), description=_("In kilo-bytes per second. Leave empty to keep original value."), required=False) # Audio conversions attributes audio_formats = List(title=_("Audio formats conversions"), description=_("Published audio files will be automatically converted to this format"), value_type=Choice(vocabulary="PyAMS media audio converters"), required=False) audio_sampling = Int(title=_("Audio frequency"), description=_("A common value is 22050. Leave empty to keep original value."), required=False) audio_bitrate = Int(title=_("Audio bitrate"), description=_("In kilo-bytes per second. Leave empty to keep original value."), required=False) def get_socket(self): """Get 0MQ socket matching utility settings""" def check_media_conversion(self, media): """Check if conversion is needed for given media""" def convert(self, media, format): """Convert given media to requested format"""