--- /dev/null
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.24 on 2020-01-06 14:27
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('nonstop', '0015_streameddiffusion'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='streameddiffusion',
+ name='jingle',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='nonstop.Jingle'),
+ ),
+ ]
label = models.CharField(_('Label'), max_length=100)
url = models.URLField(_('URL'), max_length=255)
+ def __str__(self):
+ return self.label
+
class StreamedDiffusion(models.Model):
class Meta:
verbose_name_plural = _('Streamed diffusions')
diffusion = models.ForeignKey('emissions.Diffusion')
- jingle = models.ForeignKey(Jingle, null=True)
+ jingle = models.ForeignKey(Jingle, null=True, blank=True)
stream = models.ForeignKey(Stream)
+
+ def __str__(self):
+ return self.label
<TimeContinued>1</TimeContinued>
<SpotController>0</SpotController>
+ {% if streamed_diffusion %}
+ <Type>stream</Type>
+ {% if streamed_diffusion.jingle %}
+ <Jingle>:/nonstop/SPOTS/{{ streamed_diffusion.jingle.file_path }}</Jingle>
+ {% else %}
+ <Jingle/>
+ {% endif %}
+ <Stream>{{streamed_diffusion.stream.url}}</Stream>
+ {% else %}
<Type>files</Type>
-
<Jingle>:/nonstop/SPOTS/jingles panik/H_ecoutez_RP_zoe_1.wav</Jingle>
+ <Stream></Stream>
+ {% endif %}
<Module></Module>
<ModuleData></ModuleData>
- <Stream></Stream>
<Random>0</Random>
+ {% if streamed_diffusion %}
+ <SoftStop>0</SoftStop>
+ {% else %}
<SoftStop>1</SoftStop>
+ {% endif %}
<RatioSong>10</RatioSong>
<RatioSpot>2</RatioSpot>
--- /dev/null
+{% extends "base.html" %}
+{% load i18n %}
+
+{% block appbar %}
+<h2>{% trans "New Streamed Diffusion" %}</h2>
+{% endblock %}
+
+{% block content %}
+<form method="post" enctype="multipart/form-data">
+ {% csrf_token %}
+ {{ form.as_p }}
+ <div class="buttons">
+ <button class="submit-button">{% trans "Add" %}</button>
+ <a class="cancel" href=".">{% trans "Cancel" %}</a>
+ </div>
+</form>
+{% endblock %}
from .views import (SomaDayArchiveView, SomaDayArchiveCsvView, RedirectTodayView,
TrackDetailView, ArtistDetailView, ArtistListView, StatisticsView,
UploadTracksView, RecentTracksView, QuickLinksView, SearchView, CleanupView,
- SearchCsvView, AddDiffusionView)
+ SearchCsvView, AddDiffusionView, AddStreamedDiffusionView)
urlpatterns = [
# Example: /2012/nov/10/
url(r'^quick-links/$', QuickLinksView.as_view(), name='nonstop-quick-links'),
url(r'^cleanup/$', CleanupView.as_view(), name='nonstop-cleanup'),
- # soma mangement for episodes
+ # soma management for episodes
url(r'^diffusion/(?P<pk>\d+)/add/$', AddDiffusionView.as_view(), name='nonstop-add-diffusion'),
+ url(r'^diffusion/(?P<pk>\d+)/add-stream/$', AddStreamedDiffusionView.as_view(), name='nonstop-add-streamed-diffusion'),
]
from django.template import loader
import xml.etree.ElementTree as ET
-from .models import Track, SomaLogLine, LOCAL_BASE_PATH
+from .models import Track, SomaLogLine, StreamedDiffusion, LOCAL_BASE_PATH
class SomaException(Exception):
diffusion.episode.emission.slug)
def is_already_in_soma(diffusion):
+ if StreamedDiffusion.objects.filter(diffusion=diffusion).count():
+ return True
return os.path.exists(os.path.join(LOCAL_BASE_PATH, get_diffusion_file_path(diffusion)))
class DuplicateDiffusionSlot(Exception):
pass
def add_diffusion(diffusion):
- soundfile = diffusion.episode.soundfile_set.filter(fragment=False)[0]
- diffusion_path = get_diffusion_file_path(diffusion)
-
- # copy file
- if os.path.exists(LOCAL_BASE_PATH):
- if os.path.exists(os.path.join(LOCAL_BASE_PATH, diffusion_path)):
- raise DuplicateDiffusionSlot()
- os.mkdir(os.path.join(LOCAL_BASE_PATH, diffusion_path))
- shutil.copyfile(soundfile.file.path,
- os.path.join(LOCAL_BASE_PATH, diffusion_path, os.path.basename(soundfile.file.path)))
+ context = {}
+ streamed_diffusion = StreamedDiffusion.objects.filter(diffusion=diffusion).first()
+ if streamed_diffusion:
+ # program a stream
+ context['streamed_diffusion'] = streamed_diffusion
+ context['end'] = diffusion.end_datetime
+ else:
+ # program a soundfile
+ soundfile = diffusion.episode.soundfile_set.filter(fragment=False)[0]
+ diffusion_path = get_diffusion_file_path(diffusion)
+
+ # copy file
+ if os.path.exists(LOCAL_BASE_PATH):
+ if os.path.exists(os.path.join(LOCAL_BASE_PATH, diffusion_path)):
+ raise DuplicateDiffusionSlot()
+ os.mkdir(os.path.join(LOCAL_BASE_PATH, diffusion_path))
+ shutil.copyfile(soundfile.file.path,
+ os.path.join(LOCAL_BASE_PATH, diffusion_path, os.path.basename(soundfile.file.path)))
+
+ context['diffusion_path'] = diffusion_path
+ # end should be a bit before the real end of file so the same file doesn't
+ # get repeated.
+ context['end'] = diffusion.datetime + datetime.timedelta(seconds=(soundfile.duration or 300) - 180)
# create palinsesti
palinsesti_template = loader.get_template('nonstop/soma_palinsesti.xml')
- context = {}
- context['diffusion_path'] = diffusion_path
context['episode'] = diffusion.episode
context['start'] = diffusion.datetime
- # end should be a bit before the real end of file so the same file doesn't
- # get repeated.
- context['end'] = diffusion.datetime + datetime.timedelta(seconds=(soundfile.duration or 300) - 180)
palinsesti = palinsesti_template.render(context)
palinsesti_xml = ET.fromstring(palinsesti.encode('utf-8'))
from django.views.generic.base import RedirectView, TemplateView
from django.views.generic.dates import DayArchiveView
from django.views.generic.detail import DetailView
-from django.views.generic.edit import FormView
+from django.views.generic.edit import CreateView, FormView
from django.views.generic.list import ListView
from .forms import UploadTracksForm, TrackMetaForm, TrackSearchForm, CleanupForm
-from .models import SomaLogLine, Track, Artist, NonstopFile
+from .models import SomaLogLine, Track, Artist, NonstopFile, StreamedDiffusion
from emissions.models import Nonstop, Diffusion
from . import utils
return HttpResponseRedirect(reverse('episode-view', kwargs={
'emission_slug': episode.emission.slug,
'slug': episode.slug}))
+
+
+class AddStreamedDiffusionView(CreateView):
+ model = StreamedDiffusion
+ fields = ['jingle', 'stream']
+ template_name = 'nonstop/streamed-diffusion.html'
+
+ def form_valid(self, form):
+ form.instance.diffusion_id = self.kwargs['pk']
+ response = super(AddStreamedDiffusionView, self).form_valid(form)
+ return response
+
+ def get_success_url(self):
+ diffusion = Diffusion.objects.get(id=self.kwargs['pk'])
+ episode = diffusion.episode
+ try:
+ utils.add_diffusion(diffusion)
+ except utils.SomaException as e:
+ messages.error(self.request, _('technical soma error (%s)') % e)
+ else:
+ messages.info(self.request, _('%s added to soma') % episode.emission.title)
+ return reverse('episode-view', kwargs={
+ 'emission_slug': episode.emission.slug,
+ 'slug': episode.slug})