Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Script] Check media API sidecars before importing clips into an Unraid share

Featured Replies

A media importer can write a JSON result before the video finishes arriving. If a nightly job treats that first file as proof the clip is ready, it can try to move an incomplete pair. This small check lists the pairs and the exceptions before anything touches the library share.

The input is a flat staging share with local names such as clip-001.json and clip-001.mp4. Use an ID you generate yourself and store it in the sidecar as {"clip_id":"clip-001"}. Keep the raw provider response outside the share. The report prints only the local ID and a status. It never opens a video for reading, fetches a URL, or writes to the staging share. For consistency, have the importer keep in-progress files under temporary extensions and rename each file after it's complete.

I maintain EasyDown. Its API documentation is an upstream reference if your authorized clips start as public post URLs. The example runs on locally generated metadata and makes no billable requests. Codex assisted with the script and write-up.

Save this as audit_intake.py.

"""Report local clip pairs from a staging directory, one JSON object per line."""

import argparse
import json
from pathlib import Path
import re


def status_for(clip_id, metadata, video):
    if metadata is None:
        return "missing_metadata"
    if metadata.is_symlink() or (video is not None and video.is_symlink()):
        return "symlink"
    if not metadata.is_file():
        return "invalid_metadata"
    try:
        with metadata.open("rb") as source:
            data = json.loads(source.read(4097))
            if source.tell() > 4096:
                return "invalid_metadata"
    except (OSError, ValueError, RecursionError):
        return "invalid_metadata"
    if not isinstance(data, dict) or data.get("clip_id") != clip_id:
        return "invalid_metadata"
    if video is None or not video.is_file():
        return "missing_video"
    if video.stat().st_size == 0:
        return "empty_video"
    return "paired"


def audit(directory):
    ids = {}
    for entry in directory.iterdir():
        if entry.suffix in (".json", ".mp4") and re.fullmatch(
            r"clip-[0-9]{3,8}", entry.stem
        ):
            ids.setdefault(entry.stem, {})[entry.suffix] = entry
    for clip_id, files in sorted(ids.items()):
        yield {
            "clip_id": clip_id,
            "status": status_for(clip_id, files.get(".json"), files.get(".mp4")),
        }


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("directory", type=Path)
    args = parser.parse_args()
    for row in audit(args.directory):
        print(json.dumps(row))

First, try it in an empty staging test directory. Start with one nonempty dummy file to represent a completed download and a sidecar without a matching video.

printf '%s\n' '{"clip_id":"clip-001"}' > clip-001.json
printf '%s\n' 'dummy clip' > clip-001.mp4
printf '%s\n' '{"clip_id":"clip-002"}' > clip-002.json
python3 /path/to/audit_intake.py .

Expected result:

{"clip_id": "clip-001", "status": "paired"}
{"clip_id": "clip-002", "status": "missing_video"}

On Unraid, point the input mount at the staging share and the script mount at the saved file. With the image available locally, this runs the check with a read-only filesystem and networking disabled.

docker run --rm --network none --read-only --cap-drop ALL \
  -v /mnt/user/media-staging:/intake:ro \
  -v /mnt/user/appdata/intake-check/audit_intake.py:/audit_intake.py:ro \
  python:3.13-alpine python /audit_intake.py /intake

Treat paired as a file-presence check. It means the ID matches and the MP4 has bytes. A downstream import can still check codec or duration with ffprobe. The script doesn't touch other names in the share, including in-progress files with a temporary extension.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.