summaryrefslogtreecommitdiff
path: root/radio.liq
blob: 0f5b826051df2c0456a76ca67640d3e2af042812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/liquidsoap

# Radio Susan — pre-generated daily playlist
# Tracks, announcements, and jingles are all baked into playlist.m3u
# Liquidsoap just plays it sequentially.

set("log.file.path", "/var/lib/radio/radio.log")
set("log.level", 3)
set("server.telnet", true)
set("server.telnet.port", 1234)

state_file = "/var/lib/radio/track_state.json"
playlist_file = "/var/lib/radio/playlist.m3u"

# Primary source: pre-generated daily playlist
music = playlist(
  id="daily_playlist",
  mode="normal",
  reload=3600,
  reload_mode="watch",
  playlist_file
)

# Fallback 1: live DJ (per-track)
def get_next_track() =
  result = list.hd(default="", process.read.lines("/usr/bin/python3 /var/lib/radio/radio_dj.py"))
  if result != "" then
    log("DJ fallback picked: #{result}")
    request.create(result)
  else
    log("DJ returned nothing")
    null()
  end
end

dj_fallback = request.dynamic(id="dj_fallback", get_next_track)

# Fallback 2: static random playlist (last resort)
random_fallback = playlist(
  id="random_fallback",
  mode="randomize",
  reload=3600,
  "/var/lib/radio/playlists/all.m3u"
)

# Chain: playlist → DJ → random
radio = fallback(id="Radio_Susan", track_sensitive=true, [music, dj_fallback, random_fallback])

# Write track metadata to state file on each new track
radio = source.on_track(radio, fun(m) -> begin
  artist = m["artist"]
  title = m["title"]
  data = '{"artist":"#{artist}","title":"#{title}"}'
  ignore(file.write(data=data, state_file))
  log("Now playing: #{artist} - #{title}")
end)

radio = mksafe(radio)

output.icecast(
  %mp3(bitrate=192),
  host="localhost",
  port=8910,
  password="REDACTED",
  mount="/stream",
  name="Radio Susan",
  description="Personal radio station",
  genre="Eclectic",
  url="https://radio.jihakuz.xyz",
  radio
)