Files
xenia-pos-local/local_backend/models/media.py
T
bonaminandClaude Opus 5.5 b5361e10ca feat(media): video versions: still frame + a version every screen plays (platform-v2 5.4e)
- services/video.py: background worker (one video at a time, low priority) makes a still
  frame (thumb/card/full WebP) and, when needed, play.mp4 (H.264+AAC, <=1920 px, HDR
  tone-mapped, faststart); the original is kept. Media.processing/progress (migration 0031,
  existing videos queued). ffmpeg from the pinned imageio-ffmpeg wheel; none = as uploaded.
- MOV (video/quicktime) accepted; /api/media/file/<sha>/play served with ranges.
- Signage plays the version (poster = still frame) and tells the screens playing it when ready.
- Manager library: still frames in the grid, preparing progress, status in the details.
- Tests: test_video.py (8), backend 541 passed; e2e media/signage/stack new checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 02:10:22 +02:00

48 lines
2.6 KiB
Python

"""The media library (plan step 5.1): every picture and video the venue uses, kept once.
A row is one file, identified by the sha256 of its bytes (unique: uploading the same file
again returns the existing row). The bytes live under `data/media/<sha[:2]>/<sha>/`
(services/media.py): the original as uploaded, and for images three WebP sizes (thumb,
card, full). Files are served by hash at `/api/media/file/<sha>/<variant>` with long cache
headers, so a URL never changes meaning: a different file is a different URL.
Rows are referenced by id from what uses them (products, the customer display, signage;
steps 5.2-5.4). Those users register a usage check in services/media.py so a file in use
can't be deleted.
"""
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from sqlalchemy.orm import relationship
from core.timeutil import UTCDateTime, utcnow
from database import Base
class Media(Base):
__tablename__ = "media"
id = Column(Integer, primary_key=True, index=True)
kind = Column(String, nullable=False, index=True) # image | video
name = Column(String, nullable=False) # shown in the library; editable
original_name = Column(String, nullable=True) # the uploaded file's name
content_type = Column(String, nullable=False) # of the original
sha256 = Column(String(64), nullable=False, unique=True)
bytes = Column(Integer, nullable=False) # of the original
width = Column(Integer, nullable=True) # images; videos when the file says
height = Column(Integer, nullable=True)
duration_ms = Column(Integer, nullable=True) # videos (MP4) when the file says
uploaded_by = Column(Integer, ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
created_at = Column(UTCDateTime, default=utcnow, nullable=False)
# Shipped with the server (assets/builtin_media, step 5.4a): can't be deleted or renamed
builtin = Column(Boolean, nullable=False, default=False, server_default='0')
# Videos (step 5.4e, services/video.py): the still frame and the version every screen plays are
# made in the background. waiting | working | done | failed; None = nothing to do (pictures,
# or no video tool on this server). `progress` 0-100 while working.
processing = Column(String, nullable=True)
progress = Column(Integer, nullable=True)
uploader = relationship("User", lazy="joined")
@property
def uploaded_by_name(self):
return self.uploader.full_name or self.uploader.username if self.uploader is not None else None