<commit_before># -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008 Fluendo, S.L. (www.fluendo.com).
# All rights reserved.

# This file may be distributed and/or modified under the terms of
# the GNU General Public License version 2 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.GPL" in the source distribution for more information.

# Licensees having purchased or holding a valid Flumotion Advanced
# Streaming Server license may use this file in accordance with the
# Flumotion Advanced Streaming Server Commercial License Agreement.
# See "LICENSE.Flumotion" in the source distribution for more information.

# Headers in this file shall remain intact.

"""Wizard plugin for the html5 http plug
"""

import gettext
from zope.interface import implements

from flumotion.admin.assistant.interfaces import IHTTPConsumerPlugin, \
        IHTTPConsumerPluginLine
from flumotion.admin.assistant.models import HTTPServer, HTTPPlug, Muxer, \
        Encoder
from flumotion.ui.plugarea import WizardPlugLine

_ = gettext.gettext

__version__ = "$Rev$"

# Copied from posixpath.py


def slashjoin(a, *p):
    """Join two or more pathname components, inserting '/' as needed"""
    path = a
    for b in p:
        if b.startswith('/'):
            path = b
        elif path == '' or path.endswith('/'):
            path += b
        else:
            path += '/' + b
    return path


class Html5HTTPPlug(HTTPPlug):
    """I am a model representing the configuration file for a
    HTML5 HTTP streaming plug.
    """
    plugType = "component-html5"

    # Component

    def getProperties(self):
        p = super(Html5HTTPPlug, self).getProperties()
        #TODO: find the encoders and muxer and pass in to the Html5HTTPPlug
        # find muxer
        muxer = self.streamer
        while not isinstance(muxer, Muxer):
            muxer = muxer.eaters[0]

        p.codecs = ""
        p.mime_type = ""
        if muxer.componentType == "ogg-muxer":
            p.mime_type = "video/ogg"
        elif muxer.componentType == "webm-muxer":
            p.mime_type = "video/webm"
        # now find the encoders
        for eater in muxer.eaters:
            encoder = eater
            codec = ""
            while not isinstance(encoder, Encoder):
                encoder = encoder.eaters[0]
            if encoder.componentType == "theora-encoder":
                codec = "theora"
            elif encoder.componentType == "vorbis-encoder":
                codec = "vorbis"
            elif encoder.componentType == "vp8-encoder":
                codec = "vp8"
            if p.codecs:
                p.codecs = "%s,%s" % (p.codecs, codec)
            else:
                p.codecs = codec

        p.stream_url = self.streamer.getURL()

        width = 320
        height = 240
        if self.videoProducer:
            width = self.videoProducer.properties.width
            height = self.videoProducer.properties.height

        p.width = width
        p.height = height

        return p


class Html5HTTPServer(HTTPServer):
    """I am a model representing the configuration file for a
    HTTP server component which will be used to serve an html5 
    video watching page.
    Most of the interesting logic here is actually in a plug.
    """<commit_msg>Fix more trailing whitespace.<commit_after># -*- Mode: Python -*-
# vi:si:et:sw=4:sts=4:ts=4
#
# Flumotion - a streaming media server
# Copyright (C) 2004,2005,2006,2007,2008 Fluendo, S.L. (www.fluendo.com).
# All rights reserved.

# This file may be distributed and/or modified under the terms of
# the GNU General Public License version 2 as published by
# the Free Software Foundation.
# This file is distributed without any warranty; without even the implied
# warranty of merchantability or fitness for a particular purpose.
# See "LICENSE.GPL" in the source distribution for more information.

# Licensees having purchased or holding a valid Flumotion Advanced
# Streaming Server license may use this file in accordance with the
# Flumotion Advanced Streaming Server Commercial License Agreement.
# See "LICENSE.Flumotion" in the source distribution for more information.

# Headers in this file shall remain intact.

"""Wizard plugin for the html5 http plug
"""

import gettext
from zope.interface import implements

from flumotion.admin.assistant.interfaces import IHTTPConsumerPlugin, \
        IHTTPConsumerPluginLine
from flumotion.admin.assistant.models import HTTPServer, HTTPPlug, Muxer, \
        Encoder
from flumotion.ui.plugarea import WizardPlugLine

_ = gettext.gettext

__version__ = "$Rev$"

# Copied from posixpath.py


def slashjoin(a, *p):
    """Join two or more pathname components, inserting '/' as needed"""
    path = a
    for b in p:
        if b.startswith('/'):
            path = b
        elif path == '' or path.endswith('/'):
            path += b
        else:
            path += '/' + b
    return path


class Html5HTTPPlug(HTTPPlug):
    """I am a model representing the configuration file for a
    HTML5 HTTP streaming plug.
    """
    plugType = "component-html5"

    # Component

    def getProperties(self):
        p = super(Html5HTTPPlug, self).getProperties()
        #TODO: find the encoders and muxer and pass in to the Html5HTTPPlug
        # find muxer
        muxer = self.streamer
        while not isinstance(muxer, Muxer):
            muxer = muxer.eaters[0]

        p.codecs = ""
        p.mime_type = ""
        if muxer.componentType == "ogg-muxer":
            p.mime_type = "video/ogg"
        elif muxer.componentType == "webm-muxer":
            p.mime_type = "video/webm"
        # now find the encoders
        for eater in muxer.eaters:
            encoder = eater
            codec = ""
            while not isinstance(encoder, Encoder):
                encoder = encoder.eaters[0]
            if encoder.componentType == "theora-encoder":
                codec = "theora"
            elif encoder.componentType == "vorbis-encoder":
                codec = "vorbis"
            elif encoder.componentType == "vp8-encoder":
                codec = "vp8"
            if p.codecs:
                p.codecs = "%s,%s" % (p.codecs, codec)
            else:
                p.codecs = codec

        p.stream_url = self.streamer.getURL()

        width = 320
        height = 240
        if self.videoProducer:
            width = self.videoProducer.properties.width
            height = self.videoProducer.properties.height

        p.width = width
        p.height = height

        return p


class Html5HTTPServer(HTTPServer):
    """I am a model representing the configuration file for a
    HTTP server component which will be used to serve an html5
    video watching page.
    Most of the interesting logic here is actually in a plug.
    """
{'fraction_non_alphanumeric': 0.08704943724177233, 'fraction_numerical': 0.011967516740276393, 'mean_word_length': 2.3588516746411483, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6262224', 'n_tokens_mistral': 2082, 'n_tokens_neox': 1962, 'n_words': 677}