diff --git a/cds_migrator_kit/videos/weblecture_migration/load/helpers.py b/cds_migrator_kit/videos/weblecture_migration/load/helpers.py index 489b2fb0..23d871ee 100644 --- a/cds_migrator_kit/videos/weblecture_migration/load/helpers.py +++ b/cds_migrator_kit/videos/weblecture_migration/load/helpers.py @@ -571,7 +571,7 @@ def copy_additional_files(bucket_id, additional_files): # It'll log if copying fail if not obj: - return + continue # Add tags to the additional file ObjectVersionTag.create_or_update(obj, "context_type", "additional_file") @@ -609,3 +609,32 @@ def upload_poster(bucket_id, poster_path): _create_tags(obj) ObjectVersionTag.create_or_update(obj, "context_type", "poster") ObjectVersionTag.create_or_update(obj, "media_type", "image") + + +def get_afs_file_objects_in_record(record_files, afs_files): + """Get the afs file objects from the record files.""" + afs_file_objects = [] + for afs_file in afs_files: + file_name = os.path.basename(afs_file).split(";")[0] + file_object = next( + (file for file in record_files if file["key"] == file_name), None + ) + if file_object: + afs_file_objects.append( + { + "key": file_object["key"], + "file_id": file_object["file_id"], + } + ) + return afs_file_objects + + +def create_afs_file_objects_to_record(afs_file_objects, record_bucket_id): + """Create the afs file objects.""" + for afs_file_object in afs_file_objects: + obj = ObjectVersion.create( + bucket=record_bucket_id, + key=afs_file_object["key"], + _file_id=afs_file_object["file_id"], + ) + ObjectVersionTag.create_or_update(obj, "context_type", "additional_file") diff --git a/cds_migrator_kit/videos/weblecture_migration/load/load.py b/cds_migrator_kit/videos/weblecture_migration/load/load.py index 48ca02b0..ca4db138 100644 --- a/cds_migrator_kit/videos/weblecture_migration/load/load.py +++ b/cds_migrator_kit/videos/weblecture_migration/load/load.py @@ -41,10 +41,12 @@ from .helpers import ( copy_additional_files, copy_frames, + create_afs_file_objects_to_record, create_flow, create_project, create_video, extract_metadata, + get_afs_file_objects_in_record, publish_project, publish_video_record, transcode_task, @@ -336,9 +338,21 @@ def create_publish_multiple_video_record(self, entry): multiple_video_record = json_data.get("multiple_video_record") + # Get AFS files + afs_files = json_data.get("files", []) + afs_file_objects = [] + if afs_files: + self.migration_logger.add_information( + entry["record"]["recid"], + { + "message": "AFS files found in the multiple video record", + "value": afs_files, + }, + ) + for record in multiple_video_record: # Combine ceph and afs files - media_files = self._get_files(record["files"], json_data.get("files", [])) + media_files = self._get_files(record["files"], afs_files) master_file_id = media_files["master_path"].split("/")[-1] # Update metadata for multiple video record @@ -353,6 +367,10 @@ def create_publish_multiple_video_record(self, entry): ) ) + # Create the afs file objects to the record from first created record + if afs_files and afs_file_objects: + create_afs_file_objects_to_record(afs_file_objects, bucket_id) + # Run tasks and publish video published_video = self._run_tasks_and_publish_video( video_deposit, @@ -380,6 +398,20 @@ def create_publish_multiple_video_record(self, entry): } ) + # Get the afs_file objects from the created record + if afs_files and not afs_file_objects: + afs_file_objects = get_afs_file_objects_in_record( + published_video["_files"], afs_files + ) + if not afs_file_objects: + self.migration_logger.add_information( + entry["record"]["recid"], + { + "message": "AFS file objects not found for the multiple video record", + "value": afs_files, + }, + ) + # Publish project published_project = publish_project(deposit_id=project_deposit_id) # Run after publish fixes