diff --git a/pype/plugins/global/publish/extract_scaled_thumbnails.py b/pype/plugins/global/publish/extract_scaled_thumbnails.py deleted file mode 100644 index 6d6aa6a73c..0000000000 --- a/pype/plugins/global/publish/extract_scaled_thumbnails.py +++ /dev/null @@ -1,137 +0,0 @@ -import os -import pyblish.api -import pype.api - - -class ExtractScaledThumbnails(pyblish.api.InstancePlugin): - """Create scaled thumbnails for GUIs like loader etc. - - Scaled thumbnails creation is based on data in `output_data` attribute. - The dictionary `output_data` store additional filename ending and - filters for ffmpeg. - - Example: - "small": { - "file_end": "S", - "filters": ["scale=160:-1"] - } - - "small" - key is used to store result under represetation - "file_end" - is distinguishing part for files. - - "S" means that source thumbnail "myasset_thumbnail.jpg" - will be converted to "myasset_thumbnail_S.jpg" - "filters" - should contain filters for ffmpeg, key is `scale` filter - which is used to render thumbnails with different - resolution. - - "160:-1" will render thumbnail with 160px width and keep - aspect ratio of source image - """ - - order = pyblish.api.ExtractorOrder + 0.499 - label = "Extract scaled thumbnails" - - optional = True - active = True - hosts = ["nuke", "maya", "shell"] - # Default setting for output data - output_data = { - "small": { - "file_end": "S", - "filters": ["scale=160:-1"] - }, - "middle": { - "file_end": "M", - "filters": ["scale=320:-1"] - }, - "large": { - "file_end": "L", - "filters": ["scale=1024:-1"] - } - } - - def process(self, instance): - for repre in instance.data["representations"]: - name = repre.get("name", "") - if name: - name = " <{}>".format(name) - self.log.debug("Checking repre{}: {}".format(name, repre)) - # Skip if thumbnail not in tags - tags = repre.get("tags") or [] - if ( - "thumbnail" not in tags and - not repre.get("thumbnail") # backwards compatibility - ): - continue - - # skip if files are not set or empty - files = repre.get("files") - if not files: - continue - - orig_filename = None - if isinstance(files, (str, unicode)): - orig_filename = files - elif isinstance(files, list): - orig_filename = files[0] - else: - self.log.debug(( - "Original `files`{} have invalid type \"{}\" on repre {}" - ).format(name, str(type(files)), str(repre))) - continue - - staging_dir = repre["stagingDir"] - full_input_path = os.path.join(staging_dir, orig_filename) - - orig_basename, orig_ext = os.path.splitext(orig_filename) - thumbnail_data = {} - - _input_args = [] - # Overrides output file - _input_args.append("-y") - # Set input path - _input_args.append("-i \"{}\"".format(full_input_path)) - - ffmpeg_path = os.path.join( - os.environ.get("FFMPEG_PATH", ""), "ffmpeg" - ) - - for output_type, single_data in self.output_data.items(): - # DEBUG remove after testing! - self.log.debug(output_type) - file_end = single_data["file_end"] - in_filters = single_data["filters"] - - ffmpeg_filters = [] - if in_filters: - ffmpeg_filters.append("-vf") - ffmpeg_filters.extend([fil for fil in in_filters]) - - # copy _input_args - input_args = [arg for arg in _input_args] - input_args.extend(ffmpeg_filters) - - output_args = [] - filename = "{}_{}{}".format( - orig_basename, file_end, orig_ext - ) - full_output_path = os.path.join(staging_dir, filename) - output_args.append("\"{}\"".format(full_output_path)) - - mov_args = [ - ffmpeg_path, - " ".join(input_args), - " ".join(output_args) - ] - subprcs_cmd = " ".join(mov_args) - - self.log.debug("Executing: {}".format(subprcs_cmd)) - output = pype.api.subprocess(subprcs_cmd) - self.log.debug("Output: {}".format(output)) - - # Store data for integrator - thumbnail_data[output_type] = { - "path": full_output_path, - "filename_append": file_end - } - - repre["thumbnail_data"] = thumbnail_data diff --git a/pype/plugins/global/publish/integrate_new.py b/pype/plugins/global/publish/integrate_new.py index a8e6999e8d..cc71fce49e 100644 --- a/pype/plugins/global/publish/integrate_new.py +++ b/pype/plugins/global/publish/integrate_new.py @@ -384,65 +384,6 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): repre['published_path'] = dst self.log.debug("__ dst: {}".format(dst)) - thumbnail_data = {} - if 'thumbnail' in repre.get('tags', []): - self.log.debug(( - "Looking for scaled thumbnails in <{}>" - ).format(repre["name"])) - # prepare template for thumbnails - # - same as anatomy but keys in basename are replaced with - # one single key `thumb_file_name` - # - template is same for all thumbnails - template_base_name = os.path.basename(template) - thumb_template = template.replace( - template_base_name, "{thumb_file_name}" - ) - self.log.debug( - "Thumbnail template: {}".format(thumb_template) - ) - # get orig thumbnail filename - repre_basename = os.path.basename(dst) - repre_file, repre_ext = os.path.splitext(repre_basename) - # get thumbnail data from reresentation (if there are any) - _thumbnail_data = repre.pop("thumbnail_data", {}) - if _thumbnail_data: - thumbnail_data["template"] = thumb_template - - for thumb_type, thumb_info in _thumbnail_data.items(): - _src = thumb_info["path"] - - # get filename appending "like `S` for small thumb" - filename_append = thumb_info["filename_append"] - thumb_file_name = "{}_{}{}".format( - repre_file, filename_append, repre_ext - ) - _template_data = template_data.copy() - _template_data["thumb_file_name"] = thumb_file_name - # fill thumbnail template with prepared data - self.log.debug( - "Thumbnail <{}> template data: {}".format( - thumb_type, _template_data - ) - ) - template_filled = thumb_template.format( - **_template_data - ) - _dst = os.path.normpath( - template_filled - ).replace("..", ".") - self.log.debug( - "Thumbnail <{}> src: {} || dst: {}".format( - thumb_type, _src, _dst - ) - ) - # add to transfers - instance.data["transfers"].append([_src, _dst]) - # store full path and additional context data - thumbnail_data[thumb_type] = { - "path": _dst, - "context": {"thumb_file_name": thumb_file_name} - } - representation = { "schema": "pype:representation-2.0", "type": "representation", @@ -468,9 +409,6 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): } } - if thumbnail_data: - representation["data"]["thumbnail_data"] = thumbnail_data - if sequence_repre and repre.get("frameStart"): representation['context']['frame'] = repre.get("frameStart") @@ -485,7 +423,8 @@ class IntegrateAssetNew(pyblish.api.InstancePlugin): for rep in instance.data["representations"]: self.log.debug("__ represNAME: {}".format(rep['name'])) self.log.debug("__ represPATH: {}".format(rep['published_path'])) - io.insert_many(representations) + result = io.insert_many(representations) + instance.data["published_representation_ids"] = result.inserted_ids # self.log.debug("Representation: {}".format(representations)) self.log.info("Registered {} items".format(len(representations)))