#137: Sound et EpisodeSound, dashboard UI improvements (into #121) (#138)

#137

Deployment: **Upgrade to Liquidsoap 2.4**: code has been adapted to work with liquidsoap 2.4

Co-authored-by: bkfox <thomas bkfox net>
Reviewed-on: #138
This commit is contained in:
2024-04-05 18:45:15 +02:00
parent bda4efe336
commit a24318bc84
78 changed files with 25575 additions and 15800 deletions

View File

@ -77,9 +77,12 @@ class Metadata:
air_time = tz.datetime.strptime(air_time, "%Y/%m/%d %H:%M:%S")
return local_tz.localize(air_time)
def validate(self, data):
def validate(self, data, as_dict=False):
"""Validate provided data and set as attribute (must already be
declared)"""
if as_dict and isinstance(data, list):
data = {v[0]: v[1] for v in data}
for key, value in data.items():
if hasattr(self, key) and not callable(getattr(self, key)):
setattr(self, key, value)

View File

@ -133,8 +133,10 @@ class Monitor:
# get sound
diff = None
sound = Sound.objects.path(air_uri).first()
if sound and sound.episode_id is not None:
diff = Diffusion.objects.episode(id=sound.episode_id).on_air().now(air_time).first()
if sound:
ids = sound.episodesound_set.values_list("episode_id", flat=True)
if ids:
diff = Diffusion.objects.filter(episode_id__in=ids).on_air().now(air_time).first()
# log sound on air
return self.log(
@ -198,7 +200,7 @@ class Monitor:
Diffusion.objects.station(self.station)
.on_air()
.now(now)
.filter(episode__sound__type=Sound.TYPE_ARCHIVE)
.filter(episode__episodesound__broadcast=True)
.first()
)
# Can't use delay: diffusion may start later than its assigned start.
@ -227,7 +229,7 @@ class Monitor:
return log
def start_diff(self, source, diff):
playlist = Sound.objects.episode(id=diff.episode_id).playlist()
playlist = diff.episode.episodesound_set.all().broadcast().playlist()
source.push(*playlist)
self.log(
type=Log.TYPE_START,

View File

@ -43,9 +43,9 @@ class Source(Metadata):
except ValueError:
self.remaining = None
data = self.controller.send(self.id, ".get", parse=True)
data = self.controller.send(f"var.get {self.id}_meta", parse_json=True)
if data:
self.validate(data if data and isinstance(data, dict) else {})
self.validate(data if data and isinstance(data, (dict, list)) else {}, as_dict=True)
def skip(self):
"""Skip the current source sound."""
@ -80,7 +80,7 @@ class PlaylistSource(Source):
def get_sound_queryset(self):
"""Get playlist's sounds queryset."""
return self.program.sound_set.archive()
return self.program.sound_set.broadcast()
def get_playlist(self):
"""Get playlist from db."""

View File

@ -8,8 +8,7 @@ import subprocess
import psutil
from django.template.loader import render_to_string
from aircox.conf import settings
from ..conf import settings
from ..connector import Connector
from .sources import PlaylistSource, QueueSource
@ -46,8 +45,8 @@ class Streamer:
self.outputs = self.station.port_set.active().output()
self.id = self.station.slug.replace("-", "_")
self.path = os.path.join(station.path, "station.liq")
self.connector = connector or Connector(os.path.join(station.path, "station.sock"))
self.path = settings.get_dir(station, "station.liq")
self.connector = connector or Connector(settings.get_dir(station, "station.sock"))
self.init_sources()
@property
@ -98,7 +97,6 @@ class Streamer:
{
"station": self.station,
"streamer": self,
"settings": settings,
},
)
data = re.sub("[\t ]+\n", "\n", data)