Files
privatestudio/privatestudio/settings/base.py
T
Shaun KrugerandClaude Opus 5.5 73b549cb18
Build and publish / cleanup (pull_request) Successful in 17s
Build and publish / test (pull_request) Skipped
Build and publish / build (pull_request) Skipped
Build and publish / pypi (pull_request) Skipped
Add transcode/packaging worker, job slugs, deletes and zip downloads
Worker:
- manage.py run_worker polls the database for pending transcode jobs (ffmpeg)
  and packaging jobs (Bento4 mp4fragment + mp4hls). Jobs are claimed with a
  conditional UPDATE, a heartbeat thread marks progress, stale jobs are failed,
  and SIGTERM returns an interrupted job to the queue.
- SQLite runs in WAL mode with IMMEDIATE transactions and a busy timeout so the
  web server and worker can share the database.
- transcode.py exposes a reusable transcode() and the HW->CPU fallback works.
- Docker image includes ffmpeg and a checksum-verified Bento4 SDK.

Jobs and storage:
- TranscodeJob and PackagingJob have slugs, set explicitly on creation; outputs
  go to transcodes/<slug>/ and packages/<slug>/hls/. Migrations regenerated.
- Uploads into transcodes/ and packages/ are refused; the uploader defaults to
  the videos/raw folder.

UI:
- New packaging job button on transcode jobs.
- Delete views for packaging jobs, transcode jobs, uploaded files and content
  entries, each removing files before records and refusing while referenced.
  TranscodeJob.asset is now SET_NULL so deleting a source keeps its jobs.
- Streamed zip downloads for completed transcode jobs and packages, rooted at
  the job slug; the content page lists packages with download buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 16:34:44 -07:00

161 lines
4.9 KiB
Python

"""
Base Django settings for the privatestudio project.
Environment specific settings live in dev.py and production.py.
"""
import os
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)
# Application definition
INSTALLED_APPS = [
"privatestudio.studio.app.StudioConfig",
"corsheaders",
"ninja",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"allauth",
"allauth.account",
"allauth.socialaccount",
]
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"allauth.account.middleware.AccountMiddleware",
]
MESSAGE_STORAGE = "django.contrib.messages.storage.session.SessionStorage"
ROOT_URLCONF = "privatestudio.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [
os.path.join(PROJECT_DIR, "templates"),
],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "privatestudio.wsgi.application"
ASGI_APPLICATION = "privatestudio.asgi.application"
LOGGING = {
"version": 1,
"disable_existing_loggers": False,
"handlers": {
"console": {
"class": "logging.StreamHandler",
},
},
"loggers": {
"privatestudio": {
"handlers": ["console"],
"level": "INFO",
},
},
}
# Database
# The web server and the job worker use the database at the same time. WAL lets
# readers and the writer proceed concurrently. IMMEDIATE takes the write lock when
# a transaction starts, so a read-then-write waits (up to "timeout" seconds)
# instead of failing with "database is locked".
SQLITE_OPTIONS = {
"transaction_mode": "IMMEDIATE",
"timeout": 20,
"init_command": "PRAGMA journal_mode=WAL; PRAGMA synchronous=NORMAL;",
}
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
"OPTIONS": SQLITE_OPTIONS,
}
}
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
AUTH_PASSWORD_VALIDATORS = [
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator"},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"},
]
# Internationalization
LANGUAGE_CODE = "en-us"
TIME_ZONE = os.environ.get("DJANGO_TIME_ZONE", "UTC")
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.2/howto/static-files/
STATICFILES_FINDERS = [
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
]
STATICFILES_DIRS = [
os.path.join(PROJECT_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"
# Object bodies are streamed, so this only limits API and form bodies.
DATA_UPLOAD_MAX_MEMORY_SIZE = 10 * 1024 * 1024
# Private Studio configuration
PRIVATESTUDIO_STORAGE_PATH = os.environ.get("STORAGE_PATH", os.path.join(BASE_DIR, "storage"))
PRIVATESTUDIO_S3_CREDENTIAL_TTL_HOURS = int(os.environ.get("S3_CREDENTIAL_TTL_HOURS", "1"))
# Size of the parts the browser uploader sends. Larger parts are used for files that need over 10,000.
PRIVATESTUDIO_UPLOAD_PART_SIZE = int(os.environ.get("UPLOAD_PART_SIZE_MB", "16")) * 1024 * 1024
# Largest multipart upload in bytes. 0 means no limit.
PRIVATESTUDIO_UPLOAD_MAX_SIZE = int(os.environ.get("UPLOAD_MAX_SIZE", "0"))
# cleanup_uploads removes unfinished uploads without activity for this long.
PRIVATESTUDIO_UPLOAD_EXPIRY_DAYS = int(os.environ.get("UPLOAD_EXPIRY_DAYS", "7"))
# Job worker (manage.py run_worker)
# Directory holding the Bento4 tools (mp4fragment, mp4hls). Empty means use PATH.
PRIVATESTUDIO_BENTO4_BIN = os.environ.get("BENTO4_BIN", "")
# A running job without a heartbeat for this long is marked failed.
PRIVATESTUDIO_WORKER_STALE_SECONDS = int(os.environ.get("WORKER_STALE_SECONDS", "300"))