streaming link on commission and seance views (#1003)

This commit is contained in:
Frédéric Péters 2011-12-02 16:19:42 +01:00
parent f810a555cb
commit b1f0b3a33e
3 changed files with 45 additions and 5 deletions

View File

@ -58,6 +58,15 @@
<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>

View File

@ -12,13 +12,32 @@ import tabellio.agenda.parlevent
class ParlEventBaseView(tabellio.agenda.parlevent.ParlEventBaseView):
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 not settings.audiofiles_path:
return False
return os.path.exists(os.path.join(settings.audiofiles_path, self.get_stream_name()))
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'
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' % (
self.context.start.year, self.context.start.month,
@ -33,9 +52,12 @@ class View(grok.View, ParlEventView):
class M3U(grok.View, ParlEventView):
grok.context(tabellio.agenda.parlevent.IParlEvent)
grok.require('zope2.View')
grok.name('seance.m3u')
grok.name('ecouter.m3u')
def render(self):
portal_url = getToolByName(self.context, 'portal_url').getPortalObject().absolute_url()
self.request.response.setHeader('Content-type', 'audio/x-mpegurl')
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'

View File

@ -45,7 +45,7 @@
<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 string:${context/absolute_url}/seance.m3u" class="streaming" tal:condition="view/has_stream">Streaming</a>
<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>
</ul>
@ -56,6 +56,15 @@
<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>