summaryrefslogtreecommitdiff
path: root/generate_tonight.py
blob: b457f90f45a160d0d8ed123b85d1b563599d5441 (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
#!/usr/bin/env python3
"""One-off: generate playlist for remaining hours tonight.
Unlike the full generator, this resets start_time to 0 so Liquidsoap
plays from the top immediately instead of seeking to a time offset."""
import sys, time, json, os
sys.path.insert(0, os.path.dirname(__file__))
from generate_daily_playlist import build_playlist, write_outputs

playlist = build_playlist()
if not playlist:
    sys.exit(1)

now_secs = time.localtime().tm_hour * 3600 + time.localtime().tm_min * 60
entries = [e for e in playlist["entries"] if e["start_time"] >= now_secs]

# Rebase start times to 0 so the playlist plays sequentially from the top
offset = entries[0]["start_time"] if entries else 0
for e in entries:
    e["start_time"] = round(e["start_time"] - offset, 1)
    h = int(e["start_time"] // 3600)
    m = int((e["start_time"] % 3600) // 60)
    s = int(e["start_time"] % 60)
    e["start_formatted"] = f"{h:02d}:{m:02d}:{s:02d}"

playlist["entries"] = entries
playlist["total_tracks"] = sum(1 for e in entries if e["type"] == "track")
playlist["total_entries"] = len(entries)

write_outputs(playlist)

ann_count = sum(1 for e in entries if e["type"] == "announcement")
jingle_count = sum(1 for e in entries if e["type"] == "jingle")
print(f"Tonight: {playlist['total_tracks']} tracks, {ann_count} announcements, {jingle_count} jingles from {now_secs/3600:.1f}h onwards")