Compare commits
10
Commits
3fe49b47ea
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1e7483d9c6 | ||
|
|
de13523ffd | ||
|
|
b5fd00250b | ||
|
|
23218b15f5 | ||
|
|
5d7d03a0a6 | ||
|
|
38f3a0da2f | ||
|
|
ba76671795 | ||
|
|
7231f69014 | ||
|
|
e582cb9234 | ||
|
|
5bb9a70c11 |
@@ -0,0 +1,21 @@
|
||||
.git/
|
||||
.gitea/
|
||||
.github/
|
||||
.idea/
|
||||
.vscode/
|
||||
.venv/
|
||||
venv/
|
||||
.pytest_cache/
|
||||
node_modules/
|
||||
storage/
|
||||
static/
|
||||
dist/
|
||||
build/
|
||||
*.egg-info/
|
||||
**/__pycache__
|
||||
*.pyc
|
||||
*.sqlite3
|
||||
*.db
|
||||
privatestudio/_version.py
|
||||
privatestudio/settings/local.py
|
||||
privatestudio/static/bundle/
|
||||
@@ -0,0 +1,215 @@
|
||||
name: Build and publish
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
types: [opened, synchronize, reopened, closed]
|
||||
workflow_dispatch: {}
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
packages: write
|
||||
|
||||
env:
|
||||
REGISTRY: git.krugerprojects.com
|
||||
IMAGE_NAME: skruger/privatestudio
|
||||
|
||||
jobs:
|
||||
test:
|
||||
if: github.event.action != 'closed'
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Python
|
||||
uses: astral-sh/setup-uv@v6
|
||||
with:
|
||||
python-version: "3.13"
|
||||
activate-environment: true
|
||||
|
||||
- name: Install package
|
||||
run: uv pip install -e ".[dev]"
|
||||
|
||||
- name: Run tests
|
||||
run: pytest
|
||||
|
||||
build:
|
||||
if: github.event.action != 'closed'
|
||||
needs: test
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
tag: ${{ steps.tag.outputs.tag }}
|
||||
version: ${{ steps.tag.outputs.version }}
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Determine image tags
|
||||
id: tag
|
||||
run: |
|
||||
set -euo pipefail
|
||||
git fetch --tags
|
||||
current_tag=$(git tag --points-at HEAD | head -n1)
|
||||
if [ "$GITHUB_EVENT_NAME" = "pull_request" ]; then
|
||||
PR_NUMBER=$(echo "$GITHUB_REF" | cut -d'/' -f3)
|
||||
TAG="pr-${PR_NUMBER}"
|
||||
VERSION="0.0.0.dev${PR_NUMBER}"
|
||||
tags="${TAG} ${GITHUB_SHA::7}"
|
||||
elif [ -n "$current_tag" ]; then
|
||||
echo "Head already tagged: $current_tag"
|
||||
TAG="$current_tag"
|
||||
VERSION=${TAG#v}
|
||||
tags="latest ${VERSION} ${GITHUB_SHA::7}"
|
||||
else
|
||||
latest_tag=$(git tag --sort=-v:refname | head -n1 || true)
|
||||
if [ -z "$latest_tag" ]; then
|
||||
latest_tag="v0.0.0"
|
||||
fi
|
||||
sem=${latest_tag#v}
|
||||
IFS='.' read -r major minor patch <<< "${sem}"
|
||||
major=${major:-0}
|
||||
minor=${minor:-0}
|
||||
patch=${patch:-0}
|
||||
patch=$((patch+1))
|
||||
TAG="v${major}.${minor}.${patch}"
|
||||
git config user.name "gitea-actions"
|
||||
git config user.email "gitea-actions@git.krugerprojects.com"
|
||||
git tag -a "$TAG" -m "Release $TAG"
|
||||
git push origin "$TAG"
|
||||
VERSION=${TAG#v}
|
||||
tags="latest ${VERSION} ${GITHUB_SHA::7}"
|
||||
fi
|
||||
echo "Determined tag: $TAG, version: $VERSION, image tags: $tags"
|
||||
echo "tag=$TAG" >> $GITHUB_OUTPUT
|
||||
echo "version=$VERSION" >> $GITHUB_OUTPUT
|
||||
echo "tags=$tags" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Install dependencies
|
||||
run: apt-get update && apt-get install -y podman
|
||||
|
||||
- name: Login to registry
|
||||
run: |
|
||||
echo -e "${{ secrets.PACKAGE_ACCESS_TOKEN }}" | \
|
||||
podman login ${REGISTRY} -u "${{ vars.PACKAGE_USERNAME }}" --password-stdin
|
||||
|
||||
- name: Build image
|
||||
run: |
|
||||
set -euo pipefail
|
||||
IMAGE="${REGISTRY}/${IMAGE_NAME}"
|
||||
buildah bud --userns=host -f Dockerfile \
|
||||
--build-arg VERSION="${{ steps.tag.outputs.version }}" \
|
||||
-t "${IMAGE}:build" .
|
||||
for t in ${{ steps.tag.outputs.tags }}; do
|
||||
echo "Tag: ${IMAGE}:${t}"
|
||||
buildah tag "${IMAGE}:build" "${IMAGE}:${t}"
|
||||
done
|
||||
|
||||
- name: Push image
|
||||
run: |
|
||||
set -euo pipefail
|
||||
IMAGE="${REGISTRY}/${IMAGE_NAME}"
|
||||
for t in ${{ steps.tag.outputs.tags }}; do
|
||||
echo "Push: ${IMAGE}:${t}"
|
||||
buildah push "${IMAGE}:${t}"
|
||||
done
|
||||
|
||||
pypi:
|
||||
# Only publish releases from main, and only when a PyPI token is configured.
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
needs: build
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
|
||||
|
||||
steps:
|
||||
- name: Check for PyPI token
|
||||
run: |
|
||||
if [ -z "$PYPI_TOKEN" ]; then
|
||||
echo "PYPI_TOKEN secret is not set; skipping PyPI publish."
|
||||
fi
|
||||
|
||||
- name: Checkout repository
|
||||
if: env.PYPI_TOKEN != ''
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up Node
|
||||
if: env.PYPI_TOKEN != ''
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: "24"
|
||||
|
||||
- name: Build static bundle
|
||||
if: env.PYPI_TOKEN != ''
|
||||
run: |
|
||||
mkdir -p privatestudio/static/bundle
|
||||
npm ci
|
||||
npm run build
|
||||
|
||||
- name: Set up Python
|
||||
if: env.PYPI_TOKEN != ''
|
||||
uses: astral-sh/setup-uv@v6
|
||||
with:
|
||||
python-version: "3.13"
|
||||
activate-environment: true
|
||||
|
||||
- name: Build distributions
|
||||
if: env.PYPI_TOKEN != ''
|
||||
env:
|
||||
SETUPTOOLS_SCM_PRETEND_VERSION: ${{ needs.build.outputs.version }}
|
||||
run: |
|
||||
uv pip install build twine
|
||||
python -m build
|
||||
twine check dist/*
|
||||
|
||||
- name: Publish to PyPI
|
||||
if: env.PYPI_TOKEN != ''
|
||||
env:
|
||||
TWINE_USERNAME: __token__
|
||||
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
|
||||
run: twine upload --non-interactive dist/*
|
||||
|
||||
cleanup:
|
||||
# Only run when a pull request is closed and merged
|
||||
if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Install jq
|
||||
run: |
|
||||
apt-get update && apt-get install -y jq
|
||||
|
||||
- name: Delete PR images from Gitea package registry
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SERVER: ${{ gitea.server_url }}
|
||||
OWNER: skruger
|
||||
PACKAGE: privatestudio
|
||||
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||
run: |
|
||||
set -euo pipefail
|
||||
echo "Cleaning up Gitea registry images for PR #$PR_NUMBER"
|
||||
AUTH_HEADER="Authorization: token ${GITEA_TOKEN}"
|
||||
LIST_URL="${SERVER}/api/v1/packages/${OWNER}?type=container&q=${PACKAGE}&limit=50"
|
||||
VERSIONS_JSON=$(curl -s -H "$AUTH_HEADER" "$LIST_URL")
|
||||
MATCHES=$(echo "$VERSIONS_JSON" | jq -r --arg pr "pr-$PR_NUMBER" \
|
||||
'.[] | select(.version == $pr) | .version')
|
||||
if [ -z "$(echo "$MATCHES" | tr -d '\n')" ]; then
|
||||
echo "No image versions found for PR #$PR_NUMBER"
|
||||
exit 0
|
||||
fi
|
||||
for VERSION in $MATCHES; do
|
||||
echo "Deleting package version $VERSION"
|
||||
curl -s -X DELETE -H "$AUTH_HEADER" \
|
||||
"${SERVER}/api/v1/packages/${OWNER}/container/${PACKAGE}/${VERSION}" \
|
||||
|| echo "Failed to delete package version $VERSION"
|
||||
done
|
||||
echo "Cleanup complete."
|
||||
+1
-1
@@ -13,5 +13,5 @@ __pycache__/
|
||||
|
||||
db.sqlite3
|
||||
privatestudio/settings/local.py
|
||||
static/
|
||||
privatestudio/static/bundle/
|
||||
node_modules/
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
FROM node:24 AS nodebuild
|
||||
|
||||
WORKDIR /build
|
||||
|
||||
COPY package.json package-lock.json ./
|
||||
RUN npm ci
|
||||
|
||||
COPY webpack.config.js ./
|
||||
COPY src ./src
|
||||
COPY privatestudio ./privatestudio
|
||||
RUN mkdir -p privatestudio/static/bundle && npm run build
|
||||
|
||||
|
||||
FROM python:3.13-slim-trixie
|
||||
|
||||
# Version used by setuptools_scm, since .git is not copied into the image.
|
||||
ARG VERSION=0.0.0
|
||||
|
||||
RUN useradd --create-home privatestudio
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
ENV PYTHONUNBUFFERED=1 \
|
||||
PORT=8000 \
|
||||
DJANGO_SETTINGS_MODULE=privatestudio.settings.production \
|
||||
STORAGE_PATH=/data/storage
|
||||
|
||||
RUN pip install --no-cache-dir "gunicorn~=23.0" "psycopg2-binary~=2.9.11"
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY --chown=privatestudio:privatestudio . .
|
||||
COPY --from=nodebuild --chown=privatestudio:privatestudio /build/privatestudio/static/bundle ./privatestudio/static/bundle
|
||||
|
||||
RUN SETUPTOOLS_SCM_PRETEND_VERSION="${VERSION}" pip install --no-cache-dir . \
|
||||
&& mkdir -p /data/storage && chown -R privatestudio:privatestudio /data /app
|
||||
|
||||
USER privatestudio
|
||||
|
||||
RUN python manage.py collectstatic --noinput --clear
|
||||
|
||||
VOLUME ["/data"]
|
||||
|
||||
# Migrating at startup keeps "docker run" simple. Use a release step instead if
|
||||
# you run more than one container against the same database.
|
||||
CMD set -xe; \
|
||||
python manage.py migrate --noinput; \
|
||||
exec gunicorn privatestudio.wsgi:application \
|
||||
--bind 0.0.0.0:${PORT} \
|
||||
-k gthread --workers 2 --threads 8 --timeout 600
|
||||
@@ -0,0 +1,28 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2026, Shaun Kruger
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -0,0 +1,3 @@
|
||||
# The JS/CSS bundle is built by npm and is not tracked in git, so
|
||||
# setuptools_scm will not pick it up on its own.
|
||||
graft privatestudio/static/bundle
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
"build:digitalocean": "npm install --production=false && npm run build"
|
||||
},
|
||||
"author": "Shaun Kruger",
|
||||
"license": "ISC",
|
||||
"license": "BSD-3-Clause",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"node": "v24.22.x",
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
import nh3
|
||||
|
||||
from django import forms
|
||||
from django.forms import Textarea
|
||||
|
||||
NH3_TAGS = {
|
||||
"a",
|
||||
"p",
|
||||
"strong",
|
||||
"img",
|
||||
"ul",
|
||||
"ol",
|
||||
"li",
|
||||
"b",
|
||||
"s",
|
||||
"u",
|
||||
"i",
|
||||
"em",
|
||||
}
|
||||
|
||||
NH3_ATTR = {
|
||||
"a": {
|
||||
"href",
|
||||
"target",
|
||||
},
|
||||
"img": {
|
||||
"alt",
|
||||
"src",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
class HtmlTextField(forms.CharField):
|
||||
widget = Textarea
|
||||
|
||||
def to_python(self, value):
|
||||
value = super().to_python(value)
|
||||
if value not in self.empty_values:
|
||||
value = nh3.clean(
|
||||
value,
|
||||
tags=NH3_TAGS,
|
||||
attributes=NH3_ATTR,
|
||||
)
|
||||
return value
|
||||
@@ -14,6 +14,13 @@ if os.environ.get("DATABASE_URL"):
|
||||
DATABASES = {
|
||||
"default": dj_database_url.config(),
|
||||
}
|
||||
else:
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": os.path.join("/data", "db.sqlite3"),
|
||||
}
|
||||
}
|
||||
|
||||
CORS_ALLOWED_ORIGINS = [o for o in os.environ.get("CORS_ALLOWED_ORIGINS", "").split(",") if o]
|
||||
|
||||
|
||||
@@ -1,9 +1,24 @@
|
||||
from django import forms
|
||||
|
||||
from privatestudio.studio.models import ContentAsset
|
||||
from privatestudio.studio.models import ContentAsset, TranscodeJob, TranscodeProfile
|
||||
from privatestudio.studio.profiles import validate_profile_definition
|
||||
from privatestudio.fields import HtmlTextField
|
||||
|
||||
YAML_TEXTAREA_ATTRS = {"rows": 20, "spellcheck": "false", "class": "form-control font-monospace yaml-editor"}
|
||||
|
||||
|
||||
class ContentAssetForm(forms.ModelForm):
|
||||
class BootstrapFormMixin:
|
||||
"""Adds Bootstrap classes to every widget that doesn't set its own."""
|
||||
|
||||
def apply_bootstrap(self):
|
||||
for field in self.fields.values():
|
||||
if "class" in field.widget.attrs:
|
||||
continue
|
||||
css = "form-select" if isinstance(field.widget, forms.Select) else "form-control"
|
||||
field.widget.attrs["class"] = css
|
||||
|
||||
|
||||
class ContentAssetForm(BootstrapFormMixin, forms.ModelForm):
|
||||
class Meta:
|
||||
model = ContentAsset
|
||||
fields = [
|
||||
@@ -14,10 +29,75 @@ class ContentAssetForm(forms.ModelForm):
|
||||
"release_date": forms.DateInput(attrs={"type": "date"}, format="%Y-%m-%d"),
|
||||
"description": forms.Textarea(attrs={"rows": 4}),
|
||||
}
|
||||
field_classes = {
|
||||
"description": HtmlTextField,
|
||||
}
|
||||
|
||||
def __init__(self, *args, studio, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["group"].queryset = studio.content_groups.all()
|
||||
for field in self.fields.values():
|
||||
css = "form-select" if isinstance(field.widget, forms.Select) else "form-control"
|
||||
field.widget.attrs["class"] = css
|
||||
self.apply_bootstrap()
|
||||
|
||||
|
||||
class TranscodeProfileForm(BootstrapFormMixin, forms.ModelForm):
|
||||
class Meta:
|
||||
model = TranscodeProfile
|
||||
fields = ["name", "profile_definition"]
|
||||
widgets = {"profile_definition": forms.Textarea(attrs=YAML_TEXTAREA_ATTRS)}
|
||||
labels = {"profile_definition": "Profile definition (YAML)"}
|
||||
|
||||
def __init__(self, *args, studio, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.studio = studio
|
||||
self.apply_bootstrap()
|
||||
|
||||
def clean_name(self):
|
||||
name = self.cleaned_data["name"].strip()
|
||||
duplicates = TranscodeProfile.objects.filter(studio=self.studio, name=name)
|
||||
if self.instance.pk:
|
||||
duplicates = duplicates.exclude(pk=self.instance.pk)
|
||||
if duplicates.exists():
|
||||
raise forms.ValidationError("A profile with this name already exists in this studio.")
|
||||
return name
|
||||
|
||||
def clean_profile_definition(self):
|
||||
text = self.cleaned_data["profile_definition"]
|
||||
validate_profile_definition(text)
|
||||
return text
|
||||
|
||||
|
||||
class TranscodeJobForm(BootstrapFormMixin, forms.ModelForm):
|
||||
class Meta:
|
||||
model = TranscodeJob
|
||||
fields = ["profile", "profile_definition"]
|
||||
widgets = {"profile_definition": forms.Textarea(attrs=YAML_TEXTAREA_ATTRS)}
|
||||
labels = {"profile_definition": "Profile definition (YAML)"}
|
||||
help_texts = {
|
||||
"profile_definition": "Copied from the selected profile. Changes here apply to this job only. "
|
||||
"Leave empty to use the profile as saved.",
|
||||
}
|
||||
|
||||
def __init__(self, *args, studio, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields["profile"].queryset = studio.transcode_profiles.order_by("name")
|
||||
self.apply_bootstrap()
|
||||
|
||||
def clean(self):
|
||||
cleaned = super().clean()
|
||||
profile = cleaned.get("profile")
|
||||
text = (cleaned.get("profile_definition") or "").strip()
|
||||
if not text and profile is not None:
|
||||
text = profile.profile_definition
|
||||
if not text:
|
||||
if "profile" not in self.errors:
|
||||
self.add_error("profile", "Choose a profile or enter a profile definition.")
|
||||
return cleaned
|
||||
try:
|
||||
validate_profile_definition(text)
|
||||
except forms.ValidationError as e:
|
||||
self.add_error("profile_definition", e)
|
||||
else:
|
||||
cleaned["profile_definition"] = text
|
||||
# Keep the instance in step with the copied definition before model validation runs.
|
||||
self.instance.profile_definition = text
|
||||
return cleaned
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# Generated by Django 6.1.3 on 2026-12-03 18:06
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('studio', '0003_content_assets'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='transcodedasset',
|
||||
name='content_asset',
|
||||
field=models.ForeignKey(default=0, on_delete=django.db.models.deletion.DO_NOTHING, related_name='transcoded_assets', to='studio.contentasset'),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='transcodejob',
|
||||
name='content_asset',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='transcode_jobs', to='studio.contentasset'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='transcodejob',
|
||||
name='status',
|
||||
field=models.CharField(choices=[('draft', 'Draft'), ('pending', 'Pending'), ('in_progress', 'In progress'), ('completed', 'Completed'), ('failed', 'Failed')], default='draft', max_length=20),
|
||||
),
|
||||
]
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 6.1.3 on 2026-12-03 21:52
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('studio', '0004_transcode_ui'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='transcodejob',
|
||||
name='transcode_output',
|
||||
field=models.TextField(blank=True, default=''),
|
||||
),
|
||||
]
|
||||
@@ -167,18 +167,48 @@ class TranscodeJob(models.Model):
|
||||
settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True, related_name="transcode_jobs",
|
||||
)
|
||||
asset = models.ForeignKey(UploadedAsset, on_delete=models.CASCADE, related_name="transcode_jobs")
|
||||
content_asset = models.ForeignKey(
|
||||
"ContentAsset", on_delete=models.SET_NULL, null=True, blank=True, related_name="transcode_jobs",
|
||||
)
|
||||
profile = models.ForeignKey(
|
||||
TranscodeProfile, on_delete=models.SET_NULL, null=True, blank=True, related_name="transcode_jobs",
|
||||
)
|
||||
# Inline profile definitions (or a snapshot of the named profile) used for this job.
|
||||
profile_definition = models.TextField(blank=True, default="")
|
||||
status = models.CharField(max_length=20, choices=JobStatus.choices, default=JobStatus.PENDING)
|
||||
status = models.CharField(max_length=20, choices=JobStatus.choices, default=JobStatus.DRAFT)
|
||||
requested_at = models.DateTimeField(default=timezone.now)
|
||||
completed_at = models.DateTimeField(null=True, blank=True)
|
||||
transcode_output = models.TextField(blank=True, default="")
|
||||
|
||||
def __str__(self):
|
||||
return f"Transcode job {self.pk} ({self.status})"
|
||||
|
||||
@property
|
||||
def is_editable(self) -> bool:
|
||||
return self.status == JobStatus.DRAFT
|
||||
|
||||
def clean(self):
|
||||
if self.pk is not None:
|
||||
stored = TranscodeJob.objects.filter(pk=self.pk).values_list("status", flat=True).first()
|
||||
if stored is not None and stored != JobStatus.DRAFT:
|
||||
raise ValidationError("Only draft jobs can be edited.")
|
||||
errors = {}
|
||||
if self.studio_id:
|
||||
if self.content_asset_id and self.content_asset.studio_id != self.studio_id:
|
||||
errors["content_asset"] = "The content must belong to the same studio."
|
||||
if self.profile_id and self.profile.studio_id != self.studio_id:
|
||||
errors["profile"] = "The profile must belong to the same studio."
|
||||
if self.asset_id and self.asset.studio_id != self.studio_id:
|
||||
errors["asset"] = "The file must belong to the same studio."
|
||||
if errors:
|
||||
raise ValidationError(errors)
|
||||
|
||||
def submit(self) -> bool:
|
||||
"""Move a draft job to pending. Returns False if it was no longer a draft."""
|
||||
changed = TranscodeJob.objects.filter(pk=self.pk, status=JobStatus.DRAFT).update(status=JobStatus.PENDING)
|
||||
self.refresh_from_db(fields=["status"])
|
||||
return bool(changed)
|
||||
|
||||
|
||||
class PackagingJob(models.Model):
|
||||
"""Requested packaging operation."""
|
||||
@@ -198,6 +228,7 @@ class PackagingJob(models.Model):
|
||||
class TranscodedAsset(models.Model):
|
||||
"""Output file from a transcode job."""
|
||||
studio = models.ForeignKey(Studio, on_delete=models.CASCADE, related_name="transcoded_assets")
|
||||
content_asset = models.ForeignKey("ContentAsset", on_delete=models.DO_NOTHING, related_name="transcoded_assets")
|
||||
transcode_job = models.ForeignKey(TranscodeJob, on_delete=models.CASCADE, related_name="transcoded_assets")
|
||||
filename = models.TextField()
|
||||
s3_path = models.TextField()
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
"""Validation for YAML transcode profile definitions."""
|
||||
from pathlib import Path
|
||||
|
||||
import yaml
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from privatestudio.transcode import ENCODER_MAP, parse_bitrate, parse_resolution
|
||||
|
||||
# Shipped inside the package (privatestudio/profiles/) so it is included in the wheel.
|
||||
DEFAULT_PROFILE_PATH = Path(__file__).resolve().parent.parent / "profiles" / "default.yaml"
|
||||
|
||||
EXAMPLE_PROFILE_YAML = """\
|
||||
# Optional: cpu, quicksync or nvidia (default cpu)
|
||||
encoder: cpu
|
||||
|
||||
# One entry per output rendition
|
||||
profiles:
|
||||
1080p:
|
||||
name: "Full HD" # optional label
|
||||
resolution: "1920x1080" # required, WIDTHxHEIGHT
|
||||
bitrate: "5000k" # optional, in kbit/s e.g. 2500k (default 1000k)
|
||||
codec: "h264" # optional (default h264)
|
||||
fps: 30 # optional (default 30)
|
||||
720p:
|
||||
resolution: "1280x720"
|
||||
bitrate: "2500k"
|
||||
"""
|
||||
|
||||
|
||||
def load_default_profile() -> str | None:
|
||||
"""Text of the bundled default profile, or None if it can't be read."""
|
||||
try:
|
||||
return DEFAULT_PROFILE_PATH.read_text(encoding="utf-8")
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
def validate_profile_definition(text: str) -> dict:
|
||||
"""Parse a YAML profile definition and check its structure. Raises ValidationError."""
|
||||
try:
|
||||
data = yaml.safe_load(text or "")
|
||||
except yaml.YAMLError as e:
|
||||
mark = getattr(e, "problem_mark", None)
|
||||
where = f" (line {mark.line + 1}, column {mark.column + 1})" if mark else ""
|
||||
problem = getattr(e, "problem", None) or str(e)
|
||||
raise ValidationError(f"Invalid YAML{where}: {problem}")
|
||||
if not isinstance(data, dict):
|
||||
raise ValidationError("The definition must be a YAML mapping with a 'profiles' section.")
|
||||
|
||||
errors = []
|
||||
encoder = data.get("encoder")
|
||||
if encoder is not None and str(encoder).lower() not in ENCODER_MAP:
|
||||
errors.append(f"'encoder' must be one of: {', '.join(ENCODER_MAP)}.")
|
||||
|
||||
profiles = data.get("profiles")
|
||||
if not isinstance(profiles, dict) or not profiles:
|
||||
errors.append("'profiles' must be a mapping with at least one entry.")
|
||||
raise ValidationError(errors)
|
||||
|
||||
for key, variant in profiles.items():
|
||||
if not isinstance(variant, dict):
|
||||
errors.append(f"Profile '{key}' must be a mapping.")
|
||||
continue
|
||||
try:
|
||||
width, height = parse_resolution(variant.get("resolution"))
|
||||
if width <= 0 or height <= 0:
|
||||
raise ValueError
|
||||
except (ValueError, TypeError):
|
||||
errors.append(f"Profile '{key}': 'resolution' is required in WIDTHxHEIGHT form, e.g. 1280x720.")
|
||||
if "bitrate" in variant:
|
||||
try:
|
||||
parse_bitrate(variant["bitrate"])
|
||||
except ValueError:
|
||||
errors.append(f"Profile '{key}': 'bitrate' must look like 2500k.")
|
||||
if "codec" in variant and not isinstance(variant["codec"], str):
|
||||
errors.append(f"Profile '{key}': 'codec' must be text.")
|
||||
if "fps" in variant:
|
||||
fps = variant["fps"]
|
||||
if isinstance(fps, bool) or not isinstance(fps, (int, float)) or fps <= 0:
|
||||
errors.append(f"Profile '{key}': 'fps' must be a positive number.")
|
||||
if errors:
|
||||
raise ValidationError(errors)
|
||||
return data
|
||||
@@ -1,10 +1,12 @@
|
||||
"""Transcode profile management endpoints (scoped to a studio)."""
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.shortcuts import get_object_or_404
|
||||
from ninja import Router, Schema
|
||||
from ninja.errors import HttpError
|
||||
|
||||
from privatestudio.studio.models import TranscodeProfile
|
||||
from privatestudio.studio.routers.common import get_studio_for_user, parse_yaml_body
|
||||
from privatestudio.studio.profiles import validate_profile_definition
|
||||
from privatestudio.studio.routers.common import get_studio_for_user
|
||||
|
||||
router = Router()
|
||||
|
||||
@@ -33,9 +35,13 @@ def create_profile(request, bucket: str, name: str):
|
||||
The request body must contain the YAML profile definition.
|
||||
"""
|
||||
studio = get_studio_for_user(request.auth, bucket)
|
||||
profile_data = parse_yaml_body(request)
|
||||
if "profiles" not in profile_data:
|
||||
raise HttpError(400, "Profile definition must contain a 'profiles' section")
|
||||
try:
|
||||
definition = request.body.decode("utf-8")
|
||||
validate_profile_definition(definition)
|
||||
except UnicodeDecodeError:
|
||||
raise HttpError(400, "The profile definition must be UTF-8 text")
|
||||
except ValidationError as e:
|
||||
raise HttpError(400, " ".join(e.messages))
|
||||
|
||||
if TranscodeProfile.objects.filter(studio=studio, name=name).exists():
|
||||
raise HttpError(409, f"Profile '{name}' already exists")
|
||||
@@ -44,7 +50,7 @@ def create_profile(request, bucket: str, name: str):
|
||||
studio=studio,
|
||||
created_by=request.auth,
|
||||
name=name,
|
||||
profile_definition=request.body.decode("utf-8"),
|
||||
profile_definition=definition,
|
||||
)
|
||||
return _profile_response(profile)
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
from typing import Optional
|
||||
|
||||
import yaml
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.shortcuts import get_object_or_404
|
||||
from ninja import Router, Schema
|
||||
from ninja.errors import HttpError
|
||||
|
||||
from privatestudio.studio.models import TranscodeJob, TranscodeProfile, UploadedAsset
|
||||
from privatestudio.studio.models import JobStatus, TranscodeJob, TranscodeProfile, UploadedAsset
|
||||
from privatestudio.studio.profiles import validate_profile_definition
|
||||
from privatestudio.studio.routers.common import get_studio_for_user, parse_yaml_body
|
||||
|
||||
router = Router()
|
||||
@@ -67,9 +69,11 @@ def request_transcode(request, bucket: str):
|
||||
raise HttpError(404, f"Profile '{profile_ref}' not found")
|
||||
profile_definition = profile.profile_definition
|
||||
elif isinstance(profile_ref, dict):
|
||||
if "profiles" not in profile_ref:
|
||||
raise HttpError(400, "Inline profile must contain a 'profiles' section")
|
||||
profile_definition = yaml.safe_dump(profile_ref)
|
||||
try:
|
||||
validate_profile_definition(profile_definition)
|
||||
except ValidationError as e:
|
||||
raise HttpError(400, "Invalid inline profile: " + " ".join(e.messages))
|
||||
else:
|
||||
raise HttpError(400, "Profile must be a string (name) or object (definition)")
|
||||
|
||||
@@ -79,6 +83,8 @@ def request_transcode(request, bucket: str):
|
||||
asset=asset,
|
||||
profile=profile,
|
||||
profile_definition=profile_definition,
|
||||
# API requests are submitted directly; drafts are only made in the web UI.
|
||||
status=JobStatus.PENDING,
|
||||
)
|
||||
return _job_response(job)
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
{# <meta name="description" content="{{ page.search_description }}" />#}
|
||||
{# {% endif %}#}
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" href="{% static 'favicon.ico' %}" sizes="any" />
|
||||
<link rel="icon" href="{% static 'favicon.svg' %}" type="image/svg+xml" />
|
||||
<link rel="apple-touch-icon" href="{% static 'apple-touch-icon.png' %}" />
|
||||
|
||||
{# Force all links in the live preview panel to be opened in a new tab #}
|
||||
{% if request.in_preview_panel %}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<script type="application/javascript">
|
||||
tinymce.init({
|
||||
selector: '{{ selector }}',
|
||||
license_key: 'gpl',
|
||||
menubar: '',
|
||||
toolbar: 'undo redo | bold italic | bullist numlist | link emoticons',
|
||||
plugins: [
|
||||
'link', 'emoticons', 'lists'
|
||||
],
|
||||
setup: function (editor) {
|
||||
editor.on('change', function () {
|
||||
tinymce.triggerSave();
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,11 @@
|
||||
{% for error in form.non_field_errors %}
|
||||
<div class="alert alert-danger">{{ error }}</div>
|
||||
{% endfor %}
|
||||
{% for field in form %}
|
||||
<div class="mb-3">
|
||||
<label for="{{ field.id_for_label }}" class="form-label">{{ field.label }}</label>
|
||||
{{ field }}
|
||||
{% if field.help_text %}<div class="form-text">{{ field.help_text }}</div>{% endif %}
|
||||
{% for error in field.errors %}<div class="invalid-feedback d-block">{{ error }}</div>{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
@@ -0,0 +1 @@
|
||||
<span class="badge {% if status == 'draft' %}text-bg-secondary{% elif status == 'pending' %}text-bg-info{% elif status == 'in_progress' %}text-bg-primary{% elif status == 'completed' %}text-bg-success{% elif status == 'failed' %}text-bg-danger{% else %}text-bg-light{% endif %}">{{ label }}</span>
|
||||
@@ -0,0 +1,12 @@
|
||||
<div class="card">
|
||||
<div class="card-header">Example profile definition</div>
|
||||
<div class="card-body">
|
||||
<pre class="mb-3 small"><code>{{ example_profile }}</code></pre>
|
||||
<ul class="small mb-0">
|
||||
<li><code>profiles</code> is required and needs at least one entry. Each entry produces one output rendition.</li>
|
||||
<li><code>resolution</code> is required for every entry, as <code>WIDTHxHEIGHT</code>.</li>
|
||||
<li><code>bitrate</code>, <code>codec</code>, <code>fps</code> and <code>name</code> are optional.</li>
|
||||
<li><code>encoder</code> is optional: <code>cpu</code>, <code>quicksync</code> or <code>nvidia</code>.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@@ -10,6 +10,42 @@
|
||||
|
||||
<h1>{{ content_asset.title }}</h1>
|
||||
|
||||
<section class="mb-4" aria-labelledby="transcode-jobs-heading">
|
||||
<div class="d-flex justify-content-between align-items-center mb-2">
|
||||
<h2 id="transcode-jobs-heading" class="h4 mb-0">Transcode jobs</h2>
|
||||
{% if content_asset.uploaded_asset %}
|
||||
<a href="{% url 'studio:transcode_job_create' studio.bucket_name content_asset.pk %}" class="btn btn-outline-primary btn-sm">New transcode job</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if transcode_jobs %}
|
||||
<table class="table table-sm align-middle">
|
||||
<tr>
|
||||
<th>Job</th>
|
||||
<th>Profile</th>
|
||||
<th>Status</th>
|
||||
<th>Requested</th>
|
||||
<th>Packaging</th>
|
||||
</tr>
|
||||
{% for job in transcode_jobs %}
|
||||
<tr>
|
||||
<td><a href="{% url 'studio:transcode_job' studio.bucket_name job.pk %}">Transcode job {{ job.pk }}</a></td>
|
||||
<td>{{ job.profile.name|default:"Custom definition" }}</td>
|
||||
<td>{% include "privatestudio/_job_status.html" with status=job.status label=job.get_status_display %}</td>
|
||||
<td>{{ job.requested_at }}</td>
|
||||
<td>
|
||||
{% for packaging_job in job.packaging_jobs.all %}
|
||||
<a href="{% url 'studio:packaging_job' studio.bucket_name packaging_job.pk %}">Packaging job {{ packaging_job.pk }}</a>
|
||||
{% include "privatestudio/_job_status.html" with status=packaging_job.status label=packaging_job.get_status_display %}{% if not forloop.last %}<br>{% endif %}
|
||||
{% empty %}—{% endfor %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% else %}
|
||||
<p class="text-body-secondary">No transcode jobs yet.</p>
|
||||
{% endif %}
|
||||
</section>
|
||||
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3">File</dt>
|
||||
<dd class="col-sm-9">{{ content_asset.uploaded_asset.s3_path }}</dd>
|
||||
@@ -30,7 +66,7 @@
|
||||
<dt class="col-sm-3">Title</dt>
|
||||
<dd class="col-sm-9">{{ content_asset.title }}</dd>
|
||||
<dt class="col-sm-3">Description</dt>
|
||||
<dd class="col-sm-9">{{ content_asset.description|linebreaksbr|default:"—" }}</dd>
|
||||
<dd class="col-sm-9">{{ content_asset.description|default:"—"|safe }}</dd>
|
||||
<dt class="col-sm-3">Release date</dt>
|
||||
<dd class="col-sm-9">{{ content_asset.release_date|default:"—" }}</dd>
|
||||
<dt class="col-sm-3">Series / Collection</dt>
|
||||
@@ -72,4 +108,6 @@
|
||||
{% endif %}
|
||||
</form>
|
||||
{% endwith %}
|
||||
{% include 'includes/_tinymce.html' with selector="textarea#id_description" %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<th>Position</th>
|
||||
<th>Release Date</th>
|
||||
<th>File</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% for content in content_assets %}
|
||||
<tr>
|
||||
@@ -21,10 +22,15 @@
|
||||
</td>
|
||||
<td>{{ content.release_date|default:"" }}</td>
|
||||
<td>{{ content.uploaded_asset.s3_path }}</td>
|
||||
<td class="text-end">
|
||||
{% if content.uploaded_asset %}
|
||||
<a href="{% url 'studio:transcode_job_create' studio.bucket_name content.pk %}" class="btn btn-outline-primary btn-sm">Transcode</a>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td colspan="6">No content yet. Use "Create content" on an uploaded file.</td>
|
||||
<td colspan="7">No content yet. Use "Create content" on an uploaded file.</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<div class="d-flex justify-content-end mb-2">
|
||||
<a href="{% url 'studio:transcode_profile_create' studio.bucket_name %}" class="btn btn-primary btn-sm">New profile</a>
|
||||
</div>
|
||||
<table class="table table-striped table-sm align-middle">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Created</th>
|
||||
<th>Created by</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% for profile in profiles %}
|
||||
<tr>
|
||||
<td><a href="{% url 'studio:transcode_profile' studio.bucket_name profile.pk %}">{{ profile.name }}</a></td>
|
||||
<td>{{ profile.created_at }}</td>
|
||||
<td>{{ profile.created_by|default:"" }}</td>
|
||||
<td class="text-end">
|
||||
<a href="{% url 'studio:transcode_profile' studio.bucket_name profile.pk %}" class="btn btn-outline-primary btn-sm">Edit</a>
|
||||
<a href="{% url 'studio:transcode_profile_delete' studio.bucket_name profile.pk %}" class="btn btn-outline-danger btn-sm">Delete</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% empty %}
|
||||
<tr>
|
||||
<td colspan="4">No transcode profiles yet.</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
@@ -1,4 +1,4 @@
|
||||
<nav class="studio-navbar navbar navbar-expand-lg navbar-dark bg-dark navbar-fixed-top justify-content-between">
|
||||
<nav class="studio-navbar navbar navbar-expand-lg navbar-light bg-light navbar-fixed-top justify-content-between">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="/">Private Studio</a>
|
||||
<button class="navbar-toggler" data-bs-toggle="collapse" data-bs-target="#navbarContainer" aria-expanded="false" aria-controls="navbarContainer" aria-label="Toggle Navigation">
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{% extends "privatestudio/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% with job=packaging_job.transcode_job %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:detail' studio.bucket_name %}?tab=content">{{ studio.name }}</a></li>
|
||||
{% if job.content_asset %}
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:content_asset' studio.bucket_name job.content_asset.pk %}">{{ job.content_asset.title }}</a></li>
|
||||
{% endif %}
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:transcode_job' studio.bucket_name job.pk %}">Transcode job {{ job.pk }}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Packaging job {{ packaging_job.pk }}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<h1>Packaging job {{ packaging_job.pk }} {% include "privatestudio/_job_status.html" with status=packaging_job.status label=packaging_job.get_status_display %}</h1>
|
||||
|
||||
{% if packaging_job.status == 'pending' and job.status != 'completed' %}
|
||||
<div class="alert alert-secondary">Packaging starts after transcode job {{ job.pk }} completes.</div>
|
||||
{% endif %}
|
||||
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3">Transcode job</dt>
|
||||
<dd class="col-sm-9">
|
||||
<a href="{% url 'studio:transcode_job' studio.bucket_name job.pk %}">Transcode job {{ job.pk }}</a>
|
||||
{% include "privatestudio/_job_status.html" with status=job.status label=job.get_status_display %}
|
||||
</dd>
|
||||
<dt class="col-sm-3">Content</dt>
|
||||
<dd class="col-sm-9">
|
||||
{% if job.content_asset %}<a href="{% url 'studio:content_asset' studio.bucket_name job.content_asset.pk %}">{{ job.content_asset.title }}</a>{% else %}—{% endif %}
|
||||
</dd>
|
||||
<dt class="col-sm-3">Requested</dt>
|
||||
<dd class="col-sm-9">{{ packaging_job.requested_at }}{% if packaging_job.requested_by %} by {{ packaging_job.requested_by }}{% endif %}</dd>
|
||||
<dt class="col-sm-3">Completed</dt>
|
||||
<dd class="col-sm-9">{{ packaging_job.completed_at|default:"—" }}</dd>
|
||||
</dl>
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
@@ -5,29 +5,37 @@
|
||||
<p>Bucket Name: {{ studio.bucket_name }}</p>
|
||||
<p>Group: {{ studio.group.name }}</p>
|
||||
|
||||
{% with content_tab=request.GET.tab %}
|
||||
{% with active=active_tab %}
|
||||
<ul class="nav nav-tabs mb-3" role="tablist">
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link{% if content_tab != 'content' %} active{% endif %}" id="files-tab" data-bs-toggle="tab" data-bs-target="#files-pane" type="button" role="tab" aria-controls="files-pane" aria-selected="{% if content_tab != 'content' %}true{% else %}false{% endif %}">Uploaded files</button>
|
||||
<button class="nav-link{% if active == 'files' %} active{% endif %}" id="files-tab" data-bs-toggle="tab" data-bs-target="#files-pane" type="button" role="tab" aria-controls="files-pane" aria-selected="{% if active == 'files' %}true{% else %}false{% endif %}">Uploaded files</button>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link{% if content_tab == 'content' %} active{% endif %}" id="content-tab" data-bs-toggle="tab" data-bs-target="#content-pane" type="button" role="tab" aria-controls="content-pane" aria-selected="{% if content_tab == 'content' %}true{% else %}false{% endif %}">Content</button>
|
||||
<button class="nav-link{% if active == 'content' %} active{% endif %}" id="content-tab" data-bs-toggle="tab" data-bs-target="#content-pane" type="button" role="tab" aria-controls="content-pane" aria-selected="{% if active == 'content' %}true{% else %}false{% endif %}">Content</button>
|
||||
</li>
|
||||
<li class="nav-item" role="presentation">
|
||||
<button class="nav-link{% if active == 'profiles' %} active{% endif %}" id="profiles-tab" data-bs-toggle="tab" data-bs-target="#profiles-pane" type="button" role="tab" aria-controls="profiles-pane" aria-selected="{% if active == 'profiles' %}true{% else %}false{% endif %}">Profiles</button>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane fade{% if content_tab != 'content' %} show active{% endif %}" id="files-pane" role="tabpanel" aria-labelledby="files-tab" tabindex="0">
|
||||
<div class="tab-pane fade{% if active == 'files' %} show active{% endif %}" id="files-pane" role="tabpanel" aria-labelledby="files-tab" tabindex="0">
|
||||
<div id="uploaded_assets" hx-get="{% url 'studio:uploaded_assets' studio.bucket_name %}" hx-trigger="load, assets-changed from:body" hx-target="#uploaded_assets" hx-swap="innerHTML">
|
||||
<p>Loading uploaded assets...</p>
|
||||
</div>
|
||||
|
||||
{% include "privatestudio/_file_uploader.html" %}
|
||||
</div>
|
||||
<div class="tab-pane fade{% if content_tab == 'content' %} show active{% endif %}" id="content-pane" role="tabpanel" aria-labelledby="content-tab" tabindex="0">
|
||||
<div class="tab-pane fade{% if active == 'content' %} show active{% endif %}" id="content-pane" role="tabpanel" aria-labelledby="content-tab" tabindex="0">
|
||||
<div id="content_assets" hx-get="{% url 'studio:content_assets' studio.bucket_name %}" hx-trigger="load, assets-changed from:body" hx-target="#content_assets" hx-swap="innerHTML">
|
||||
<p>Loading content...</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-pane fade{% if active == 'profiles' %} show active{% endif %}" id="profiles-pane" role="tabpanel" aria-labelledby="profiles-tab" tabindex="0">
|
||||
<div id="transcode_profiles" hx-get="{% url 'studio:transcode_profiles' studio.bucket_name %}" hx-trigger="load" hx-target="#transcode_profiles" hx-swap="innerHTML">
|
||||
<p>Loading profiles...</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endwith %}
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
{% extends "privatestudio/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:detail' studio.bucket_name %}?tab=content">{{ studio.name }}</a></li>
|
||||
{% if job.content_asset %}
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:content_asset' studio.bucket_name job.content_asset.pk %}">{{ job.content_asset.title }}</a></li>
|
||||
{% endif %}
|
||||
<li class="breadcrumb-item active" aria-current="page">Transcode job {{ job.pk }}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<h1>Transcode job {{ job.pk }} {% include "privatestudio/_job_status.html" with status=job.status label=job.get_status_display %}</h1>
|
||||
|
||||
{% if job.is_editable %}
|
||||
<div class="d-flex gap-2 mb-3">
|
||||
<a href="{% url 'studio:transcode_job_update' studio.bucket_name job.pk %}" class="btn btn-secondary">Edit</a>
|
||||
<form method="post" action="{% url 'studio:transcode_job_submit' studio.bucket_name job.pk %}" class="m-0">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</form>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<dl class="row">
|
||||
<dt class="col-sm-3">Content</dt>
|
||||
<dd class="col-sm-9">
|
||||
{% if job.content_asset %}<a href="{% url 'studio:content_asset' studio.bucket_name job.content_asset.pk %}">{{ job.content_asset.title }}</a>{% else %}—{% endif %}
|
||||
</dd>
|
||||
<dt class="col-sm-3">File</dt>
|
||||
<dd class="col-sm-9">{{ job.asset.s3_path }}</dd>
|
||||
<dt class="col-sm-3">Profile</dt>
|
||||
<dd class="col-sm-9">
|
||||
{% if job.profile %}<a href="{% url 'studio:transcode_profile' studio.bucket_name job.profile.pk %}">{{ job.profile.name }}</a>{% else %}Custom definition{% endif %}
|
||||
</dd>
|
||||
<dt class="col-sm-3">Requested</dt>
|
||||
<dd class="col-sm-9">{{ job.requested_at }}{% if job.requested_by %} by {{ job.requested_by }}{% endif %}</dd>
|
||||
<dt class="col-sm-3">Completed</dt>
|
||||
<dd class="col-sm-9">{{ job.completed_at|default:"—" }}</dd>
|
||||
</dl>
|
||||
|
||||
<h2 class="h4">Packaging jobs</h2>
|
||||
<ul>
|
||||
{% for packaging_job in job.packaging_jobs.all %}
|
||||
<li>
|
||||
<a href="{% url 'studio:packaging_job' studio.bucket_name packaging_job.pk %}">Packaging job {{ packaging_job.pk }}</a>
|
||||
{% include "privatestudio/_job_status.html" with status=packaging_job.status label=packaging_job.get_status_display %}
|
||||
</li>
|
||||
{% empty %}
|
||||
<li>None</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% with outputs=job.transcoded_assets.all %}
|
||||
{% if outputs %}
|
||||
<h2 class="h4">Outputs</h2>
|
||||
<table class="table table-striped table-sm">
|
||||
<tr><th>File</th><th>Format</th><th>Created</th></tr>
|
||||
{% for output in outputs %}
|
||||
<tr><td>{{ output.s3_path }}</td><td>{{ output.format }}</td><td>{{ output.created_at }}</td></tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
|
||||
<h2 class="h4">Profile definition</h2>
|
||||
<pre class="border rounded p-3 small"><code>{{ job.profile_definition }}</code></pre>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,69 @@
|
||||
{% extends "privatestudio/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:detail' studio.bucket_name %}?tab=content">{{ studio.name }}</a></li>
|
||||
{% if content_asset %}
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:content_asset' studio.bucket_name content_asset.pk %}">{{ content_asset.title }}</a></li>
|
||||
{% endif %}
|
||||
{% if job %}
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:transcode_job' studio.bucket_name job.pk %}">Transcode job {{ job.pk }}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Edit</li>
|
||||
{% else %}
|
||||
<li class="breadcrumb-item active" aria-current="page">New transcode job</li>
|
||||
{% endif %}
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<h1>{% if job %}Edit transcode job {{ job.pk }}{% else %}New transcode job{% endif %}</h1>
|
||||
{% if content_asset %}<p class="text-body-secondary">{{ content_asset.title }} · {{ content_asset.uploaded_asset.s3_path }}</p>{% endif %}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-7">
|
||||
<form method="post" novalidate>
|
||||
{% csrf_token %}
|
||||
{% include "privatestudio/_form_fields.html" %}
|
||||
{% if not form.fields.profile.queryset.exists %}
|
||||
<div class="alert alert-secondary">
|
||||
This studio has no saved profiles. You can enter a definition here, or
|
||||
<a href="{% url 'studio:transcode_profile_create' studio.bucket_name %}">create a profile</a> first.
|
||||
</div>
|
||||
{% endif %}
|
||||
<button type="submit" name="save" class="btn btn-secondary">Save draft</button>
|
||||
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
|
||||
{% if job %}
|
||||
<a href="{% url 'studio:transcode_job' studio.bucket_name job.pk %}" class="btn btn-link">Cancel</a>
|
||||
{% elif content_asset %}
|
||||
<a href="{% url 'studio:content_asset' studio.bucket_name content_asset.pk %}" class="btn btn-link">Cancel</a>
|
||||
{% endif %}
|
||||
<div class="form-text">A submitted job is queued for transcoding and can no longer be edited.</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-lg-5 mt-4 mt-lg-0">
|
||||
{% include "privatestudio/_profile_example.html" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{ profile_definitions|json_script:"profile-definitions" }}
|
||||
<script>
|
||||
(function () {
|
||||
const definitions = JSON.parse(document.getElementById("profile-definitions").textContent);
|
||||
const select = document.getElementById("{{ form.profile.id_for_label }}");
|
||||
const editor = document.getElementById("{{ form.profile_definition.id_for_label }}");
|
||||
if (!select || !editor) return;
|
||||
// Replace the text only while it is empty or still matches a saved profile, so edits aren't lost.
|
||||
const untouched = () => editor.value.trim() === "" ||
|
||||
Object.values(definitions).some((text) => text.trim() === editor.value.trim());
|
||||
select.addEventListener("change", () => {
|
||||
const text = definitions[select.value];
|
||||
if (text !== undefined && (untouched() || confirm("Replace your edits with the selected profile?"))) {
|
||||
editor.value = text;
|
||||
}
|
||||
});
|
||||
if (editor.value.trim() === "" && definitions[select.value] !== undefined) {
|
||||
editor.value = definitions[select.value];
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,19 @@
|
||||
{% extends "privatestudio/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:detail' studio.bucket_name %}?tab=profiles">{{ studio.name }}</a></li>
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:transcode_profile' studio.bucket_name profile.pk %}">{{ profile.name }}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Delete</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<h1>Delete profile {{ profile.name }}?</h1>
|
||||
<p>Transcode jobs that used this profile keep their own copy of its definition.</p>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
<button type="submit" class="btn btn-danger">Delete</button>
|
||||
<a href="{% url 'studio:detail' studio.bucket_name %}?tab=profiles" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,49 @@
|
||||
{% extends "privatestudio/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<nav aria-label="breadcrumb">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{% url 'studio:detail' studio.bucket_name %}?tab=profiles">{{ studio.name }}</a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">{% if profile %}{{ profile.name }}{% else %}New profile{% endif %}</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<h1>{% if profile %}Edit profile {{ profile.name }}{% else %}New transcode profile{% endif %}</h1>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-7">
|
||||
<form method="post" novalidate>
|
||||
{% csrf_token %}
|
||||
{% include "privatestudio/_form_fields.html" %}
|
||||
<button type="submit" class="btn btn-primary">Save</button>
|
||||
<a href="{% url 'studio:detail' studio.bucket_name %}?tab=profiles" class="btn btn-secondary">Cancel</a>
|
||||
{% if default_profile %}
|
||||
<button type="button" id="fill-default-profile" class="btn btn-outline-secondary">Fill with default profile</button>
|
||||
{% endif %}
|
||||
{% if profile %}
|
||||
<a href="{% url 'studio:transcode_profile_delete' studio.bucket_name profile.pk %}" class="btn btn-outline-danger float-end">Delete</a>
|
||||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
<div class="col-lg-5 mt-4 mt-lg-0">
|
||||
{% include "privatestudio/_profile_example.html" %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if default_profile %}
|
||||
{{ default_profile|json_script:"default-profile" }}
|
||||
<script>
|
||||
(function () {
|
||||
const text = JSON.parse(document.getElementById("default-profile").textContent);
|
||||
const editor = document.getElementById("{{ form.profile_definition.id_for_label }}");
|
||||
document.getElementById("fill-default-profile").addEventListener("click", () => {
|
||||
const current = editor.value.trim();
|
||||
if (current === "" || current === text.trim() || confirm("Replace the current definition with the default profile?")) {
|
||||
editor.value = text;
|
||||
editor.focus();
|
||||
}
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,64 @@
|
||||
import re
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.urls import reverse
|
||||
|
||||
from privatestudio.studio.auth import hash_api_key, user_for_api_key
|
||||
from privatestudio.studio.models import APIKey
|
||||
from privatestudio.studio.tests.base import StudioTestCase
|
||||
|
||||
ADD_URL = reverse("admin:studio_apikey_add")
|
||||
LIST_URL = reverse("admin:studio_apikey_changelist")
|
||||
TOKEN_RE = re.compile(r"<code>([^<]+)</code>")
|
||||
|
||||
|
||||
class APIKeyAdminTests(StudioTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.client.force_login(User.objects.create_superuser("admin"))
|
||||
self.existing = APIKey.objects.get()
|
||||
self.change_url = reverse("admin:studio_apikey_change", args=[self.existing.pk])
|
||||
|
||||
def form_data(self, **extra):
|
||||
return {
|
||||
"user": self.user.pk,
|
||||
"created_at_0": "2026-01-01",
|
||||
"created_at_1": "12:00:00",
|
||||
"is_active": "on",
|
||||
**extra,
|
||||
}
|
||||
|
||||
def add_key(self):
|
||||
"""Submit the add form and return the token shown to the admin."""
|
||||
response = self.client.post(ADD_URL, self.form_data(), follow=True)
|
||||
self.assertRedirects(response, LIST_URL)
|
||||
return TOKEN_RE.search(response.content.decode()).group(1)
|
||||
|
||||
def test_add_shows_working_token_once(self):
|
||||
token = self.add_key()
|
||||
self.assertEqual(APIKey.objects.get(key_hash=hash_api_key(token)).user, self.user)
|
||||
self.assertEqual(user_for_api_key(token), self.user)
|
||||
self.assertNotContains(self.client.get(LIST_URL), token)
|
||||
|
||||
def test_each_key_is_unique(self):
|
||||
self.assertNotEqual(self.add_key(), self.add_key())
|
||||
self.assertEqual(APIKey.objects.count(), 3)
|
||||
|
||||
def test_submitted_key_hash_is_ignored(self):
|
||||
self.client.post(ADD_URL, self.form_data(key_hash=hash_api_key("chosen")))
|
||||
self.assertIsNone(user_for_api_key("chosen"))
|
||||
|
||||
def test_change_keeps_hash_and_shows_no_token(self):
|
||||
data = self.form_data()
|
||||
del data["is_active"]
|
||||
response = self.client.post(self.change_url, data, follow=True)
|
||||
self.assertRedirects(response, LIST_URL)
|
||||
self.assertIsNone(TOKEN_RE.search(response.content.decode()))
|
||||
original_hash = self.existing.key_hash
|
||||
self.existing.refresh_from_db()
|
||||
self.assertEqual(self.existing.key_hash, original_hash)
|
||||
self.assertFalse(self.existing.is_active)
|
||||
|
||||
def test_key_hash_only_on_change_form(self):
|
||||
self.assertNotContains(self.client.get(ADD_URL), "field-key_hash")
|
||||
self.assertContains(self.client.get(self.change_url), self.existing.key_hash)
|
||||
@@ -141,7 +141,7 @@ class TranscodeTests(StudioTestCase):
|
||||
self.assertEqual([j["id"] for j in listing], [job_id])
|
||||
|
||||
def test_transcode_with_inline_profile_by_filename(self):
|
||||
response = self.request_transcode("asset: video.mp4\nprofile:\n profiles:\n sd:\n bitrate: 800k\n")
|
||||
response = self.request_transcode("asset: video.mp4\nprofile:\n profiles:\n sd:\n resolution: 640x360\n bitrate: 800k\n")
|
||||
self.assertEqual(response.status_code, 200, response.content)
|
||||
self.assertIsNone(response.json()["profile_id"])
|
||||
job = TranscodeJob.objects.get()
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.urls import reverse
|
||||
|
||||
from privatestudio.studio.models import (
|
||||
ContentAsset, JobStatus, PackagingJob, TranscodeJob, TranscodeProfile,
|
||||
)
|
||||
from privatestudio.studio.profiles import EXAMPLE_PROFILE_YAML, load_default_profile, validate_profile_definition
|
||||
from privatestudio.studio.tests.test_content import ContentTestCase
|
||||
|
||||
PROFILE_YAML = "profiles:\n hd:\n resolution: 1280x720\n bitrate: 2500k\n"
|
||||
OTHER_YAML = "profiles:\n sd:\n resolution: 640x360\n"
|
||||
|
||||
|
||||
class ValidateProfileDefinitionTests(ContentTestCase):
|
||||
def assert_invalid(self, text, fragment):
|
||||
with self.assertRaises(ValidationError) as ctx:
|
||||
validate_profile_definition(text)
|
||||
self.assertIn(fragment, " ".join(ctx.exception.messages))
|
||||
|
||||
def test_valid(self):
|
||||
self.assertIn("1080p", validate_profile_definition(EXAMPLE_PROFILE_YAML)["profiles"])
|
||||
validate_profile_definition(PROFILE_YAML)
|
||||
|
||||
def test_invalid(self):
|
||||
self.assert_invalid("profiles: [oops", "Invalid YAML (line")
|
||||
self.assert_invalid("- a\n- b\n", "YAML mapping")
|
||||
self.assert_invalid("", "YAML mapping")
|
||||
self.assert_invalid("encoder: cpu\n", "'profiles' must be a mapping")
|
||||
self.assert_invalid("profiles: {}\n", "'profiles' must be a mapping")
|
||||
self.assert_invalid("profiles:\n hd: 720\n", "Profile 'hd' must be a mapping")
|
||||
self.assert_invalid("profiles:\n hd:\n bitrate: 1000k\n", "'resolution' is required")
|
||||
self.assert_invalid("profiles:\n hd:\n resolution: big\n", "'resolution' is required")
|
||||
self.assert_invalid("profiles:\n hd:\n resolution: 10x10\n bitrate: fast\n", "'bitrate'")
|
||||
self.assert_invalid("profiles:\n hd:\n resolution: 10x10\n fps: -1\n", "'fps'")
|
||||
self.assert_invalid("encoder: gpu\nprofiles:\n hd:\n resolution: 10x10\n", "'encoder'")
|
||||
|
||||
|
||||
class TranscodeProfileViewTests(ContentTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.profile = TranscodeProfile.objects.create(studio=self.studio, name="hd", profile_definition=PROFILE_YAML)
|
||||
self.other_profile = TranscodeProfile.objects.create(
|
||||
studio=self.other_studio, name="secret", profile_definition=PROFILE_YAML,
|
||||
)
|
||||
|
||||
def test_list_only_studio_profiles(self):
|
||||
response = self.client.get(reverse("studio:transcode_profiles", args=["demo"]))
|
||||
self.assertContains(response, "hd")
|
||||
self.assertNotContains(response, "secret")
|
||||
|
||||
def test_create(self):
|
||||
url = reverse("studio:transcode_profile_create", args=["demo"])
|
||||
response = self.client.get(url)
|
||||
self.assertContains(response, "Example profile definition")
|
||||
response = self.client.post(url, {"name": "sd", "profile_definition": OTHER_YAML})
|
||||
self.assertRedirects(response, reverse("studio:detail", args=["demo"]) + "?tab=profiles",
|
||||
fetch_redirect_response=False)
|
||||
profile = TranscodeProfile.objects.get(studio=self.studio, name="sd")
|
||||
self.assertEqual(profile.created_by, self.user)
|
||||
|
||||
def test_create_default_profile_button(self):
|
||||
url = reverse("studio:transcode_profile_create", args=["demo"])
|
||||
response = self.client.get(url)
|
||||
self.assertContains(response, 'id="fill-default-profile"')
|
||||
self.assertContains(response, 'id="default-profile"')
|
||||
validate_profile_definition(load_default_profile()) # The shipped default must be a valid profile.
|
||||
# Not offered when editing, or when the file isn't available.
|
||||
edit = self.client.get(reverse("studio:transcode_profile", args=["demo", self.profile.pk]))
|
||||
self.assertNotContains(edit, 'id="fill-default-profile"')
|
||||
with mock.patch("privatestudio.studio.profiles.DEFAULT_PROFILE_PATH", Path(self.storage_dir) / "missing.yaml"):
|
||||
self.assertNotContains(self.client.get(url), 'id="fill-default-profile"')
|
||||
|
||||
def test_create_invalid_yaml(self):
|
||||
url = reverse("studio:transcode_profile_create", args=["demo"])
|
||||
response = self.client.post(url, {"name": "bad", "profile_definition": "profiles: {}"})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, "'profiles' must be a mapping")
|
||||
self.assertContains(response, "Example profile definition")
|
||||
self.assertFalse(TranscodeProfile.objects.filter(name="bad").exists())
|
||||
|
||||
def test_duplicate_name(self):
|
||||
url = reverse("studio:transcode_profile_create", args=["demo"])
|
||||
response = self.client.post(url, {"name": "hd", "profile_definition": PROFILE_YAML})
|
||||
self.assertContains(response, "already exists")
|
||||
# The same name in another studio is fine, and an edit may keep its own name.
|
||||
url = reverse("studio:transcode_profile_create", args=["demo"])
|
||||
self.assertEqual(self.client.post(url, {"name": "secret", "profile_definition": PROFILE_YAML}).status_code, 302)
|
||||
url = reverse("studio:transcode_profile", args=["demo", self.profile.pk])
|
||||
self.assertEqual(self.client.post(url, {"name": "hd", "profile_definition": OTHER_YAML}).status_code, 302)
|
||||
|
||||
def test_update(self):
|
||||
url = reverse("studio:transcode_profile", args=["demo", self.profile.pk])
|
||||
self.assertContains(self.client.get(url), "1280x720")
|
||||
self.client.post(url, {"name": "hd2", "profile_definition": OTHER_YAML})
|
||||
self.profile.refresh_from_db()
|
||||
self.assertEqual((self.profile.name, self.profile.profile_definition), ("hd2", OTHER_YAML.strip()))
|
||||
|
||||
def test_delete(self):
|
||||
url = reverse("studio:transcode_profile_delete", args=["demo", self.profile.pk])
|
||||
self.assertContains(self.client.get(url), "Delete profile hd?")
|
||||
self.client.post(url)
|
||||
self.assertFalse(TranscodeProfile.objects.filter(pk=self.profile.pk).exists())
|
||||
|
||||
def test_other_studio_profile_inaccessible(self):
|
||||
for name in ("transcode_profile", "transcode_profile_delete"):
|
||||
response = self.client.get(reverse(f"studio:{name}", args=["demo", self.other_profile.pk]))
|
||||
self.assertEqual(response.status_code, 404)
|
||||
|
||||
|
||||
class TranscodeJobTestCase(ContentTestCase):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
self.profile = TranscodeProfile.objects.create(studio=self.studio, name="hd", profile_definition=PROFILE_YAML)
|
||||
self.content_asset = self.content(title="Pilot")
|
||||
|
||||
def make_job(self, **fields):
|
||||
return TranscodeJob.objects.create(
|
||||
studio=self.studio, asset=self.asset, content_asset=self.content_asset, profile=self.profile,
|
||||
profile_definition=PROFILE_YAML, **fields,
|
||||
)
|
||||
|
||||
|
||||
class TranscodeJobCreateTests(TranscodeJobTestCase):
|
||||
def url(self, content=None):
|
||||
return reverse("studio:transcode_job_create", args=["demo", (content or self.content_asset).pk])
|
||||
|
||||
def test_get(self):
|
||||
response = self.client.get(self.url())
|
||||
self.assertContains(response, "Save draft")
|
||||
self.assertContains(response, 'id="profile-definitions"')
|
||||
|
||||
def test_save_draft_creates_packaging_job(self):
|
||||
response = self.client.post(self.url(), {
|
||||
"profile": self.profile.pk, "profile_definition": OTHER_YAML, "save": "",
|
||||
})
|
||||
job = TranscodeJob.objects.get()
|
||||
self.assertRedirects(response, reverse("studio:transcode_job", args=["demo", job.pk]),
|
||||
fetch_redirect_response=False)
|
||||
self.assertEqual(job.status, JobStatus.DRAFT)
|
||||
self.assertEqual((job.content_asset, job.asset, job.profile), (self.content_asset, self.asset, self.profile))
|
||||
self.assertEqual(job.profile_definition, OTHER_YAML.strip())
|
||||
self.assertEqual(job.requested_by, self.user)
|
||||
packaging = PackagingJob.objects.get()
|
||||
self.assertEqual((packaging.transcode_job, packaging.status), (job, JobStatus.PENDING))
|
||||
|
||||
def test_submit(self):
|
||||
self.client.post(self.url(), {"profile": self.profile.pk, "profile_definition": "", "submit": ""})
|
||||
job = TranscodeJob.objects.get()
|
||||
self.assertEqual(job.status, JobStatus.PENDING)
|
||||
self.assertEqual(job.profile_definition, PROFILE_YAML) # Copied from the profile when left empty.
|
||||
|
||||
def test_requires_profile_or_definition(self):
|
||||
response = self.client.post(self.url(), {"profile": "", "profile_definition": "", "save": ""})
|
||||
self.assertContains(response, "Choose a profile or enter a profile definition.")
|
||||
response = self.client.post(self.url(), {"profile": "", "profile_definition": "profiles: {}", "save": ""})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertFalse(TranscodeJob.objects.exists())
|
||||
self.assertFalse(PackagingJob.objects.exists())
|
||||
|
||||
def test_definition_without_profile(self):
|
||||
self.client.post(self.url(), {"profile": "", "profile_definition": OTHER_YAML, "save": ""})
|
||||
self.assertIsNone(TranscodeJob.objects.get().profile)
|
||||
|
||||
def test_other_studio_profile_rejected(self):
|
||||
other = TranscodeProfile.objects.create(studio=self.other_studio, name="x", profile_definition=PROFILE_YAML)
|
||||
response = self.client.post(self.url(), {"profile": other.pk, "profile_definition": "", "save": ""})
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertFalse(TranscodeJob.objects.exists())
|
||||
|
||||
def test_content_without_file(self):
|
||||
content = ContentAsset.objects.create(studio=self.studio, title="No file")
|
||||
response = self.client.get(self.url(content))
|
||||
self.assertRedirects(response, reverse("studio:content_asset", args=["demo", content.pk]),
|
||||
fetch_redirect_response=False)
|
||||
|
||||
def test_other_studio_content(self):
|
||||
content = self.content(asset=self.other_asset)
|
||||
self.assertEqual(self.client.get(self.url(content)).status_code, 404)
|
||||
|
||||
|
||||
class TranscodeJobUpdateTests(TranscodeJobTestCase):
|
||||
def test_edit_draft(self):
|
||||
job = self.make_job()
|
||||
url = reverse("studio:transcode_job_update", args=["demo", job.pk])
|
||||
self.assertContains(self.client.get(url), "Edit transcode job")
|
||||
self.client.post(url, {"profile": self.profile.pk, "profile_definition": OTHER_YAML, "save": ""})
|
||||
job.refresh_from_db()
|
||||
self.assertEqual((job.profile_definition, job.status), (OTHER_YAML.strip(), JobStatus.DRAFT))
|
||||
|
||||
def test_edit_and_submit(self):
|
||||
job = self.make_job()
|
||||
url = reverse("studio:transcode_job_update", args=["demo", job.pk])
|
||||
self.client.post(url, {"profile": self.profile.pk, "profile_definition": OTHER_YAML, "submit": ""})
|
||||
job.refresh_from_db()
|
||||
self.assertEqual((job.profile_definition, job.status), (OTHER_YAML.strip(), JobStatus.PENDING))
|
||||
|
||||
def test_non_draft_not_editable(self):
|
||||
job = self.make_job(status=JobStatus.PENDING)
|
||||
url = reverse("studio:transcode_job_update", args=["demo", job.pk])
|
||||
detail = reverse("studio:transcode_job", args=["demo", job.pk])
|
||||
self.assertRedirects(self.client.get(url), detail, fetch_redirect_response=False)
|
||||
response = self.client.post(url, {"profile": self.profile.pk, "profile_definition": OTHER_YAML})
|
||||
self.assertRedirects(response, detail, fetch_redirect_response=False)
|
||||
job.refresh_from_db()
|
||||
self.assertEqual(job.profile_definition, PROFILE_YAML)
|
||||
|
||||
def test_model_clean_blocks_non_draft_edits(self):
|
||||
job = self.make_job()
|
||||
job.status = JobStatus.PENDING
|
||||
job.full_clean() # The draft -> pending change itself is allowed.
|
||||
job.save()
|
||||
job.profile_definition = OTHER_YAML
|
||||
with self.assertRaisesMessage(ValidationError, "Only draft jobs can be edited."):
|
||||
job.full_clean()
|
||||
|
||||
def test_other_studio_job(self):
|
||||
job = TranscodeJob.objects.create(studio=self.other_studio, asset=self.other_asset)
|
||||
for name in ("transcode_job", "transcode_job_update"):
|
||||
self.assertEqual(self.client.get(reverse(f"studio:{name}", args=["demo", job.pk])).status_code, 404)
|
||||
|
||||
|
||||
class TranscodeJobSubmitAndDetailTests(TranscodeJobTestCase):
|
||||
def test_submit(self):
|
||||
job = self.make_job()
|
||||
url = reverse("studio:transcode_job_submit", args=["demo", job.pk])
|
||||
self.assertEqual(self.client.get(url).status_code, 405)
|
||||
self.client.post(url)
|
||||
job.refresh_from_db()
|
||||
self.assertEqual(job.status, JobStatus.PENDING)
|
||||
job.status = JobStatus.IN_PROGRESS
|
||||
job.save()
|
||||
self.client.post(url) # A second submit changes nothing.
|
||||
job.refresh_from_db()
|
||||
self.assertEqual(job.status, JobStatus.IN_PROGRESS)
|
||||
|
||||
def test_detail_buttons_only_for_drafts(self):
|
||||
job = self.make_job()
|
||||
packaging = PackagingJob.objects.create(studio=self.studio, transcode_job=job)
|
||||
url = reverse("studio:transcode_job", args=["demo", job.pk])
|
||||
response = self.client.get(url)
|
||||
self.assertContains(response, reverse("studio:transcode_job_submit", args=["demo", job.pk]))
|
||||
self.assertContains(response, reverse("studio:packaging_job", args=["demo", packaging.pk]))
|
||||
job.submit()
|
||||
self.assertNotContains(self.client.get(url), reverse("studio:transcode_job_submit", args=["demo", job.pk]))
|
||||
|
||||
def test_packaging_detail(self):
|
||||
job = self.make_job()
|
||||
packaging = PackagingJob.objects.create(studio=self.studio, transcode_job=job)
|
||||
response = self.client.get(reverse("studio:packaging_job", args=["demo", packaging.pk]))
|
||||
self.assertContains(response, "Packaging starts after transcode job")
|
||||
other_job = TranscodeJob.objects.create(studio=self.other_studio, asset=self.other_asset)
|
||||
other = PackagingJob.objects.create(studio=self.other_studio, transcode_job=other_job)
|
||||
self.assertEqual(self.client.get(reverse("studio:packaging_job", args=["demo", other.pk])).status_code, 404)
|
||||
|
||||
|
||||
class ContentPagesTests(TranscodeJobTestCase):
|
||||
def test_content_asset_page_lists_jobs(self):
|
||||
job = self.make_job()
|
||||
packaging = PackagingJob.objects.create(studio=self.studio, transcode_job=job)
|
||||
response = self.client.get(reverse("studio:content_asset", args=["demo", self.content_asset.pk]))
|
||||
content = response.content.decode()
|
||||
jobs_at = content.index("Transcode jobs")
|
||||
self.assertLess(jobs_at, content.index('id="content-form"'))
|
||||
self.assertContains(response, reverse("studio:transcode_job", args=["demo", job.pk]))
|
||||
self.assertContains(response, reverse("studio:packaging_job", args=["demo", packaging.pk]))
|
||||
self.assertContains(response, reverse("studio:transcode_job_create", args=["demo", self.content_asset.pk]))
|
||||
|
||||
def test_content_list_has_transcode_button(self):
|
||||
ContentAsset.objects.create(studio=self.studio, title="No file")
|
||||
response = self.client.get(reverse("studio:content_assets", args=["demo"]))
|
||||
self.assertContains(response, reverse("studio:transcode_job_create", args=["demo", self.content_asset.pk]),
|
||||
count=1)
|
||||
|
||||
def test_profiles_tab(self):
|
||||
url = reverse("studio:detail", args=["demo"])
|
||||
self.assertContains(self.client.get(url + "?tab=profiles"), 'class="nav-link active" id="profiles-tab"')
|
||||
self.assertContains(self.client.get(url + "?tab=bogus"), 'class="nav-link active" id="files-tab"')
|
||||
@@ -14,6 +14,21 @@ studio_patterns = [
|
||||
path("<slug:bucket_name>/content/create/<int:asset_id>/", views.ContentAssetCreateView.as_view(),
|
||||
name="content_asset_create"),
|
||||
path("<slug:bucket_name>/content/<int:pk>/", views.ContentAssetUpdateView.as_view(), name="content_asset"),
|
||||
path("<slug:bucket_name>/content/<int:pk>/transcode/new/", views.TranscodeJobCreateView.as_view(),
|
||||
name="transcode_job_create"),
|
||||
path("<slug:bucket_name>/hx/profiles/", views.TranscodeProfilesView.as_view(), name="transcode_profiles"),
|
||||
path("<slug:bucket_name>/profiles/new/", views.TranscodeProfileCreateView.as_view(),
|
||||
name="transcode_profile_create"),
|
||||
path("<slug:bucket_name>/profiles/<int:pk>/", views.TranscodeProfileUpdateView.as_view(),
|
||||
name="transcode_profile"),
|
||||
path("<slug:bucket_name>/profiles/<int:pk>/delete/", views.TranscodeProfileDeleteView.as_view(),
|
||||
name="transcode_profile_delete"),
|
||||
path("<slug:bucket_name>/transcode/<int:pk>/", views.TranscodeJobDetailView.as_view(), name="transcode_job"),
|
||||
path("<slug:bucket_name>/transcode/<int:pk>/edit/", views.TranscodeJobUpdateView.as_view(),
|
||||
name="transcode_job_update"),
|
||||
path("<slug:bucket_name>/transcode/<int:pk>/submit/", views.TranscodeJobSubmitView.as_view(),
|
||||
name="transcode_job_submit"),
|
||||
path("<slug:bucket_name>/packaging/<int:pk>/", views.PackagingJobDetailView.as_view(), name="packaging_job"),
|
||||
path("<slug:bucket_name>/uploads/", views.UploadCreateView.as_view(), name="upload_create"),
|
||||
path("<slug:bucket_name>/uploads/<uuid:upload_id>/", views.UploadView.as_view(), name="upload"),
|
||||
path("<slug:bucket_name>/uploads/<uuid:upload_id>/parts/<int:number>/", views.UploadPartView.as_view(),
|
||||
|
||||
@@ -4,17 +4,21 @@ import logging
|
||||
import os
|
||||
|
||||
from django.contrib import messages
|
||||
from django.db import transaction
|
||||
from django.db.models import OuterRef, Subquery
|
||||
from django.http import HttpResponse, JsonResponse
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.urls import reverse
|
||||
from django.views import View
|
||||
from django.views.generic import ListView, DetailView, UpdateView
|
||||
from django.views.generic import CreateView, DeleteView, DetailView, ListView, UpdateView
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin, AccessMixin
|
||||
|
||||
from privatestudio.studio import uploads
|
||||
from privatestudio.studio.forms import ContentAssetForm
|
||||
from privatestudio.studio.models import ContentAsset, MultipartUpload, Studio, UploadedAsset
|
||||
from privatestudio.studio.forms import ContentAssetForm, TranscodeJobForm, TranscodeProfileForm
|
||||
from privatestudio.studio.models import (
|
||||
ContentAsset, MultipartUpload, PackagingJob, Studio, TranscodeJob, TranscodeProfile, UploadedAsset,
|
||||
)
|
||||
from privatestudio.studio.profiles import EXAMPLE_PROFILE_YAML, load_default_profile
|
||||
from privatestudio.studio.request_body import BodyError, read_small_body
|
||||
from privatestudio.studio.storage import InvalidKey
|
||||
from privatestudio.studio.uploads import UploadError
|
||||
@@ -57,12 +61,17 @@ class StudioDetailView(StudioMixin, DetailView):
|
||||
context_object_name = "studio"
|
||||
slug_field = "bucket_name"
|
||||
slug_url_kwarg = "bucket_name"
|
||||
tabs = ("files", "content", "profiles")
|
||||
|
||||
def get_queryset(self):
|
||||
# Filter studios based on the user's group memberships
|
||||
user_groups = self.request.user.groups.all()
|
||||
return super().get_queryset().filter(group__in=user_groups)
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
tab = self.request.GET.get("tab")
|
||||
return super().get_context_data(active_tab=tab if tab in self.tabs else self.tabs[0], **kwargs)
|
||||
|
||||
|
||||
class UploadedAssetsView(StudioMixin, ListView):
|
||||
model = UploadedAsset
|
||||
@@ -123,7 +132,13 @@ class ContentAssetUpdateView(StudioMixin, UpdateView):
|
||||
return {**super().get_form_kwargs(), "studio": self.studio}
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(studio=self.studio, **kwargs)
|
||||
transcode_jobs = (
|
||||
self.object.transcode_jobs
|
||||
.select_related("profile")
|
||||
.prefetch_related("packaging_jobs")
|
||||
.order_by("-requested_at", "-pk")
|
||||
)
|
||||
return super().get_context_data(studio=self.studio, transcode_jobs=transcode_jobs, **kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
messages.success(self.request, f"Saved {form.instance.title}.")
|
||||
@@ -138,6 +153,203 @@ class ContentAssetUpdateView(StudioMixin, UpdateView):
|
||||
return reverse("studio:content_asset", args=[self.studio.bucket_name, self.object.pk])
|
||||
|
||||
|
||||
class StudioContextMixin:
|
||||
"""Adds the studio to template context and forms."""
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(studio=self.studio, **kwargs)
|
||||
|
||||
|
||||
class StudioFormMixin(StudioContextMixin):
|
||||
def get_form_kwargs(self):
|
||||
return {**super().get_form_kwargs(), "studio": self.studio}
|
||||
|
||||
|
||||
def _profiles_tab_url(studio):
|
||||
return reverse("studio:detail", args=[studio.bucket_name]) + "?tab=profiles"
|
||||
|
||||
|
||||
class TranscodeProfilesView(StudioContextMixin, StudioMixin, ListView):
|
||||
model = TranscodeProfile
|
||||
template_name = "privatestudio/hx_transcode_profiles.html"
|
||||
context_object_name = "profiles"
|
||||
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(studio=self.studio).select_related("created_by").order_by("name")
|
||||
|
||||
|
||||
class TranscodeProfileEditMixin(StudioFormMixin):
|
||||
model = TranscodeProfile
|
||||
form_class = TranscodeProfileForm
|
||||
template_name = "privatestudio/transcode_profile_form.html"
|
||||
context_object_name = "profile"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(example_profile=EXAMPLE_PROFILE_YAML, **kwargs)
|
||||
|
||||
def form_valid(self, form):
|
||||
response = super().form_valid(form)
|
||||
messages.success(self.request, f"Saved profile {self.object.name}.")
|
||||
return response
|
||||
|
||||
def get_success_url(self):
|
||||
return _profiles_tab_url(self.studio)
|
||||
|
||||
|
||||
class TranscodeProfileCreateView(TranscodeProfileEditMixin, StudioMixin, CreateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
return super().get_context_data(default_profile=load_default_profile(), **kwargs)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs["instance"] = TranscodeProfile(studio=self.studio, created_by=self.request.user)
|
||||
return kwargs
|
||||
|
||||
|
||||
class TranscodeProfileUpdateView(TranscodeProfileEditMixin, StudioMixin, UpdateView):
|
||||
def get_queryset(self):
|
||||
return TranscodeProfile.objects.filter(studio=self.studio)
|
||||
|
||||
|
||||
class TranscodeProfileDeleteView(StudioContextMixin, StudioMixin, DeleteView):
|
||||
model = TranscodeProfile
|
||||
template_name = "privatestudio/transcode_profile_confirm_delete.html"
|
||||
context_object_name = "profile"
|
||||
|
||||
def get_queryset(self):
|
||||
return TranscodeProfile.objects.filter(studio=self.studio)
|
||||
|
||||
def form_valid(self, form):
|
||||
name = self.object.name
|
||||
response = super().form_valid(form)
|
||||
messages.success(self.request, f"Deleted profile {name}.")
|
||||
return response
|
||||
|
||||
def get_success_url(self):
|
||||
return _profiles_tab_url(self.studio)
|
||||
|
||||
|
||||
class TranscodeJobEditMixin(StudioFormMixin):
|
||||
"""Shared by the create and update views: the form has 'save' (draft) and 'submit' buttons."""
|
||||
model = TranscodeJob
|
||||
form_class = TranscodeJobForm
|
||||
template_name = "privatestudio/transcode_job_form.html"
|
||||
context_object_name = "job"
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
profiles = {str(p.pk): p.profile_definition for p in self.studio.transcode_profiles.all()}
|
||||
return super().get_context_data(
|
||||
example_profile=EXAMPLE_PROFILE_YAML, profile_definitions=profiles,
|
||||
content_asset=self.content_asset, **kwargs,
|
||||
)
|
||||
|
||||
def form_valid(self, form):
|
||||
with transaction.atomic():
|
||||
self.save_job(form)
|
||||
submitted = "submit" in self.request.POST and self.object.submit()
|
||||
if submitted:
|
||||
messages.success(self.request, f"Submitted transcode job {self.object.pk}.")
|
||||
else:
|
||||
messages.success(self.request, f"Saved draft transcode job {self.object.pk}.")
|
||||
return redirect(self.get_success_url())
|
||||
|
||||
def save_job(self, form):
|
||||
self.object = form.save()
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("studio:transcode_job", args=[self.studio.bucket_name, self.object.pk])
|
||||
|
||||
|
||||
class TranscodeJobCreateView(TranscodeJobEditMixin, StudioMixin, CreateView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
return self.load_content_asset() or super().get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
return self.load_content_asset() or super().post(request, *args, **kwargs)
|
||||
|
||||
def load_content_asset(self):
|
||||
"""Sets self.content_asset; returns a redirect if it has no file to transcode."""
|
||||
self.content_asset = get_object_or_404(
|
||||
ContentAsset.objects.select_related("uploaded_asset"), pk=self.kwargs["pk"], studio=self.studio,
|
||||
)
|
||||
if self.content_asset.uploaded_asset is None:
|
||||
messages.error(self.request, "This content has no uploaded file to transcode.")
|
||||
return redirect("studio:content_asset", self.studio.bucket_name, self.content_asset.pk)
|
||||
return None
|
||||
|
||||
def get_form_kwargs(self):
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs["instance"] = TranscodeJob(
|
||||
studio=self.studio, requested_by=self.request.user,
|
||||
content_asset=self.content_asset, asset=self.content_asset.uploaded_asset,
|
||||
)
|
||||
return kwargs
|
||||
|
||||
def save_job(self, form):
|
||||
super().save_job(form)
|
||||
PackagingJob.objects.create(
|
||||
studio=self.studio, requested_by=self.request.user, transcode_job=self.object,
|
||||
)
|
||||
|
||||
|
||||
class TranscodeJobUpdateView(TranscodeJobEditMixin, StudioMixin, UpdateView):
|
||||
def get_queryset(self):
|
||||
return TranscodeJob.objects.filter(studio=self.studio).select_related("content_asset", "asset")
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
return self.check_editable() or super().get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
return self.check_editable() or super().post(request, *args, **kwargs)
|
||||
|
||||
def check_editable(self):
|
||||
"""Loads the job; returns a redirect to its detail page if it is no longer a draft."""
|
||||
job = self.get_object()
|
||||
self.content_asset = job.content_asset
|
||||
if not job.is_editable:
|
||||
messages.warning(self.request, f"Transcode job {job.pk} is {job.get_status_display().lower()} "
|
||||
"and can no longer be edited.")
|
||||
return redirect("studio:transcode_job", self.studio.bucket_name, job.pk)
|
||||
return None
|
||||
|
||||
|
||||
class TranscodeJobDetailView(StudioContextMixin, StudioMixin, DetailView):
|
||||
model = TranscodeJob
|
||||
template_name = "privatestudio/transcode_job_detail.html"
|
||||
context_object_name = "job"
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
TranscodeJob.objects.filter(studio=self.studio)
|
||||
.select_related("profile", "content_asset", "asset", "requested_by")
|
||||
.prefetch_related("packaging_jobs", "transcoded_assets")
|
||||
)
|
||||
|
||||
|
||||
class TranscodeJobSubmitView(StudioMixin, View):
|
||||
http_method_names = ["post"]
|
||||
|
||||
def post(self, request, bucket_name, pk):
|
||||
job = get_object_or_404(TranscodeJob, pk=pk, studio=self.studio)
|
||||
if job.submit():
|
||||
messages.success(request, f"Submitted transcode job {job.pk}.")
|
||||
else:
|
||||
messages.warning(request, f"Transcode job {job.pk} was already submitted.")
|
||||
return redirect("studio:transcode_job", self.studio.bucket_name, job.pk)
|
||||
|
||||
|
||||
class PackagingJobDetailView(StudioContextMixin, StudioMixin, DetailView):
|
||||
model = PackagingJob
|
||||
template_name = "privatestudio/packaging_job_detail.html"
|
||||
context_object_name = "packaging_job"
|
||||
|
||||
def get_queryset(self):
|
||||
return (
|
||||
PackagingJob.objects.filter(studio=self.studio)
|
||||
.select_related("transcode_job__content_asset", "transcode_job__profile", "requested_by")
|
||||
)
|
||||
|
||||
|
||||
class UploadApiView(StudioMixin, View):
|
||||
"""JSON endpoints for the browser uploader. Uses the session, with normal CSRF protection."""
|
||||
|
||||
|
||||
+6
-2
@@ -1,11 +1,13 @@
|
||||
[build-system]
|
||||
requires = ["setuptools>=68", "setuptools_scm[toml]>=8", "wheel"]
|
||||
requires = ["setuptools>=77", "setuptools_scm[toml]>=8", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "privatestudio"
|
||||
description = "Video transcoding tools with multi-profile H.264 encoding support"
|
||||
readme = "notes.md"
|
||||
readme = "README.md"
|
||||
license = "BSD-3-Clause"
|
||||
license-files = ["LICENSE"]
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"PyYAML>=6.0",
|
||||
@@ -16,6 +18,7 @@ dependencies = [
|
||||
"whitenoise~=6.11.0",
|
||||
"pytz~=2026.5",
|
||||
"django-allauth[socialaccount]~=65.0.2",
|
||||
"nh3==0.2.20",
|
||||
]
|
||||
dynamic = ["version"]
|
||||
|
||||
@@ -25,6 +28,7 @@ dev = [
|
||||
"pytest-cov>=4.0",
|
||||
"pytest-django>=4.14",
|
||||
"boto3",
|
||||
"build",
|
||||
]
|
||||
|
||||
[project.scripts]
|
||||
|
||||
@@ -6,6 +6,20 @@ $h4-font-size: $font-size-base * 1.25 !default;
|
||||
$h5-font-size: $font-size-base * 1.15 !default;
|
||||
$h6-font-size: $font-size-base !default;
|
||||
|
||||
|
||||
$white: #ffffff;
|
||||
|
||||
$theme-colors: (
|
||||
"light": #fdc8b2,
|
||||
"dark": #e4440f,
|
||||
"primary": #18499b,
|
||||
"secondary": #a65d66,
|
||||
"info": #da9a37,
|
||||
"success": #17a762,
|
||||
"warning": #e3cc17,
|
||||
"danger": #f31b0a,
|
||||
);
|
||||
|
||||
@import "bootstrap/scss/bootstrap";
|
||||
|
||||
form.simpleform input[type=text], form.simpleform textarea {
|
||||
@@ -16,3 +30,11 @@ form.simpleform label {
|
||||
font-weight: bold;
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
div.tox-tinymce div.tox-promotion {
|
||||
display: none;
|
||||
}
|
||||
|
||||
//span.tox-statusbar__branding {
|
||||
// display: none;
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user