Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review: Integrate reviewables to AYON #790

Merged
merged 19 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/ayon_core/lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
convert_ffprobe_fps_value,
convert_ffprobe_fps_to_float,
get_rescaled_command_arguments,
get_media_mime_type,
)

from .plugin_tools import (
Expand Down Expand Up @@ -209,6 +210,7 @@
"convert_ffprobe_fps_value",
"convert_ffprobe_fps_to_float",
"get_rescaled_command_arguments",
"get_media_mime_type",

"compile_list_of_regexes",

Expand Down
85 changes: 85 additions & 0 deletions client/ayon_core/lib/transcoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import tempfile
import subprocess
import platform
from typing import Optional

import xml.etree.ElementTree

Expand Down Expand Up @@ -1455,3 +1456,87 @@ def get_oiio_input_and_channel_args(oiio_input_info, alpha_default=None):
input_arg += ":ch={}".format(input_channels_str)

return input_arg, channels_arg


def _get_media_mime_type_from_ftyp(content):
if content[8:10] == b"qt":
return "video/quicktime"

if content[8:12] == b"isom":
return "video/mp4"
if content[8:12] in (b"M4V\x20", b"mp42"):
return "video/mp4v"
# (
# b"avc1", b"iso2", b"isom", b"mmp4", b"mp41", b"mp71",
# b"msnv", b"ndas", b"ndsc", b"ndsh", b"ndsm", b"ndsp", b"ndss",
# b"ndxc", b"ndxh", b"ndxm", b"ndxp", b"ndxs"
# )
return None


def get_media_mime_type(filepath: str) -> Optional[str]:
"""Determine Mime-Type of a file.

Args:
filepath (str): Path to file.

Returns:
Optional[str]: Mime type or None if is unknown mime type.

"""
if not filepath or not os.path.exists(filepath):
return None

with open(filepath, "rb") as stream:
content = stream.read()

content_len = len(content)
# Pre-validation (largest definition check)
# - hopefully there cannot be media defined in less than 12 bytes
if content_len < 12:
return None

# FTYP
if content[4:8] == b"ftyp":
return _get_media_mime_type_from_ftyp(content)

# BMP
if content[0:2] == b"BM":
return "image/bmp"

# Tiff
if content[0:2] in (b"MM", b"II"):
return "tiff"

# PNG
if content[0:4] == b"\211PNG":
return "image/png"

# SVG
if b'xmlns="http://www.w3.org/2000/svg"' in content:
return "image/svg+xml"

# JPEG, JFIF or Exif
if (
content[0:4] == b"\xff\xd8\xff\xdb"
or content[6:10] in (b"JFIF", b"Exif")
):
return "image/jpeg"

# Webp
if content[0:4] == b"RIFF" and content[8:12] == b"WEBP":
return "image/webp"

# Gif
if content[0:6] in (b"GIF87a", b"GIF89a"):
return "gif"

# Adobe PhotoShop file (8B > Adobe, PS > PhotoShop)
if content[0:4] == b"8BPS":
return "image/vnd.adobe.photoshop"

# Windows ICO > this might be wild guess as multiple files can start
# with this header
if content[0:4] == b"\x00\x00\x01\x00":
return "image/x-icon"
return None
86 changes: 81 additions & 5 deletions client/ayon_core/plugins/publish/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import clique
import pyblish.api
from ayon_api import (
get_server_api_connection,
get_attributes_for_type,
get_product_by_name,
get_version_by_name,
get_representations,
RequestTypes,
)
from ayon_api.operations import (
OperationsSession,
Expand All @@ -19,12 +21,13 @@
)
from ayon_api.utils import create_entity_id

from ayon_core.lib import source_hash
from ayon_core.lib import source_hash, get_media_mime_type
from ayon_core.lib.file_transaction import (
FileTransaction,
DuplicateDestinationError
)
from ayon_core.pipeline.publish import (
get_publish_repre_path,
KnownPublishError,
get_publish_template_name,
)
Expand Down Expand Up @@ -114,18 +117,19 @@ class IntegrateAsset(pyblish.api.InstancePlugin):
# the database even if not used by the destination template
db_representation_context_keys = [
"project",
"asset",
"hierarchy",
"folder",
"task",
"product",
"subset",
"family",
"version",
"representation",
"username",
"user",
"output"
"output",
# OpenPype keys - should be removed
"asset", # folder[name]
"subset", # product[name]
"family", # product[type]
]

def process(self, instance):
Expand Down Expand Up @@ -348,6 +352,8 @@ def register(self, instance, file_transactions, filtered_repres):
self.log.debug("{}".format(op_session.to_data()))
op_session.commit()

self._upload_reviewable(project_name, version_entity["id"], instance)

BigRoy marked this conversation as resolved.
Show resolved Hide resolved
# Backwards compatibility used in hero integration.
# todo: can we avoid the need to store this?
instance.data["published_representations"] = {
Expand Down Expand Up @@ -984,6 +990,76 @@ def prepare_file_info(self, path, anatomy):
"hash_type": "op3",
}

def _upload_reviewable(self, project_name, version_id, instance):
ayon_con = get_server_api_connection()
major, minor, _, _, _ = ayon_con.get_server_version_tuple()
if (major, minor) < (1, 3):
self.log.info(
"Skipping reviewable upload, supported from server 1.3.x."
f" User server version {ayon_con.get_server_version()}"
)
return

uploaded_labels = set()
for repre in instance.data["representations"]:
repre_tags = repre.get("tags") or []
# Ignore representations that are not reviewable
if "webreview" not in repre_tags:
continue

# exclude representations with are going to be published on farm
if "publish_on_farm" in repre_tags:
continue

# Skip thumbnails
if repre.get("thumbnail") or "thumbnail" in repre_tags:
continue

# include only thumbnail representations
repre_path = get_publish_repre_path(
instance, repre, False
)
if not repre_path or not os.path.exists(repre_path):
# TODO log skipper path
continue

content_type = get_media_mime_type(repre_path)
if not content_type:
self.log.warning("Could not determine Content-Type")
continue

# Use output name as label if available
label = repre.get("outputName")
query = ""
if label:
query = f"?label={label}"

endpoint = (
f"/projects/{project_name}"
f"/versions/{version_id}/reviewables{query}"
)
# Make sure label is unique
orig_label = label
idx = 0
while label in uploaded_labels:
idx += 1
label = f"{orig_label}_{idx}"

uploaded_labels.add(label)

# Upload the reviewable
self.log.info(f"Uploading reviewable '{label}' ...")

headers = ayon_con.get_headers(content_type)
headers["x-file-name"] = os.path.basename(repre_path)
self.log.info(f"Uploading reviewable {repre_path}")
ayon_con.upload_file(
endpoint,
repre_path,
headers=headers,
request_type=RequestTypes.post,
)

def _validate_path_in_project_roots(self, anatomy, file_path):
"""Checks if 'file_path' starts with any of the roots.

Expand Down
11 changes: 8 additions & 3 deletions server/settings/publish_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,8 @@ class PublishPuginsModel(BaseSettingsModel):
"ext": "png",
"tags": [
"ftrackreview",
"kitsureview"
"kitsureview",
"webreview"
],
"burnins": [],
"ffmpeg_args": {
Expand Down Expand Up @@ -1051,7 +1052,8 @@ class PublishPuginsModel(BaseSettingsModel):
"tags": [
"burnin",
"ftrackreview",
"kitsureview"
"kitsureview",
"webreview"
],
"burnins": [],
"ffmpeg_args": {
Expand All @@ -1063,7 +1065,10 @@ class PublishPuginsModel(BaseSettingsModel):
"output": [
"-pix_fmt yuv420p",
"-crf 18",
"-intra"
"-c:a acc",
"-b:a 192k",
"-g 1",
"-movflags faststart"
]
},
"filter": {
Expand Down