summaryrefslogtreecommitdiff
path: root/track_announce.liq
blob: 8aac47650d07784cc02016620db5267c0dcd4bc7 (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
72
73
74
75
76
77
#!/usr/bin/liquidsoap

# Radio Susan — with track announcements

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

# State file for track metadata exchange
state_file = "/var/lib/radio/track_state.json"

# Track counter
track_count = ref(0)

music = playlist(
  mode="randomize",
  reload=3600,
  reload_mode="watch",
  "/var/lib/radio/playlists/all.m3u"
)
music = drop_video(music)

# Write track metadata to state file on each new track
music = on_track(fun(m) -> begin
  track_count := !track_count + 1
  artist = m["artist"]
  title = m["title"]
  count = !track_count
  # Write JSON state file
  data = '{"artist":"#{artist}","title":"#{title}","count":#{string_of(count)}}'
  ignore(file.write(data=data, state_file))
  log("Track #{string_of(count)}: #{artist} - #{title}")
end, music)

# Jingles
jingles = playlist(
  mode="randomize",
  "/var/lib/radio/jingles"
)
jingles = drop_video(jingles)
jingles = amplify(3.0, jingles)

# Dynamic announcements
def get_announcement() =
  result = list.hd(default="", process.read.lines("/usr/bin/python3 /var/lib/radio/announce_tracks.py --state"))
  if result != "" then
    log("Announcement: #{result}")
    request.create(result)
  else
    # Fallback to a random jingle
    null()
  end
end

announcements = request.dynamic(get_announcement)
announcements = drop_video(announcements)
announcements = amplify(3.0, announcements)

# Rotate: 2 music tracks, then 1 announcement or jingle
radio = rotate(weights=[2, 1], [music, random(weights=[1, 1], [jingles, announcements])])

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
)