parent
35f8275c2c
commit
bcb9da62e3
|
@ -28,4 +28,4 @@ class M3U(grok.View, CommissionView):
|
|||
def render(self):
|
||||
portal_url = getToolByName(self.context, 'portal_url').getPortalObject().absolute_url()
|
||||
self.request.response.setHeader('Content-type', 'audio/x-mpegurl')
|
||||
return portal_url + '/mp3/' + self.get_stream_name() + '\n'
|
||||
return portal_url + '/mp3/jp/' + self.get_stream_name() + '\n'
|
||||
|
|
|
@ -41,10 +41,31 @@
|
|||
<p class="place" tal:content="context/place">
|
||||
</p>
|
||||
|
||||
<ul id="cri-stream">
|
||||
<ul id="cri-stream"
|
||||
tal:define="is_manager python: modules['AccessControl'].getSecurityManager().checkPermission('Manage Portal', context)">
|
||||
|
||||
<li><a href="#" class="cri" tal:condition="python: context.cri and context.cri.to_object"
|
||||
tal:attributes="href context/cri/to_object/absolute_url">Compte-rendu intégral</a>
|
||||
<span class="cri" tal:condition="python: not(context.cri and context.cri.to_object)">Compte-rendu intégral (non disponible)</span></li>
|
||||
|
||||
<li>
|
||||
<tal:if tal:define="live_stream view/get_live_stream_infos"
|
||||
tal:condition="live_stream/enabled">
|
||||
<span class="streaming" tal:condition="live_stream/not_yet_streaming">Le streaming sera disponible pendant la réunion</span>
|
||||
<span class="streaming" tal:condition="live_stream/streaming">
|
||||
Ecouter en direct :<br />
|
||||
|
||||
<audio src="" tal:attributes="src live_stream/url" type="audio/mpeg" controls></audio>
|
||||
</span>
|
||||
<span class="streaming"
|
||||
tal:define="stream_url view/get_stream_url"
|
||||
tal:condition="python: live_stream.finished and stream_url">
|
||||
Réécouter l'enregistrement :<br />
|
||||
|
||||
<audio src="" tal:attributes="src stream_url" type="audio/mpeg" controls></audio>
|
||||
</span>
|
||||
</tal:if>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
@ -56,15 +77,6 @@
|
|||
|
||||
<div tal:replace="structure provider:plone.belowcontentbody" />
|
||||
|
||||
<script>
|
||||
$('a.streaming').click(function(event) {
|
||||
if ($(this).attr('href').indexOf('.m3u') == -1) {
|
||||
window.open($(this).attr('href'), 'streaming', 'width=220,height=220');
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</tal:main-macro>
|
||||
</metal:main>
|
||||
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from Products.CMFCore.utils import getToolByName
|
||||
from datetime import datetime
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger("Plone")
|
||||
|
||||
STREAM_LOCATIONS = {
|
||||
u"HG Salle Bleue": "http://audio.pfwb.be:8007/",
|
||||
u"HG Salle des Gouverneurs": "http://audio.pfwb.be:8006/",
|
||||
u"HL Salle Audiovisuelle": "http://audio.pfwb.be:8002/audio",
|
||||
u"HL Salle Blanche": "http://audio.pfwb.be:8003/blanche",
|
||||
u"HL Salle Ovale": "http://audio.pfwb.be:8004/ovale",
|
||||
u"HL Salle du Parc": "http://audio.pfwb.be:8001/parc",
|
||||
u"H\xe9micycle": "http://audio.pfwb.be:8005/hemi",
|
||||
}
|
||||
|
||||
|
||||
class Stream(object):
|
||||
|
||||
def __init__(self, location, start, end, real_finished):
|
||||
self.location = location
|
||||
self.start = start
|
||||
self.end = end
|
||||
self.real_finished = real_finished
|
||||
|
||||
@property
|
||||
def enabled(self):
|
||||
return (self.location in STREAM_LOCATIONS)
|
||||
|
||||
@property
|
||||
def streaming(self):
|
||||
return (self.enabled and not self.not_yet_streaming and not self.finished)
|
||||
|
||||
@property
|
||||
def not_yet_streaming(self):
|
||||
now = datetime.now()
|
||||
return (self.enabled and now < self.start)
|
||||
|
||||
@property
|
||||
def finished(self):
|
||||
now = datetime.now()
|
||||
return (self.enabled and now > self.end and self.real_finished)
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return STREAM_LOCATIONS.get(self.location)
|
||||
|
||||
|
||||
def get_live_stream_infos_for_context(context):
|
||||
# event_id = context.id
|
||||
# portal = getToolByName(context, "portal_url").getPortalObject()
|
||||
# db_connection = portal.db._wrapper.connection
|
||||
# cursor = db_connection.cursor()
|
||||
# cursor.execute('''SELECT lieu, datedeb, heuredeb, datefin, heurefin, finreel
|
||||
# FROM t_reunion
|
||||
# WHERE id = %(id)s''', {'id': event_id})
|
||||
# row = cursor.fetchone()
|
||||
# cursor.close()
|
||||
# lieu, datedeb, heuredeb, datefin, heurefin, finreel = row
|
||||
|
||||
# -- For testing purposes
|
||||
from datetime import date
|
||||
from datetime import time
|
||||
lieu, datedeb, heuredeb, datefin, heurefin, finreel = (
|
||||
"HG Salle Bleue",
|
||||
date(2019, 9, 1),
|
||||
time(9, 0),
|
||||
date(2019, 9, 2),
|
||||
time(9, 0),
|
||||
True,
|
||||
)
|
||||
|
||||
start = datetime.combine(datedeb, heuredeb)
|
||||
end = datetime.combine(datefin, heurefin)
|
||||
stream_infos = Stream(lieu, start, end, finreel)
|
||||
return stream_infos
|
|
@ -1,4 +1,4 @@
|
|||
import os
|
||||
import urllib2
|
||||
|
||||
from five import grok
|
||||
from zope import schema, component
|
||||
|
@ -9,34 +9,30 @@ from tabellio.config.interfaces import ITabellioSettings
|
|||
|
||||
import tabellio.agenda.parlevent
|
||||
|
||||
from tabellio.pcfviews.live_stream import get_live_stream_infos_for_context
|
||||
|
||||
|
||||
class ParlEventBaseView(tabellio.agenda.parlevent.ParlEventBaseView):
|
||||
|
||||
def get_live_stream_infos(self):
|
||||
return get_live_stream_infos_for_context(self.context)
|
||||
|
||||
def has_stream(self):
|
||||
return (self.get_stream_url() is not None)
|
||||
|
||||
def get_stream_url(self):
|
||||
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
||||
if settings.audiofiles_path:
|
||||
if os.path.exists(os.path.join(settings.audiofiles_path, self.get_stream_name())):
|
||||
if settings.embedded_audio_player_url:
|
||||
return settings.embedded_audio_player_url + '?' + self.get_stream_name()
|
||||
else:
|
||||
return self.context.absolute_url() + '/ecouter.m3u'
|
||||
portal_url = getToolByName(self.context, 'portal_url').getPortalObject().absolute_url()
|
||||
stream_url = portal_url + '/mp3/jp/' + self.get_stream_name()
|
||||
try:
|
||||
response = urllib2.urlopen(stream_url)
|
||||
if response.code == 200:
|
||||
return stream_url
|
||||
except:
|
||||
pass
|
||||
return None
|
||||
|
||||
|
||||
class ParlEventView(ParlEventBaseView):
|
||||
def get_stream_url(self):
|
||||
stream_url = ParlEventBaseView.get_stream_url(self)
|
||||
if stream_url:
|
||||
return stream_url
|
||||
if not self.context.is_now():
|
||||
return None
|
||||
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
||||
if settings.embedded_audio_player_url:
|
||||
return settings.embedded_audio_player_url
|
||||
else:
|
||||
return self.context.absolute_url() + '/ecouter.m3u'
|
||||
|
||||
def get_stream_name(self):
|
||||
filename = '%04d%02d%02d%02d-SEAN.mp3' % (
|
||||
|
@ -60,4 +56,4 @@ class M3U(grok.View, ParlEventView):
|
|||
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
||||
if self.context.is_now():
|
||||
return settings.live_stream_url + '\n'
|
||||
return portal_url + '/mp3/' + self.get_stream_name() + '\n'
|
||||
return portal_url + '/mp3/jp/' + self.get_stream_name() + '\n'
|
||||
|
|
|
@ -41,12 +41,21 @@
|
|||
<p class="place" tal:content="context/place">
|
||||
</p>
|
||||
|
||||
<ul id="cri-stream">
|
||||
<ul id="cri-stream"
|
||||
tal:define="is_manager python: modules['AccessControl'].getSecurityManager().checkPermission('Manage Portal', context)">
|
||||
<li><a href="#" class="cri" tal:condition="python: context.cri and context.cri.to_object"
|
||||
tal:attributes="href context/cri/to_object/absolute_url">Compte-rendu intégral</a>
|
||||
<span class="cri" tal:condition="python: not(context.cri and context.cri.to_object)">Compte-rendu intégral (non disponible)</span></li>
|
||||
<li><a tal:attributes="href view/get_stream_url" class="streaming" tal:condition="view/has_stream">Streaming</a>
|
||||
<span class="streaming" tal:condition="not: view/has_stream">Streaming (non disponible)</span></li>
|
||||
|
||||
<li>
|
||||
<tal:if tal:define="live_stream view/get_live_stream_infos"
|
||||
tal:condition="live_stream/enabled">
|
||||
<span class="streaming" tal:condition="live_stream/not_yet_streaming">Le streaming sera disponible pendant la réunion</span>
|
||||
<a href="http://direct.pfwb.be" class="streaming" tal:condition="live_stream/streaming">Visionner en direct</a>
|
||||
<a href="http://tv.pfwb.be" class="streaming" tal:condition="live_stream/finished">Consulter la vidéo</a>
|
||||
</tal:if>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<div class="order-of-the-day" tal:condition="context/order_of_the_day">
|
||||
|
@ -56,15 +65,6 @@
|
|||
|
||||
<div tal:replace="structure provider:plone.belowcontentbody" />
|
||||
|
||||
<script>
|
||||
$('a.streaming').click(function(event) {
|
||||
if ($(this).attr('href').indexOf('.m3u') == -1) {
|
||||
window.open($(this).attr('href'), 'streaming', 'width=220,height=220');
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</tal:main-macro>
|
||||
</metal:main>
|
||||
|
||||
|
|
Reference in New Issue