Refactor representation data handling for thumbnails and media types.

- Refactored how thumbnail and media representation data is processed.
- Added logic to handle different types of representations based on colorspaces.
This commit is contained in:
Jakub Jezek 2024-03-05 16:17:08 +01:00
parent 09effd30fb
commit 8ecb1fa3a5
No known key found for this signature in database
GPG key ID: 730D7C02726179A7
2 changed files with 48 additions and 13 deletions

View file

@ -246,15 +246,27 @@ configuration in project settings.
"stagingDir": thumb_dir,
"outputName": explicit_output_name,
})
new_instance["prepared_data_for_repres"].append(
("_thumbnail_", thumbnail_repr_data)
)
new_instance["prepared_data_for_repres"].append({
"type": "thumbnail",
"colorspace": None,
"representation": thumbnail_repr_data,
})
# also add thumbnailPath for ayon to integrate
if not new_instance.get("thumbnailPath"):
new_instance["thumbnailPath"] = (
os.path.join(thumb_dir, thumb_file)
)
elif (
thumbnails
and not multiple_thumbnails
and not thumbnails_processed
or not reviewable
):
"""
For case where we have only one thumbnail
and not reviewable medias. This needs to be processed
only once per instance.
"""
if not thumbnails:
continue
# here we will use only one thumbnail for
@ -273,9 +285,17 @@ configuration in project settings.
"files": thumb_file,
"stagingDir": thumb_dir
})
new_instance["prepared_data_for_repres"].append(
("_thumbnail_", thumbnail_repr_data)
)
new_instance["prepared_data_for_repres"].append({
"type": "thumbnail",
"colorspace": None,
"representation": thumbnail_repr_data,
})
# also add thumbnailPath for ayon to integrate
if not new_instance.get("thumbnailPath"):
new_instance["thumbnailPath"] = (
os.path.join(thumb_dir, thumb_file)
)
thumbnails_processed = True
# get representation data
@ -284,9 +304,11 @@ configuration in project settings.
explicit_output_name
)
new_instance["prepared_data_for_repres"].append(
(repre_data["colorspace"], representation_data)
)
new_instance["prepared_data_for_repres"].append({
"type": "media",
"colorspace": repre_data["colorspace"],
"representation": representation_data,
})
def _get_refactor_thumbnail_path(
self, staging_dir, relative_thumbnail_path):

View file

@ -22,13 +22,26 @@ class CollectCSVIngestInstancesData(
prepared_repres_data_items = instance.data[
"prepared_data_for_repres"]
for colorspace, repre_data in prepared_repres_data_items:
# only apply colorspace to those which are not marked as thumbnail
if colorspace != "_thumbnail_":
for prep_repre_data in prepared_repres_data_items:
type = prep_repre_data["type"]
colorspace = prep_repre_data["colorspace"]
repre_data = prep_repre_data["representation"]
# thumbnails should be skipped
if type == "media":
# colorspace name is passed from CSV column
self.set_representation_colorspace(
repre_data, instance.context, colorspace
)
elif type == "media" and colorspace is None:
# TODO: implement colorspace file rules file parsing
self.log.warning(
"Colorspace is not defined in csv for following"
f" representation: {pformat(repre_data)}"
)
pass
elif type == "thumbnail":
# thumbnails should be skipped
pass
instance.data["representations"].append(repre_data)