#132 | #121: backoffice / dev-1.0-121 (#131)

cfr #121

Co-authored-by: Christophe Siraut <d@tobald.eu.org>
Co-authored-by: bkfox <thomas bkfox net>
Co-authored-by: Thomas Kairos <thomas@bkfox.net>
Reviewed-on: rc/aircox#131
Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
This commit is contained in:
2024-04-28 22:02:09 +02:00
committed by Thomas Kairos
parent 1e17a1334a
commit 55123c386d
348 changed files with 124397 additions and 17879 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

@ -3,6 +3,7 @@ import tzlocal
from aircox.utils import to_seconds
from ..conf import settings
from .metadata import Metadata, Request
@ -43,9 +44,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."""
@ -76,11 +77,11 @@ class PlaylistSource(Source):
self.program = program
super().__init__(controller, id=id, **kwargs)
self.path = os.path.join(self.station.path, f"{self.id}.m3u")
self.path = settings.get_dir(self.station, f"{self.id}.m3u")
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."""
@ -88,6 +89,7 @@ class PlaylistSource(Source):
def write_playlist(self, playlist=[]):
"""Write playlist to file."""
playlist = playlist or self.get_playlist()
os.makedirs(os.path.dirname(self.path), exist_ok=True)
with open(self.path, "w") as file:
file.write("\n".join(playlist or []))
@ -129,7 +131,7 @@ class QueueSource(Source):
def push(self, *paths):
"""Add the provided paths to source's play queue."""
for path in paths:
self.controller.send(f"{self.id}_queue.push {path}")
print(self.controller.send(f"{self.id}_queue.push {path}"))
def fetch(self):
super().fetch()

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
@ -96,9 +95,10 @@ class Streamer:
data = render_to_string(
self.template_name,
{
"dir": settings.get_dir(self.station),
"log_file": settings.get_dir(self.station, "liquidsoap.log"),
"station": self.station,
"streamer": self,
"settings": settings,
},
)
data = re.sub("[\t ]+\n", "\n", data)