"""Local file ingest for the download center (E7 S5) — the non-yt-dlp path into the media library. A user-uploaded file joins the SAME library as a downloaded one, so it inherits the whole function set already built (metadata chips, share links, and — for media — in-app play/edit). Unlike a download it bypasses yt-dlp AND the worker entirely: the file is already on the host, so ingest probes it, places it on disk, and creates an already-`ready` MediaAsset + `done` DownloadJob in one step — the same "the file exists, mark it done now" shortcut `service.enqueue` takes on a cache hit. Kinds (the invariant lives in `mediakind`): a probe with a real video stream -> video, audio-only -> audio, neither -> a generic 'file' (pdf/zip/docx/…) that is download-only and never rendered inline (see the force-download serving in the file/watch routes). This module is the ingest seam a future sub-function (e.g. convert) plugs a new adapter into, mirroring how it sidesteps the worker. An upload does NOT get an `expires_at`: it's user-provided and may be irreplaceable (there's no source to re-download), so it doesn't age out on the retention clock the way a re-fetchable download does — it lives until the user deletes it. """ import secrets from datetime import datetime, timezone from pathlib import Path from sqlalchemy.orm import Session from app.config import settings from app.downloads import edit as editmod from app.downloads import mediakind, quota, service, storage from app.models import DownloadJob, MediaAsset # ffprobe container formats that mean "this is a still image / image sequence", NOT playable media. # A standalone jpg/png/gif/webp/bmp reports a real video stream (codec mjpeg/png/…) with no # `attached_pic` flag, so without this guard it would classify as media_kind='video' and get a Play # button + a broken in-app