feat: detect and play DVDs where a drive is fitted

DVD support stays optional per room: DVD_ENABLED decides whether the
button is built at all, and rooms without it poll nothing. Upgrades
append a commented DVD_ENABLED=false so the option is discoverable
without changing what those rooms already do.

The dock polls the drive with CDROM_DRIVE_STATUS, which is a status
query rather than a read, so it does not spin the disc up. A disc that
becomes ready announces itself once and brings the DVD logo up to full
strength; an empty or unplugged drive holds it back, the same gray
versus colour language the LIVE icon already uses. Nothing autoplays —
playback always needs a deliberate press.

Playback is VLC rather than mpv because mpv dropped DVD menu support,
and menus are the part that matters for a commercial disc. It goes
through classroom-window like everything else, so the player minimizes
and restores from the dock exactly as the browser does.

Pressing the button with no drive, no disc, or a disc still spinning up
gives a plain-language notification instead of failing silently.

Reading the drive needs group cdrom, which the postinst grants and the
OTA reboot activates. Commercial CSS discs additionally need libdvdcss,
which Debian cannot ship; classroom-dvd-css-setup bootstraps it from
contrib. That is deliberately not run from the postinst, which executes
while dpkg already holds the apt lock.

The optical helpers live in a shared module both the dock and
classroom-dvd import, and the dock imports it defensively: if it ever
goes missing the shell loses disc detection rather than failing to
start.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
ekklesia
2026-09-04 17:07:25 -05:00
co-authored by Claude Opus 5
parent 6b133bdc3e
commit 0c1acfe5f5
7 changed files with 438 additions and 3 deletions
+164
View File
@@ -0,0 +1,164 @@
#!/usr/bin/env python3
"""Classroom DVD control.
Discs are never played automatically. Inserting a disc only produces a
notification and changes the dock icon; playback always starts from a
deliberate press of the DVD button.
"""
import argparse
import os
import shutil
import subprocess
import sys
sys.path.insert(0, "/usr/local/lib/ekklesia-classroom")
sys.path.insert(
0,
os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "lib"),
)
import classroom_optical as optical # noqa: E402
PLAYER = "vlc"
WINDOW_TOOL = "/usr/local/bin/classroom-window"
def notify(title, message, urgency="normal"):
try:
subprocess.Popen(
[
"notify-send",
"--app-name=Ekklesia Classroom",
f"--urgency={urgency}",
"--",
title,
message,
],
start_new_session=True,
)
except OSError:
print(f"{title}: {message}", file=sys.stderr)
def player_command(device):
return [
PLAYER,
"--fullscreen",
"--no-video-title-show",
"--no-qt-privacy-ask",
"--no-qt-updates-notif",
f"dvd://{device}",
]
def play(device):
"""Hand the disc to the player through the normal window toggle."""
if shutil.which(PLAYER) is None:
notify(
"DVD",
"The DVD player is not installed on this classroom computer.",
)
return 1
subprocess.run(
[
WINDOW_TOOL,
"toggle",
"--match",
"(?i)vlc",
"--",
*player_command(device),
]
)
return 0
def action_toggle(force_play=False):
device = optical.default_device()
if device is None:
notify("DVD", "No DVD drive is connected to this classroom computer.")
return 1
status = optical.drive_status(device)
if status == optical.CDS_DISC_OK:
return play(device)
if status == optical.CDS_DRIVE_NOT_READY:
notify("DVD", "Reading the disc. Please try again in a moment.")
return 1
if status == optical.CDS_TRAY_OPEN:
notify("DVD", "The disc tray is open. Insert a disc to get started.")
return 1
if force_play:
return play(device)
notify("DVD", "No disc is in the drive. Insert a disc to get started.")
return 1
def action_status():
device = optical.default_device()
if device is None:
print("drive: none")
return 1
status = optical.drive_status(device)
print(f"drive: {device}")
print(f"status: {optical.describe(status)}")
print(f"player: {shutil.which(PLAYER) or 'not installed'}")
if status == optical.CDS_DISC_OK:
print(f"disc: {optical.disc_status(device)}")
return 0
return 1
def action_eject():
device = optical.default_device()
if device is None:
notify("DVD", "No DVD drive is connected to this classroom computer.")
return 1
if not optical.eject(device):
notify("DVD", "The disc could not be ejected. It may still be playing.")
return 1
return 0
def main():
parser = argparse.ArgumentParser(description="Classroom DVD control.")
subparsers = parser.add_subparsers(dest="action", required=True)
subparsers.add_parser("toggle", help="Dock button behaviour")
subparsers.add_parser("play", help="Start playback even if the drive is unsure")
subparsers.add_parser("status", help="Report drive and disc state")
subparsers.add_parser("eject", help="Open the disc tray")
arguments = parser.parse_args()
if arguments.action == "toggle":
return action_toggle()
if arguments.action == "play":
return action_toggle(force_play=True)
if arguments.action == "status":
return action_status()
return action_eject()
if __name__ == "__main__":
sys.exit(main())