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:
co-authored by
Claude Opus 5
parent
6b133bdc3e
commit
0c1acfe5f5
+53
-3
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
@@ -11,11 +12,23 @@ gi.require_version("GtkLayerShell", "0.1")
|
||||
|
||||
from gi.repository import Gtk, Gdk, GdkPixbuf, GLib, GtkLayerShell
|
||||
|
||||
# Optional on purpose. The dock is the one thing the classroom cannot
|
||||
# afford to lose, so a missing DVD helper simply disables disc detection
|
||||
# instead of taking the whole shell down.
|
||||
sys.path.insert(0, "/usr/local/lib/ekklesia-classroom")
|
||||
|
||||
try:
|
||||
import classroom_optical as optical
|
||||
except ImportError:
|
||||
optical = None
|
||||
|
||||
|
||||
CONFIG_FILE = Path("/etc/ekklesia-classroom/device.conf")
|
||||
CSS_FILE = Path("/etc/ekklesia-classroom/dock/style.css")
|
||||
ICON_DIR = Path("/etc/ekklesia-classroom/icons")
|
||||
|
||||
DVD_POLL_SECONDS = 2
|
||||
|
||||
|
||||
def read_device_config():
|
||||
config = {}
|
||||
@@ -110,6 +123,9 @@ class ClassroomShell(Gtk.Window):
|
||||
|
||||
self.config = read_device_config()
|
||||
|
||||
self.dvd_image = None
|
||||
self.disc_ready = None
|
||||
|
||||
GtkLayerShell.init_for_window(self)
|
||||
GtkLayerShell.set_layer(
|
||||
self,
|
||||
@@ -207,9 +223,8 @@ class ClassroomShell(Gtk.Window):
|
||||
dock.pack_start(
|
||||
self.make_button(
|
||||
self.dvd_icon(),
|
||||
lambda *_: notify(
|
||||
"DVD",
|
||||
"DVD support is being prepared.",
|
||||
lambda *_: launch(
|
||||
["/usr/local/bin/classroom-dvd", "toggle"]
|
||||
),
|
||||
),
|
||||
False,
|
||||
@@ -217,6 +232,8 @@ class ClassroomShell(Gtk.Window):
|
||||
0,
|
||||
)
|
||||
|
||||
self.start_disc_watch()
|
||||
|
||||
dock.pack_start(
|
||||
self.make_button(
|
||||
self.sanctuary_icon(),
|
||||
@@ -268,6 +285,7 @@ class ClassroomShell(Gtk.Window):
|
||||
)
|
||||
|
||||
if image is not None:
|
||||
self.dvd_image = image
|
||||
return image
|
||||
|
||||
image = themed_icon(
|
||||
@@ -307,6 +325,38 @@ class ClassroomShell(Gtk.Window):
|
||||
|
||||
return image
|
||||
|
||||
def start_disc_watch(self):
|
||||
if optical is None:
|
||||
return
|
||||
|
||||
self.check_disc()
|
||||
|
||||
GLib.timeout_add_seconds(
|
||||
DVD_POLL_SECONDS,
|
||||
self.check_disc,
|
||||
)
|
||||
|
||||
def check_disc(self):
|
||||
ready = optical.drive_status() == optical.CDS_DISC_OK
|
||||
|
||||
# The disc indicator: the DVD logo sits back when the drive is
|
||||
# empty or unplugged and comes up to full strength once a disc is
|
||||
# ready, the same gray/colour language the LIVE icon uses.
|
||||
if self.dvd_image is not None:
|
||||
self.dvd_image.set_opacity(1.0 if ready else 0.55)
|
||||
|
||||
# The first poll only records what is already in the drive, so a
|
||||
# disc left in over the week does not announce itself at boot.
|
||||
if self.disc_ready is not None and ready and not self.disc_ready:
|
||||
notify(
|
||||
"DVD Ready",
|
||||
"A disc is ready to play.",
|
||||
)
|
||||
|
||||
self.disc_ready = ready
|
||||
|
||||
return True
|
||||
|
||||
def update_time(self):
|
||||
self.clock.set_text(
|
||||
datetime.now().strftime("%-I:%M %p")
|
||||
|
||||
Executable
+164
@@ -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())
|
||||
Executable
+61
@@ -0,0 +1,61 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# One-time bootstrap for encrypted (commercial) DVD-Video playback.
|
||||
#
|
||||
# Most retail DVDs are CSS encrypted. Debian cannot ship the decryption
|
||||
# library, so libdvdcss has to be built on the machine from the contrib
|
||||
# package libdvd-pkg. This is deliberately NOT run from the package
|
||||
# postinst: it needs the network, it compiles a package, and it must not
|
||||
# run while dpkg already holds the apt lock during an OTA update.
|
||||
#
|
||||
# Run this once, as root, on any classroom that needs commercial discs:
|
||||
#
|
||||
# sudo classroom-dvd-css-setup
|
||||
#
|
||||
# Unencrypted discs (church curriculum, home-burned video) play without it.
|
||||
|
||||
if [[ "$(id -u)" -ne 0 ]]; then
|
||||
echo "classroom-dvd-css-setup must be run as root." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ -e /usr/lib/x86_64-linux-gnu/libdvdcss.so.2 ]]; then
|
||||
echo "libdvdcss is already installed. Nothing to do."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Enabling the Debian contrib component..."
|
||||
|
||||
if ! grep -rqs 'contrib' /etc/apt/sources.list /etc/apt/sources.list.d/; then
|
||||
if [[ -f /etc/apt/sources.list.d/debian.sources ]]; then
|
||||
sed -i 's/^\(Components:.*\)$/\1 contrib/' \
|
||||
/etc/apt/sources.list.d/debian.sources
|
||||
else
|
||||
echo "Could not find a Debian sources file to add contrib to." >&2
|
||||
echo "Add 'contrib' manually and re-run this script." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Installing libdvd-pkg..."
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
apt-get update
|
||||
apt-get install -y libdvd-pkg
|
||||
|
||||
echo "Building libdvdcss..."
|
||||
|
||||
# libdvd-pkg downloads and builds libdvdcss during reconfigure.
|
||||
dpkg-reconfigure -f noninteractive libdvd-pkg
|
||||
|
||||
if [[ -e /usr/lib/x86_64-linux-gnu/libdvdcss.so.2 ]]; then
|
||||
echo
|
||||
echo "libdvdcss installed. Commercial DVDs should now play."
|
||||
echo "Test with an actual disc before relying on it."
|
||||
else
|
||||
echo
|
||||
echo "libdvdcss was not installed. Commercial discs will not play." >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user