Compare commits

...

6 Commits

@ -1,7 +1,6 @@
#!/usr/bin/liquidsoap
set("log.stdout", true)
set("log.file",false)
#%include "cross.liq"
# Allow requests from Telnet (Liquidsoap Requester)
set("server.telnet", true)
@ -121,55 +120,83 @@ pmain_crossed = mksafe(pmain_crossed)
output.icecast(%vorbis.cbr(samplerate=48000, channels=2, bitrate=164),
host = "10.7.0.3", port = 24100,
icy_metadata="true", description="WOW!Radio",
send_icy_metadata=true, description="WOW!Radio",
password = "lel", mount = "wow.ogg",
pmain_crossed)
output.icecast(%vorbis.cbr(samplerate=48000, channels=2, bitrate=164),
host = "10.7.0.3", port = 24100,
icy_metadata="true", description="WOW!Radio | Anjunadeep",
send_icy_metadata=true, description="WOW!Radio | Anjunadeep",
password = "lel", mount = "anjunadeep.ogg",
panjunadeep)
output.icecast(%vorbis.cbr(samplerate=48000, channels=2, bitrate=164),
host = "10.7.0.3", port = 24100,
icy_metadata="true", description="WOW!Radio | Berlin",
send_icy_metadata=true, description="WOW!Radio | Berlin",
password = "lel", mount = "berlin.ogg",
pberlin)
output.icecast(%vorbis.cbr(samplerate=48000, channels=2, bitrate=164),
host = "10.7.0.3", port = 24100,
icy_metadata="true", description="WOW!Radio | Breakbeat",
send_icy_metadata=true, description="WOW!Radio | Breakbeat",
password = "lel", mount = "breaks.ogg",
pbreaks)
output.icecast(%vorbis.cbr(samplerate=48000, channels=2, bitrate=164),
host = "10.7.0.3", port = 24100,
icy_metadata="true", description="WOW!Radio | Dnb",
send_icy_metadata=true, description="WOW!Radio | Dnb",
password = "lel", mount = "dnb.ogg",
pdnb)
output.icecast(%vorbis.cbr(samplerate=48000, channels=2, bitrate=164),
host = "10.7.0.3", port = 24100,
icy_metadata="true", description="WOW!Radio | Raves",
password = "lel", mount = "raves.ogg",
praves)
output.icecast(%vorbis.cbr(samplerate=48000, channels=2, bitrate=164),
host = "10.7.0.3", port = 24100,
icy_metadata="true", description="WOW!Radio | Trance",
send_icy_metadata=true, description="WOW!Radio | Trance",
password = "lel", mount = "trance.ogg",
ptrance)
output.icecast(%vorbis.cbr(samplerate=48000, channels=2, bitrate=164),
host = "10.7.0.3", port = 24100,
icy_metadata="true", description="WOW!Radio | Weed",
send_icy_metadata=true, description="WOW!Radio | Weed",
password = "lel", mount = "weed.ogg",
pweed)
output.icecast(%vorbis.cbr(samplerate=48000, channels=2, bitrate=128),
host = "10.7.0.3", port = 24100,
send_icy_metadata=true, description="WOW!Radio | Rave",
password = "lel", mount = "rave.ogg",
praves)
def get_now_playing_filepaths(_)
def null_list(key, _list)
list.assoc.mem(key, _list) ? list.assoc(key, _list) : null()
end
pmain_meta = pmain.last_metadata() ?? []
panjunadeep_meta = panjunadeep.last_metadata() ?? []
pberlin_meta = pberlin.last_metadata() ?? []
pbreaks_meta = pbreaks.last_metadata() ?? []
pdnb_meta = pdnb.last_metadata() ?? []
praves_meta = praves.last_metadata() ?? []
ptrance_meta = ptrance.last_metadata() ?? []
pweed_meta = pweed.last_metadata() ?? []
pmain_filename = null_list("filename", pmain_meta)
panjunadeep_filename = null_list("filename", panjunadeep_meta)
pberlin_filename = null_list("filename", pberlin_meta)
pbreaks_filename = null_list("filename", pbreaks_meta)
pdnb_filename = null_list("filename", pdnb_meta)
praves_filename = null_list("filename", praves_meta)
ptrance_filename = null_list("filename", ptrance_meta)
pweed_filename = null_list("filename", pweed_meta)
"pmain_filename=#{pmain_filename}\npanjunadeep_filename=#{panjunadeep_filename}\npberlin_filename=#{pberlin_filename}\npbreaks_filename=#{pbreaks_filename}\npdnb_filename=#{pdnb_filename}\npraves_filename=#{praves_filename}\nptrance_filename=#{ptrance_filename}\npweed_filename=#{pweed_filename}\n"
end
server.register("now_playing", get_now_playing_filepaths)

@ -1,6 +1,7 @@
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2021, dsc@xmr.pm
import re
import sys
import collections
from typing import List, Optional
@ -29,6 +30,7 @@ irc_message_announce_bus = MultisubscriberQueue()
websocket_status_bus_last_item: Optional[dict[str, Station]] = None
irc_bot = None
keycloak = None
NP_MAP = {} # station, filepath
soap = Radio()
@ -61,6 +63,7 @@ async def _setup_tasks(app: Quart):
asyncio.create_task(last_websocket_item_updater())
asyncio.create_task(irc_announce_task())
asyncio.create_task(_now_playing_watch())
async def _setup_irc(app: Quart):
@ -97,6 +100,29 @@ async def _setup_cache(app: Quart):
Session(app)
async def _now_playing_watch():
global NP_MAP
proc = await asyncio.create_subprocess_exec(
"journalctl", "-n15000", "-xefu", "liquidsoap",
stdout=asyncio.subprocess.PIPE,
)
line = await proc.stdout.readline()
while line:
line = line.decode().strip()
if '] Prepared "/' in line and ".ogg" in line:
try:
filename = re.findall(r"\"(.*\.ogg)\"", line)[0]
radio = re.findall(r"\[(\w+)\:\d\]", line)[0]
if radio == "playlist":
radio = "pmain"
NP_MAP[radio] = filename
except Exception as ex:
print(f"_now_playing_watch: {ex}")
line = await proc.stdout.readline()
def create_app():
global app, soap, icecast2
app = Quart(__name__)

@ -61,10 +61,17 @@ class Station:
# 4. check .ogg.json metadata file (Song.from_filepath)
# 5. verify the above by comparing icecast metadata
liq_meta = await Radio.command(self.telnet_cmd_metadata)
liq_meta = liq_meta.decode(errors="ignore")
liq_filenames = re.findall(r"filename=\"(.*)\"", liq_meta)
liq_filenames = [fn for fn in liq_filenames if os.path.exists(fn)]
# find a better way to get current song
liq_filenames = []
from ircradio.factory import NP_MAP
np_uid = self.id
if np_uid == "main":
np_uid = "pmain"
elif np_uid == "wow":
np_uid = "pmain"
if np_uid in NP_MAP:
liq_filenames = [NP_MAP[np_uid]]
liq_remaining = await Radio.command(self.telnet_cmd_remaining)
liq_remaining = liq_remaining.decode(errors="ignore")
@ -173,15 +180,15 @@ class Station:
@property
def telnet_cmd_metadata(self):
return f"{self.mount_point}.metadata"
return f"now_playing"
@property
def telnet_cmd_remaining(self):
return f"{self.mount_point}.remaining"
return f"{self.mount_point.replace('.', '_')}.remaining"
@property
def telnet_cmd_skip(self):
return f"{self.mount_point}.skip"
return f"{self.mount_point.replace('.', '_')}.skip"
@property
def stream_url(self):

@ -121,6 +121,7 @@ class YouTube:
title = 'Unknown'
app.logger.warning(f"could not detect artist/title from metadata for {filepath}")
title = title if '-' in title else f"{artist} - {title}"
return {
"name": f"{title}",
"data": metadata,

Loading…
Cancel
Save