forked from rc/aircox
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:
@ -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()
|
||||
|
Reference in New Issue
Block a user