feat: MP3 asset reclassifier v1.0 - patches type:type document -> audio

This commit is contained in:
Zac Gaetano 2026-04-04 14:45:50 -04:00
parent c7a6a338df
commit efd34eb178

57
mp3-reclassify-v1.0.py Normal file
View file

@ -0,0 +1,57 @@
# ================================================================
# AMPP Framelight X — MP3 Asset Reclassifier
# Production v1.0
#
# The S3 File Trigger registers .mp3 files as type "document"
# instead of "audio". This script detects MP3 assets and patches
# their type:type from "document" to "audio".
#
# Place this script node AFTER S3 Transfer in the workflow,
# BEFORE Generate Proxy. Wire:
# S3 Transfer (ok) → MP3 Reclassifier → Generate Proxy / Rename
# S3 Transfer (failed) → End (ITS OVER, WE LOST!)
#
# If the asset is not an MP3, the script exits cleanly via ok
# with no changes made.
# ================================================================
import json
asset_id = str(asset.Id)
asset_name = str(job.AssetName)
# Check if this is an MP3 file (case-insensitive)
if not asset_name.lower().endswith(".mp3"):
# Not an MP3 — nothing to do, pass through
pass
else:
# Fetch the current asset record to get asset:rev (required for PATCH)
try:
current = httpClient.sendAsync(
"GET",
"api/v1/store/asset/Assets/" + asset_id
)
asset_rev = str(current.get("asset:rev", "0"))
except Exception as ex:
raise Exception("MP3 Reclassifier: failed to fetch asset record: " + str(ex))
# PATCH type:type from "document" → "audio"
# Uses JSON Patch format as required by the AMPP Assets API
patch_body = json.dumps([
{
"op": "replace",
"path": "/type:type",
"value": "audio"
}
])
try:
httpClient.sendAsync(
"PATCH",
"api/v1/store/asset/Assets/" + asset_id,
patch_body
)
except Exception as ex:
raise Exception(
"MP3 Reclassifier: PATCH failed for asset '"
+ asset_name + "' (" + asset_id + "): " + str(ex)
)