Class: Vidispine::API::Utilities
- Defined in:
- lib/vidispine/api/utilities.rb,
lib/vidispine/api/utilities/cli.rb,
lib/vidispine/api/utilities/http_server.rb,
lib/vidispine/api/utilities/http_server/cli.rb
Defined Under Namespace
Classes: CLI, HTTPServer
Constant Summary collapse
- DEFAULT_REQUIRE_METADATA_MAP_MATCH =
false
Instance Attribute Summary collapse
-
#default_metadata_map ⇒ Object
Returns the value of attribute default_metadata_map.
-
#default_storage_map ⇒ Object
Returns the value of attribute default_storage_map.
Attributes inherited from Client
#api_endpoint_prefix, #api_noauth_endpoint_prefix, #http_client, #logger, #request, #response
Class Method Summary collapse
- .build_metadata_document(metadata_in, map = { }, options = { }) ⇒ Hash
- .build_metadata_documents(metadata_in, map = { }, options = { }) ⇒ Object
-
.transform_metadata_get_response_to_hash(_response, options = { }) ⇒ Hash
Reads an item’s metadata array and return a hash version of the metadata.
- .transform_metadata_group(group, breadcrumbs = [ ]) ⇒ Hash
Instance Method Summary collapse
- #build_item_search_document(criteria, options = { }) ⇒ Hash
- #build_metadata_document(metadata_in, map = { }, options = { }) ⇒ Object
- #build_metadata_documents(metadata_in, map = { }, options = { }) ⇒ Array
- #cantemo_metadata_field_group_map(field_group, options = { }) ⇒ Hash
- #cantemo_metadata_field_process(field, options = { }) ⇒ Hash
-
#collection_create_if_not_exists(args = { }, options = { }) ⇒ Hash
Searches for a collection by name and if a match is not found then a new collection is created This method will only return the first match if an existing collection is found.
- #collection_file_add_using_path(args = { }, options = { }) ⇒ Object
-
#collection_get_by_name(args = { }, options = { }) ⇒ Hash|Array|nil
Searches for a collection by name.
-
#collection_item_add_extended(args = { }, options = { }) ⇒ Object
Adds an Item to a Collection but Gives Multiple ways of Determining the Collection.
-
#determine_collection(args, options = { }) ⇒ Object
Tries to find a collection using either the collection id, name, or a file path with a collection name position.
-
#initialize(args = { }) ⇒ Utilities
constructor
A new instance of Utilities.
-
#item_add_using_file_path(args = { }, options = { }) ⇒ Hash
Adds a file using the files path.
-
#item_add_using_file_path_metadata(args = { }, options = { }) ⇒ Object
Add an item to the system using file path metadata field as the key 1.
- #item_annotation_create(args = { }, options = { }) ⇒ Object
- #item_annotation_get(args = { }, options = { }) ⇒ Object
- #item_create_with_proxy_using_file_uri(args = { }, options = { }) ⇒ Object deprecated Deprecated.
- #item_create_with_proxy_using_storage_file_paths(args = { }, options = { }) ⇒ Hash deprecated Deprecated.
- #item_export_extended(args = { }, options = { }) ⇒ Object
- #item_shape_add_using_file_path(args = { }, options = { }) ⇒ Object (also: #item_add_shape_using_file_path)
- #item_shapes_get_extended(args = { }, options = { }) ⇒ Object
- #item_transcode_shape(args = { }, options = { }) ⇒ Object
- #items_search_extended(args = { }, options = { }) ⇒ Object (also: #item_search_extended)
-
#process_file_path_using_storage_map(file_path, storage_path_map = nil) ⇒ Hash
Will process a file path through a storage path map.
- #storage_file_copy_extended(args = { }, options = { }) ⇒ Object
- #storage_file_create_extended(args = { }, options = { }) ⇒ Object
-
#storage_file_get_or_create(storage_id, file_path_relative_to_storage_path, options = { }) ⇒ Hash
Will search for a relative file path on a storage and if not found will trigger a storage_file_create.
- #storage_file_get_using_file_path(args = { }) ⇒ Hash|nil
-
#storage_file_path_map_create(args = {}) ⇒ Hash
Generates a storage file path map from the current storages.
-
#symbolize_keys(value, recursive = true) ⇒ Object
Converts hash keys to symbols.
- #transform_metadata_get_response_to_hash(_response, options = { }) ⇒ Object
- #transform_metadata_to_fields(metadata_in, map = { }, options = { }) ⇒ Object
-
#wait_for_job_completion(args = { }) ⇒ Hash
Waits for a job to complete.
Methods inherited from Client
#collection_access_add, #collection_access_delete, #collection_access_get, #collection_create, #collection_delete, #collection_get, #collection_items_get, #collection_metadata_get, #collection_metadata_set, #collection_object_add, #collection_object_remove, #collection_rename, #collections_get, #error, #http, #import_placeholder, #import_placeholder_item, #import_using_uri, #item_access_add, #item_access_delete, #item_access_get, #item_access_list, #item_collections_get, #item_delete, #item_export, #item_get, #item_metadata_get, #item_metadata_set, #item_notifications_delete, #item_shape_files_get, #item_shape_get, #item_shape_import, #item_shape_placholder_create, #item_shapes_get, #item_sidecar_import, #item_thumbnail, #item_transcode, #item_uris_get, #items_get, #items_search, #job_abort, #job_get, #jobs_get, #metadata_field_delete, #metadata_field_get, #metadata_field_group_get, #metadata_field_groups_get, #metadata_field_terse_schema, #metadata_fields_get, #process_request, #process_request_using_class, #search, #search_browse, #storage_delete, #storage_file_copy, #storage_file_create, #storage_file_get, #storage_file_item_get, #storage_files_get, #storage_get, #storage_method_get, #storage_rescan, #storages_get, #success?, #version
Constructor Details
#initialize(args = { }) ⇒ Utilities
Returns a new instance of Utilities.
14 15 16 17 18 19 |
# File 'lib/vidispine/api/utilities.rb', line 14 def initialize(args = { }) @default_storage_map = args[:storage_map] || { } = args[:metadata_map] || { } = args.fetch(:require_metadata_map_match, DEFAULT_REQUIRE_METADATA_MAP_MATCH) super end |
Instance Attribute Details
#default_metadata_map ⇒ Object
Returns the value of attribute default_metadata_map.
12 13 14 |
# File 'lib/vidispine/api/utilities.rb', line 12 def end |
#default_storage_map ⇒ Object
Returns the value of attribute default_storage_map.
12 13 14 |
# File 'lib/vidispine/api/utilities.rb', line 12 def default_storage_map @default_storage_map end |
Class Method Details
.build_metadata_document(metadata_in, map = { }, options = { }) ⇒ Hash
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/vidispine/api/utilities.rb', line 312 def self.(, map = { }, = { }) # map = (options[:default_metadata_map]).merge((options[:metadata_map] || { }).merge(map)) require_map_match = .fetch(:require_metadata_map_match, DEFAULT_REQUIRE_METADATA_MAP_MATCH) groups = { } .each do |k,v| _map = map[k] _map = k if _map.nil? && !require_map_match next unless _map _map = [ _map ] unless _map.is_a?(Array) _map.each do |_map_| _map_ = { :field => _map_ } if _map_.is_a?(String) #puts "##{_map_[:group].inspect} #{_map_.class.name} #{_map_.inspect}" (groups[_map_[:group]] ||= { })[_map_[:field]] = v end end = map[:__build_metadata_document_options] || map['__build_metadata_document_options'] || { } .merge!() parent_group_name = [:parent_group_name] _field = groups.delete(nil) { { } }.map { |fname, values| { :name => fname, :value => [*values].map { |v| { :value => v } } } } _group = groups.map { |name, fields| { :name => name, :field => fields.map { |fname, values| { :name => fname, :value => [*values].map { |v| { :value => v } } } } } } # metadata_out = { } # metadata_out[:field] = _field unless _field.empty? # metadata_out[:group] = _group unless _group.empty? # metadata_out #{ :field => _field, :group => _group } if (_field.empty? && _group.length == 1 && (!parent_group_name || parent_group_name.empty?)) _group = _group.first group_name = _group[:name] group_fields = _group[:field] return { :group => [ group_name ], :timespan => [ { :start => '-INF', :end => '+INF', :field => group_fields } ] } end _data_out = { :timespan => [ { :start => '-INF', :end => '+INF', :field => _field, :group => _group } ] } _data_out[:group] ||= [ parent_group_name ] if parent_group_name _data_out end |
.build_metadata_documents(metadata_in, map = { }, options = { }) ⇒ Object
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'lib/vidispine/api/utilities.rb', line 361 def self.(, map = { }, = { }) require_map_match = .fetch(:require_metadata_map_match, DEFAULT_REQUIRE_METADATA_MAP_MATCH) groups = { } .each do |k,v| _map = require_map_match ? map[k] : map.fetch(k, k) next unless _map _map = [ _map ] unless _map.is_a?(Array) _map.each do |_map_| _map_ = { :field => _map_ } if _map_.is_a?(String) || _map.is_a?(Symbol) #puts "##{_map_[:group].inspect} #{_map_.class.name} #{_map_.inspect}" (groups[_map_[:group]] ||= { })[_map_[:field]] = v end end _field = groups.delete(nil) { { } }.map { |fname, values| { :name => fname, :value => [*values].map { |v| { :value => v } } } } _groups = groups.map { |name, fields| { :name => name, :field => fields.map { |fname, values| { :name => fname, :value => [*values].map { |v| { :value => v } } } } } } docs = [ ] if !_field.empty? docs << { :timespan => [ { :start => '-INF', :end => '+INF', :field => _field, :group => [ ] } ] } end _groups.each do |_group| group_name = _group[:name] group_fields = _group[:field] docs << { :group => [ group_name ], :timespan => [ { :start => '-INF', :end => '+INF', :field => group_fields } ] } end docs end |
.transform_metadata_get_response_to_hash(_response, options = { }) ⇒ Hash
Reads an item’s metadata array and return a hash version of the metadata
{
"item": [
{
"metadata": {
"revision": "VX-348,VX-766,VX-350,VX-352,VX-767,VX-353,VX-816,VX-815,VX-346",
"group": [
"Film"
],
"timespan": [
{
"start": "-INF",
"end": "+INF",
"field": [
{
"name": "portal_mf778031",
"uuid": "4150479f-b15e-475b-bc48-80ef85d3c2cf",
"change": "VX-767",
"user": "admin",
"value": [
{
"uuid": "a7f91e7c-ffc6-4ba1-9658-3458bec886e9",
"change": "VX-767",
"user": "admin",
"value": "556dd36a02a760d6bd000071",
"timestamp": "2015-07-06T22:25:17.926+0000"
}
],
"timestamp": "2015-07-06T22:25:17.926+0000"
},
{
"name": "portal_mf897662"
},
{
"name": "portal_mf396149"
}
],
"group": [
]
}
]
},
"id": "VX-84"
}
]
}
232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/vidispine/api/utilities.rb', line 232 def self.(_response, = { }) items = _response['item'] || _response item = items.is_a?(Array) ? items.first : items = item['metadata'] || item = { } # group = item_metadata['group'].first timespans = ['timespan'] timespans.each do |t| .merge!((t)) end end |
.transform_metadata_group(group, breadcrumbs = [ ]) ⇒ Hash
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
# File 'lib/vidispine/api/utilities.rb', line 253 def self.(group, = [ ]) = { } name = group['name'] = .dup << name bc = .compact.join(':') bc << ':' unless bc.empty? groups = group['group'] if groups.length == 1 and (_group_name = groups.first).is_a?(String) # group_name = _group_name.is_a?(String) ? _group_name : '' else # group_name = '' groups.each do |g| .merge!((g, )) end end fields = group['field'] fields.each do |f| # field_name = "#{group_name}#{group_name.empty? ? '' : ':'}#{f['name']}" field_name = "#{bc}#{f['name']}" field_value_raw = f['value'] if field_value_raw.is_a?(Array) field_value = field_value_raw.map { |v| v['value'] } field_value = field_value.first if field_value.length == 1 else field_value = field_value_raw end [field_name] = field_value end end |
Instance Method Details
#build_item_search_document(criteria, options = { }) ⇒ Hash
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/vidispine/api/utilities.rb', line 289 def build_item_search_document(criteria, = { }) fields = criteria[:fields] || criteria item_search_document = { :field => fields.map { |fname, values| if values.is_a?(Hash) #_values = values.map { |k, values| { k => [ { :value => [*values].map { |v| { :value => v } } } ] } }.inject({}) { |hash, value| hash.merge(value) } _values = Hash[ values.map { |k, values| [ k, [ { :value => [*values].map { |v| { :value => v } } } ] ] } ] else _values = { :value => [*values].map { |v| { :value => v } } } end { :name => fname }.merge(_values) } } item_search_document end |
#build_metadata_document(metadata_in, map = { }, options = { }) ⇒ Object
354 355 356 357 358 359 |
# File 'lib/vidispine/api/utilities.rb', line 354 def (, map = { }, = { }) map = ([:default_metadata_map] || ).merge(([:metadata_map] || { }).merge(map)) = [:require_metadata_map_match] [:require_metadata_map_match] = if .nil? self.class.(, map, ) end |
#build_metadata_documents(metadata_in, map = { }, options = { }) ⇒ Array
395 396 397 398 399 400 |
# File 'lib/vidispine/api/utilities.rb', line 395 def (, map = { }, = { }) map = ([:default_metadata_map] || ).merge(map.merge([:metadata_map] || { })) = [:require_metadata_map_match] [:require_metadata_map_match] = if .nil? self.class.(, map, ) end |
#cantemo_metadata_field_group_map(field_group, options = { }) ⇒ Hash
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/vidispine/api/utilities.rb', line 404 def (field_group, = { }) field_group = (:group_name => field_group, :include_values => true, :traverse => true) if field_group.is_a?(String) field_map = { } group_name = field_group['schema']['name'] fields = field_group['field'] fields.each do |field| cp_field = (field) cp_field[:group] = group_name cp_field[:vs_def] = field field_map[cp_field[:label]] = cp_field end field_map end |
#cantemo_metadata_field_process(field, options = { }) ⇒ Hash
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/vidispine/api/utilities.rb', line 424 def (field, = { }) field_name = field['name'] field_data = field['data'] field_data = JSON.parse(field['data']) if field_data.is_a?(String) && field_data.start_with?('{') field_extra_data = field_data.find { |fd| fd['key'] == 'extradata' } || { } field_extra_data_value = field_extra_data['value'] field_extra_data_value = JSON.parse(field_extra_data_value) if field_extra_data_value.is_a?(String) && field_extra_data_value.start_with?('{') return nil unless field_extra_data_value.is_a?(Hash) field_label = field_extra_data_value['name'] cp_field_type = field_extra_data_value['type'] cp_field = { :name => field_name, :type => cp_field_type, :label => field_label, :cp_def => field_extra_data_value } case cp_field_type when 'checkbox', 'dropdown' _values = field_extra_data_value['values'] choices = Hash[ _values.map { |v| [ v['key'], v['value'] ] } ] cp_field[:choices] = choices when 'lookup' field_data__values = (field_data.find { |fd| fd['key'] == '__values' } || { })['value'] if field_data__values __values_xml = field_data__values.gsub('\"', '"') __values_doc = REXML::Document.new(StringIO.new(__values_xml)) choices = { } __values_doc.elements.each('SimpleMetadataDocument/field') do |e| choices[e.elements['key'].text] = e.elements['value'].text end cp_field[:choices] = choices end end cp_field end |
#collection_create_if_not_exists(args = { }, options = { }) ⇒ Hash
Searches for a collection by name and if a match is not found then a new collection is created This method will only return the first match if an existing collection is found.
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/vidispine/api/utilities.rb', line 475 def collection_create_if_not_exists(args = { }, = { }) return args.map { |v| collection_create_if_not_exists(v, ) } if args.is_a?(Array) args = args.is_a?(Hash) ? args : { :collection_name => args } collection_name = args[:collection_name] || args[:name] raise ArgumentError, 'collection_name is required.' unless collection_name case_sensitive = .fetch(:case_sensitive, true) collection = collection_get_by_name( :collection_name => collection_name, :case_sensitive => case_sensitive ) collection_already_existed = collection && !collection.empty? ? true : false collection ||= collection_create(collection_name) [:extended_response] ? { :collection => collection, :collection_already_existed => collection_already_existed } : collection end |
#collection_file_add_using_path(args = { }, options = { }) ⇒ Object
1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 |
# File 'lib/vidispine/api/utilities.rb', line 1023 def collection_file_add_using_path(args = { }, = { }) args = symbolize_keys(args, false) _response = { } # 1. Receive a File Path file_path = args[:file_path] raise ArgumentError, ':file_path is a required argument.' unless file_path = args[:metadata_file_path_field_id] raise ArgumentError, ':metadata_file_path_field_id is a required argument.' unless # 2. Determine Storage ID storage_path_map = args[:storage_path_map] || args[:storage_map] raise ArgumentError, ':storage_path_map is a required argument.' unless storage_path_map # Make sure the keys are strings storage_path_map = Hash[storage_path_map.map { |k,v| [k.to_s, v] }] if storage_path_map.is_a?(Hash) volume_path, storage = storage_path_map.find { |path, _| file_path.start_with?(path) } raise "Unable to find match in storage path map for '#{file_path}'. Storage Map: #{storage_path_map.inspect}" unless volume_path file_path_relative_to_storage_path = file_path.sub(volume_path, '') logger.debug { "File Path Relative to Storage Path: #{file_path_relative_to_storage_path}" } storage = storage_get(:id => storage) if storage.is_a?(String) _response[:storage] = storage raise 'Error Retrieving Storage Record. Storage Id: #{' unless storage storage_id = storage['id'] storage_uri_raw = storage['method'].first['uri'] storage_uri = URI.parse(storage_uri_raw) vidispine_file_path = File.join(storage_uri.path, file_path_relative_to_storage_path) logger.debug { "Vidispine File Path: '#{vidispine_file_path}'" } _response[:vidispine_file_path] = vidispine_file_path # 3 Get Collection collection_id = args[:collection_id] unless collection_id collection_name = args[:collection_name] unless collection_name file_path_collection_name_position = args[:file_path_collection_name_position] raise ArgumentError, ':collection_id, :collection_name, or :file_path_collection_name_position argument is required.' unless file_path_collection_name_position file_path_split = (file_path_relative_to_storage_path.start_with?('/') ? file_path_relative_to_storage_path[1..-1] : file_path_relative_to_storage_path).split('/') collection_name = file_path_split[file_path_collection_name_position] raise ArgumentError, 'Unable to determine collection name from path.' unless collection_name logger.debug { "Using '#{collection_name}' as collection_name. File Path Array: #{file_path_split.inspect}" } end # Determine Collection collection = collection_create_if_not_exists(:collection_name => collection_name) collection_id = collection['id'] else collection = collection_get(:collection_id => collection_id) raise ArgumentError, 'Collection not found.' unless collection end _response[:collection] = collection #return # 4.1 Search for Item using File Path search_response = search(:content => 'metadata', :item_search_document => { :field => [ { :name => , :value => [ { :value => vidispine_file_path } ] } ] } ) || { 'entry' => [ ] } _response[:search] = search_response item = (search_response['entry'].first || { })['item'] unless item storage_file_get_or_create_response = storage_file_get_or_create(storage_id, file_path_relative_to_storage_path, :extended_response => true) _response[:storage_file_get_or_create_response] = storage_file_get_or_create_response file = storage_file_get_or_create_response[:file] item = placeholder = file['item'] unless item # 4.2 Create a Placeholder logger.debug { 'Creating Placeholder.' } #placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1, :metadata_document => { :group => [ 'Film' ], :timespan => [ { :field => [ { :name => metadata_file_path_field_id, :value => [ { :value => vidispine_file_path } ] } ], :start => '-INF', :end => '+INF' } ] } } placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1, :metadata_document => { :timespan => [ { :field => [ { :name => , :value => [ { :value => vidispine_file_path } ] } ], :start => '-INF', :end => '+INF' } ] } } item = placeholder = import_placeholder(placeholder_args) end _response[:placeholder] = placeholder end _response[:item] = item item_id = item['id'] # 5. Add Item to the Collection logger.debug { 'Adding Item to Collection.' } collection_object_add_response = collection_object_add(:collection_id => collection_id, :object_id => item_id) _response[:collection_object_add] = collection_object_add_response # Item was already in the system so exit here return _response unless file file_id = file['id'] raise "File Id Not Found. #{file.inspect}" unless file_id # 6. Add the file as the original shape logger.debug { 'Adding the file as the Original Shape.' } item_shape_import_response = item_shape_import(:item_id => item_id, :file_id => file_id, :tag => 'original') _response[:item_shape_import] = item_shape_import_response job_id = item_shape_import_response['jobId'] if job_id job_monitor_response = wait_for_job_completion(:job_id => job_id) { |env| logger.debug { "Waiting for Item Shape Import Job to Complete. Time Elapsed: #{Time.now - env[:time_started]} seconds" } } last_response = job_monitor_response[:last_response] raise "Error Adding file As Original Shape. Response: #{last_response.inspect}" unless last_response['status'] == 'FINISHED' _response[:item_shape_import_job] = job_monitor_response end # 7. Generate the Transcode of the item transcode_tag = args[:transcode_tag] || 'lowres' logger.debug { 'Generating Transcode of the Item.' } item_transcode_response = item_transcode(:item_id => item_id, :tag => transcode_tag) _response[:item_transcode] = item_transcode_response # 8. Generate the Thumbnails and Poster Frame create_thumbnails = args.fetch(:create_thumbnails, true) create_posters = args[:create_posters] || 3 logger.debug { 'Generating Thumbnails(s) and Poster Frame.' } item_thumbnail_response = item_thumbnail(:item_id => item_id, :createThumbnails => create_thumbnails, :createPosters => create_posters) _response[:item_thumbnail] = item_thumbnail_response _response end |
#collection_get_by_name(args = { }, options = { }) ⇒ Hash|Array|nil
Searches for a collection by name
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
# File 'lib/vidispine/api/utilities.rb', line 499 def collection_get_by_name(args = { }, = { }) return collection_create_if_not_exists(args, ) if [:collection_create_if_not_exists] args = args.is_a?(Hash) ? args : { :collection_name => args } collection_name = args[:collection_name] || args[:name] return_first_match = .fetch(:return_first_match, true) unless collection_name raise ArgumentError, 'collection_name is required.' end # collections = ( (collections_get || { })['collection'] || [ ] ) first = 1 limit = 1000 collections = [ ] loop do r = collections_get(:first => first, :number => limit) _collections = r['collection'] break if _collections.empty? collections.concat _collections first += _collections.length end comparison_method, comparison_value = .fetch(:case_sensitive, true) ? [ :eql?, true ] : [ :casecmp, 0 ] collections_search_method = return_first_match ? :find : :select collections.send(collections_search_method) { |c| c['name'].send(comparison_method, collection_name) == comparison_value } end |
#collection_item_add_extended(args = { }, options = { }) ⇒ Object
Adds an Item to a Collection but Gives Multiple ways of Determining the Collection
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/vidispine/api/utilities.rb', line 83 def collection_item_add_extended(args = { }, = { }) args = symbolize_keys(args, false) _response = { } item = args[:item] || { } item_id = args[:item_id] || item['id'] # # 3 Get Collection # collection_id = args[:collection_id] || collection['id'] # unless collection_id # collection_name = args[:collection_name] # unless collection_name # file_path_collection_name_position = args[:file_path_collection_name_position] # raise ArgumentError, ':collection_id, :collection_name, or :file_path_collection_name_position argument is required.' unless file_path_collection_name_position # # file_path_split = (file_path.start_with?('/') ? file_path[1..-1] : file_path).split('/') # collection_name = file_path_split[file_path_collection_name_position] # raise ArgumentError, 'Unable to determine collection name from path.' unless collection_name # logger.debug { "Using '#{collection_name}' as collection_name. File Path Array: #{file_path_split.inspect}" } # end # # Determine Collection # collection = collection_create_if_not_exists(:collection_name => collection_name) # collection_id = collection['id'] # else # collection ||= collection_get(:collection_id => collection_id) # raise ArgumentError, 'Collection not found.' unless collection # end collection = determine_collection(args) _response[:collection] = collection collection_id = collection['id'] # 5. Add Item to the Collection logger.debug { 'Adding Item to Collection.' } collection_object_add_response = collection_object_add(:collection_id => collection_id, :object_id => item_id) _response[:collection_object_add] = collection_object_add_response _response end |
#determine_collection(args, options = { }) ⇒ Object
Tries to find a collection using either the collection id, name, or a file path with a collection name position. For use in other methods that need to perform the same type of lookup
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vidispine/api/utilities.rb', line 47 def determine_collection(args, = { }) collection = args[:collection] || { } # 3 Get Collection collection_id = args[:collection_id] || collection['id'] unless collection_id collection_name = args[:collection_name] || args[:name] unless collection_name file_path_collection_name_position = args[:file_path_collection_name_position] raise ArgumentError, ':collection_id, :collection_name, or :file_path_collection_name_position argument is required.' unless file_path_collection_name_position file_path = args[:file_path] raise ArgumentError, ':file_path is a required argument when using :file_path_collection_name_position' unless file_path file_path_split = (file_path.start_with?('/') ? file_path[1..-1] : file_path).split('/') collection_name = file_path_split[file_path_collection_name_position] raise ArgumentError, 'Unable to determine collection name from path.' unless collection_name logger.debug { "Using '#{collection_name}' as collection_name. File Path Array: #{file_path_split.inspect}" } end # Determine Collection #collection = collection_create_if_not_exists(:collection_name => collection_name) collection = collection_get_by_name({ :collection_name => collection_name }, ) else collection = collection_get(:collection_id => collection_id) raise ArgumentError, 'Collection not found.' unless collection and collection['id'] end collection end |
#item_add_using_file_path(args = { }, options = { }) ⇒ Hash
Adds a file using the files path
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 |
# File 'lib/vidispine/api/utilities.rb', line 547 def item_add_using_file_path(args = { }, = { }) args = symbolize_keys(args, false) _response = { } original_shape_tag_name = args[:original_shape_tag_name] || 'original' # 1. Receive a File Path file_path = args[:file_path] raise ArgumentError, ':file_path is a required argument.' unless file_path # 2. Determine Storage ID storage_method = args[:storage_method] || 'file' storage_path_map = args[:storage_path_map] storage_path_map = storage_file_path_map_create(:storage_method => storage_method) unless storage_path_map and !storage_path_map.empty? storage_id = args[:storage_id] if storage_id volume_path, storage = storage_path_map.find { |_, id| id == storage_id } raise "Unable to find match in storage path map for '#{storage_id}'. Storage Map: #{storage_path_map.inspect}" unless volume_path else volume_path, storage = storage_path_map.find { |path, _| file_path.start_with?(path) } raise "Unable to find match in storage path map for '#{file_path}'. Storage Map: #{storage_path_map.inspect}" unless volume_path end file_path_relative_to_storage_path = file_path.sub(volume_path, '') logger.debug { "File Path Relative to Storage Path: #{file_path_relative_to_storage_path}" } storage = storage_get(:id => storage) if storage.is_a?(String) _response[:storage] = storage storage_id = storage['id'] raise "Error Retrieving Storage Record. Storage: #{storage.inspect}" unless storage_id # The URI Lookup part was commented out as it should be handled by the storage_file_path_map_create # The method type of the URI to lookup # storage_method_type = args[:storage_method_type] ||= 'file' # # storage_uri_method = "#{storage_method_type}:" # storage_uri_raw = (storage['method'].find { |v| v['uri'].start_with?(storage_uri_method) } || { })['uri'] rescue nil # raise "Error Getting URI from Storage Method. Storage: #{storage.inspect}" unless storage_uri_raw # storage_uri = URI.parse(storage_uri_raw) # # vidispine_file_path = File.join(storage_uri.path, file_path_relative_to_storage_path) vidispine_file_path = File.join(volume_path, file_path_relative_to_storage_path) logger.debug { "Vidispine File Path: '#{vidispine_file_path}'" } _response[:vidispine_file_path] = vidispine_file_path = args[:metadata] || { } = args[:metadata_map] || { } # map metadata assuming 1 value per field #_metadata_as_fields = transform_metadata_to_fields(_metadata, _metadata_map, options) #metadata_document = build_metadata_document(_metadata, _metadata_map, options) = (, , ) = .shift || { } # Allow the file to be passed in file = args[:file] unless file file_id = args[:file_id] file = { 'id' => file_id } end if file_id && file && !file['item'] # If the passed file doesn't have an item then requery to verify that the item is absent storage_file_get_response = storage_file_get(:storage_id => storage_id, :file_id => file_id, :include_item => true) raise "Error Getting Storage File. '#{storage_file_get_response.inspect}'" unless storage_file_get_response and storage_file_get_response['id'] _response[:storage_file_get_response] = storage_file_get_response file = storage_file_get_response else storage_file_get_or_create_response = storage_file_get_or_create(storage_id, file_path_relative_to_storage_path, :extended_response => true) _response[:storage_file_get_or_create_response] = storage_file_get_or_create_response file = storage_file_get_or_create_response[:file] file_found = storage_file_get_or_create_response[:file_already_existed] end if file _response[:item] = item = file['item'] file_found = true end _response[:file_already_existed] = file_found _response[:item_already_existed] = !!item return _response if item file_id = file['id'] unless item # 4.2 Create a Placeholder logger.debug { 'Creating Placeholder.' } #placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1, :metadata_document => { :group => [ 'Film' ], :timespan => [ { :field => [ { :name => metadata_file_path_field_id, :value => [ { :value => vidispine_file_path } ] } ], :start => '-INF', :end => '+INF' } ] } } #placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1, :metadata_document => { :timespan => [ { :start => '-INF', :end => '+INF' }.merge(_metadata_as_fields) ] } } #placeholder_args = args[:placeholder_args] ||= { :container => 1, :metadata_document => { :timespan => [ { :start => '-INF', :end => '+INF' }.merge(_metadata_as_fields) ] } } placeholder_args = args[:placeholder_args] ||= { :container => 1, :metadata_document => } _response[:item] = item = import_placeholder(placeholder_args) end item_id = item['id'] shape = item['shape'] raise "Error Creating Placeholder: #{item.inspect}" unless item_id # Add any additional metadata (Vidispine will only take one group at a time) .each do || (:item_id => item_id, :metadata_document => ) end if [:add_item_to_collection] logger.debug { 'Determining Collection to Add the Item to.' } collection = determine_collection(args, ) _response[:collection] = collection collection_id = collection['id'] logger.debug { 'Adding Item to Collection.' } collection_object_add_response = collection_object_add(:collection_id => collection_id, :object_id => item_id) _response[:collection_object_add] = collection_object_add_response end create_thumbnails = args.fetch(:create_thumbnails, true) create_posters = args.fetch(:create_posters, 3) unless shape # 6. Add the file as the original shape logger.debug { 'Adding the file as the Original Shape.' } item_shape_import_response = import_placeholder_item(:item_id => item_id, :file_id => file_id, :tag => original_shape_tag_name) # item_shape_import_response = item_shape_import(:item_id => item_id, :file_id => file_id, :tag => original_shape_tag_name) _response[:item_shape_import] = item_shape_import_response job_id = item_shape_import_response['jobId'] unless job_id invalid_input = item_shape_import_response['invalidInput'] if invalid_input explanation = invalid_input['explanation'] job_id = $1 if explanation.match(/.*\[(.*)\]$/) end end raise "Error Creating Item Shape Import Job. Response: #{item_shape_import_response.inspect}" unless job_id job_monitor_response = wait_for_job_completion(:job_id => job_id) { |env| logger.debug { "Waiting for Item Shape Import Job to Complete. Time Elapsed: #{Time.now - env[:time_started]} seconds" } } last_response = job_monitor_response[:last_response] raise "Error Adding file As Original Shape. Response: #{last_response.inspect}" unless last_response['status'] == 'FINISHED' # 7. Generate the Transcode of the item transcode_tag = args.fetch(:transcode_tag, 'lowres') if transcode_tag and !transcode_tag.empty? and transcode_tag.to_s.downcase != 'false' wait_for_transcode_job = [:wait_for_transcode_job] skip_transcode_if_shape_with_tag_exists = .fetch(:skip_transcode_if_shape_with_tag_exists, true) [*transcode_tag].each do |_transcode_tag| transcode_response = item_transcode_shape({ :item_id => item_id, :transcode_tag => _transcode_tag }, { :wait_for_transcode_job => wait_for_transcode_job, :skip_if_shape_with_tag_exists => skip_transcode_if_shape_with_tag_exists }) (_response[:transcode] ||= { })[transcode_tag] = transcode_response # each transcode_tag end # if transcode_tag end # 8. Generate the Thumbnails and Poster Frame if (create_thumbnails or create_posters) logger.debug { 'Generating Thumbnails(s) and Poster Frame.' } args_out = { :item_id => item_id } args_out[:create_thumbnails] = create_thumbnails if create_thumbnails args_out[:create_posters] = create_posters if create_posters item_thumbnail_response = item_thumbnail(args_out) _response[:item_thumbnail] = item_thumbnail_response end end _response end |
#item_add_using_file_path_metadata(args = { }, options = { }) ⇒ Object
Add an item to the system using file path metadata field as the key
-
Search for pre existing asset
-
Create a placeholder with metadata (if asset doesn’t exist)
-
Create an original shape.
-
Poll the Job status of the shape creation
-
Trigger the Transcode of the Proxy, thumbnails
-
Trigger the Transcode of the thumbnail.
-
Trigger the Transcode of the poster frame
This was an early experiment
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 |
# File 'lib/vidispine/api/utilities.rb', line 738 def (args = { }, = { }) args = symbolize_keys(args, false) _response = { } # 1. Receive a File Path file_path = args[:file_path] raise ArgumentError, ':file_path is a required argument.' unless file_path = args[:metadata_file_path_field_id] raise ArgumentError, ':metadata_file_path_field_id is a required argument.' unless # 2. Determine Storage ID storage_path_map = args[:storage_path_map] raise ArgumentError, ':storage_path_map is a required argument.' unless storage_path_map # Make sure the keys are strings storage_path_map = Hash[storage_path_map.map { |k,v| [k.to_s, v] }] if storage_path_map.is_a?(Hash) volume_path, storage = storage_path_map.find { |path, _| file_path.start_with?(path) } raise "Unable to find match in storage path map for '#{file_path}'. Storage Map: #{storage_path_map.inspect}" unless volume_path file_path_relative_to_storage_path = file_path.sub(volume_path, '') logger.debug { "File Path Relative to Storage Path: #{file_path_relative_to_storage_path}" } storage = storage_get(:id => storage) if storage.is_a?(String) _response[:storage] = storage raise "Error Retrieving Storage Record. Storage Id: #{storage.inspect}" unless storage storage_id = storage['id'] storage_uri_raw = storage['method'].first['uri'] storage_uri = URI.parse(storage_uri_raw) vidispine_file_path = File.join(storage_uri.path, file_path_relative_to_storage_path) logger.debug { "Vidispine File Path: '#{vidispine_file_path}'" } _response[:vidispine_file_path] = vidispine_file_path = args[:metadata] || { } [] ||= vidispine_file_path = args[:metadata_map] || { } # map metadata assuming 1 value per field = (, , ) # 4.1 Search for Item using File Path search_response = search(:content => 'metadata', :item_search_document => { :field => [ { :name => , :value => [ { :value => vidispine_file_path } ] } ] } ) || { 'entry' => [ ] } _response[:search] = search_response item = (search_response['entry'].first || { })['item'] unless item # If the item wasn't found then get the file id for the file # 4.1 Search for the storage file record storage_file_get_response = storage_files_get(:storage_id => storage_id, :path => file_path_relative_to_storage_path) || { 'file' => [ ] } raise "Error Getting Storage File. '#{response.inspect}'" unless storage_file_get_response and storage_file_get_response['id'] file = storage_file_get_response['file'].first _response[:storage_file_get_response] = storage_file_get_response unless file # 4.1.1 Create the storage file record if it does not exist file = storage_file_create_response = storage_file_create(:storage_id => storage_id, :path => file_path_relative_to_storage_path, :state => 'CLOSED') raise "Error Creating File on Storage. Response: #{response}" unless file _response[:storage_file_create_response] = storage_file_create_response end # 4.2 Create a Placeholder logger.debug { 'Creating Placeholder.' } #placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1, :metadata_document => { :group => [ 'Film' ], :timespan => [ { :field => [ { :name => metadata_file_path_field_id, :value => [ { :value => vidispine_file_path } ] } ], :start => '-INF', :end => '+INF' } ] } } placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1, :metadata_document => { :timespan => [ { :start => '-INF', :end => '+INF' }.merge() ] } } item = placeholder = import_placeholder(placeholder_args) _response[:placeholder] = placeholder end _response[:item] = item item_id = item['id'] if [:add_item_to_collection] logger.debug { 'Determining Collection to Add the Item to.' } collection = determine_collection(args, ) _response[:collection] = collection collection_id = collection['id'] logger.debug { 'Adding Item to Collection.' } collection_object_add_response = collection_object_add(:collection_id => collection_id, :object_id => item_id) _response[:collection_object_add] = collection_object_add_response end # Item was already in the system so exit here return _response unless file file_id = file['id'] raise "File Id Not Found. #{file.inspect}" unless file_id # 6. Add the file as the original shape logger.debug { 'Adding the file as the Original Shape.' } item_shape_import_response = item_shape_import(:item_id => item_id, :file_id => file_id, :tag => 'original') _response[:item_shape_import] = item_shape_import_response job_id = item_shape_import_response['jobId'] job_monitor_response = wait_for_job_completion(:job_id => job_id) { |env| logger.debug { "Waiting for Item Shape Import Job to Complete. Time Elapsed: #{Time.now - env[:time_started]} seconds" } } last_response = job_monitor_response[:last_response] raise "Error Adding file As Original Shape. Response: #{last_response.inspect}" unless last_response['status'] == 'FINISHED' # 7. Generate the Transcode of the item transcode_tag = args[:transcode_tag] || 'lowres' logger.debug { 'Generating Transcode of the Item.' } item_transcode_response = item_transcode(:item_id => item_id, :tag => transcode_tag) _response[:item_transcode] = item_transcode_response # 8. Generate the Thumbnails and Poster Frame create_thumbnails = args.fetch(:create_thumbnails, true) create_posters = args[:create_posters] || 3 logger.debug { 'Generating Thumbnails(s) and Poster Frame.' } item_thumbnail_response = item_thumbnail(:item_id => item_id, :createThumbnails => create_thumbnails, :createPosters => create_posters) _response[:item_thumbnail] = item_thumbnail_response _response end |
#item_annotation_create(args = { }, options = { }) ⇒ Object
THIS IS A CANTEMO SPECIFIC CALL
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 |
# File 'lib/vidispine/api/utilities.rb', line 1241 def item_annotation_create(args = { }, = { }) # _args = args # item_id = _args[:item_id] # # in_point = _args[:in_point] # out_point = _args[:out_point] # title = _args[:title] # # body = { } # body[:title] = title if title # body[:inpoint] = in_point if in_point # body[:outpoint] = out_point if out_point # # http(:post, "v1/item/#{item_id}/annotation", :body => body) _request = Requests::BaseRequest.new( args, { :http_path => 'v1/item/#{arguments[:item_id]}/annotation', :http_method => :post, :default_parameter_send_in_value => :body, :parameters => [ { :name => :item_id, :aliases => [ :id ], :required => true, :send_in => :path }, :inpoint, :outpoint, { :name => :title, :default => '' }, ] }.merge() ) process_request(_request) end |
#item_annotation_get(args = { }, options = { }) ⇒ Object
THIS IS A CANTEMO SPECIFIC CALL
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 |
# File 'lib/vidispine/api/utilities.rb', line 1275 def item_annotation_get(args = { }, = { }) args = { :item_id => args } if args.is_a?(String) # item_id = args[:item_id] # http(:get, "v1/item/#{item_id}/annotation") _request = Requests::BaseRequest.new( args, { :http_path => 'v1/item/#{arguments[:item_id]}/annotation', :parameters => [ { :name => :item_id, :aliases => [ :id ], :required => true, :send_in => :path } ] }.merge() ) process_request(_request) end |
#item_create_with_proxy_using_file_uri(args = { }, options = { }) ⇒ Object
SEQUENCE THAT CREATE AN ITEM AND THE PROXY USING THE FILE URI/PATH
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 |
# File 'lib/vidispine/api/utilities.rb', line 1215 def item_create_with_proxy_using_file_uri(args = { }, = { }) original_file_uri = args[:original_file_uri] || args[:original] file_type = args[:file_type] || 'video' import_tag = args[:import_tag] || 'lowres' placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1 } storage_id = args[:storage_id] # /API/import/placeholder/?container=1&video=1 placeholder = import_placeholder(placeholder_args) placeholder_item_id = placeholder['id'] # /API/import/placeholder/VX-99/video/?uri=file%3A%2F%2F%2Fsrv%2Fmedia1%2Ftest_orginal2.mp4&tag=lowres item = import_placeholder_item(:item_id => placeholder_item_id, :type => file_type, :uri => original_file_uri, :tag => import_tag) item_id = item['file'].first['id'] # /API/item/VX-99/shape?tag=lowres&fileId=VX-136 #item_shape_import(:item_id => item_id, :tag => nil, :file_id => nil) # /API/storage/VX-2/file/?path=storages/test/test_orginal2.mp4 #storage_file_get(:storage_id => storage_id) end |
#item_create_with_proxy_using_storage_file_paths(args = { }, options = { }) ⇒ Hash
SEQUENCE THAT CREATES AN ITEM AND THE PROXY USING THE FILE ID
1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 |
# File 'lib/vidispine/api/utilities.rb', line 1161 def item_create_with_proxy_using_storage_file_paths(args = { }, = { }) original_file_path = args[:original_file_path] || args[:original] lowres_file_path = args[:lowres_file_path] || args[:lowres] placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1 } storage_id = args[:storage_id] create_posters = args[:create_posters] #|| '300@NTSC' create_thumbnails = args.fetch(:create_thumbnails, true) # Create a placeholder # /API/import/placeholder/?container=1&video=1 logger.debug { "Creating Placeholder: #{placeholder_args.inspect}" } place_holder = import_placeholder(placeholder_args) item_id = place_holder['id'] raise 'Placeholder Create Failed.' unless success? # /API/storage/VX-2/file/?path=storages/test/test_orginal2.mp4 _original_file = original_file = storage_file_get(:storage_id => storage_id, :path => original_file_path) raise "Unexpected Response Format. Expecting Hash instead of #{original_file.class.name} #{original_file}" unless _original_file.is_a?(Hash) original_file = original_file['file'] begin original_file = original_file.first rescue => e raise "Error Getting File from Response. #{$!}\n#{original_file.inspect}\n#{_original_file.inspect}" end raise "File Not Found. '#{original_file_path}' in storage '#{storage_id}'" unless original_file original_file_id = original_file['id'] # /API/item/VX-98/shape?tag=original&fileId=[FileIDofOriginal] item_shape_import(:item_id => item_id, :tag => 'original', :file_id => original_file_id) # /API/storage/VX-2/file/?path=storages/test/test_proxy2.mp4 lowres_file = storage_file_get(:storage_id => storage_id, :path => lowres_file_path) lowres_file_id = lowres_file['file'].first['id'] # /API/item/VX-98/shape?tag=lowres&fileId=[FileIDofProxy] item_shape_import(:item_id => item_id, :tag => 'lowres', :file_id => lowres_file_id) # /API/item/VX-98/thumbnail/?createThumbnails=true&createPoster item_thumbnail_args = { :item_id => item_id } item_thumbnail_args[:createThumbnails] = create_thumbnails item_thumbnail_args[:createPosters] = create_posters if create_posters item_thumbnail(item_thumbnail_args) { :item_id => item_id, :original_file_id => original_file_id, :lowres_file_id => lowres_file_id } end |
#item_export_extended(args = { }, options = { }) ⇒ Object
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 |
# File 'lib/vidispine/api/utilities.rb', line 857 def item_export_extended(args = { }, = { }) logger.debug { "#{__method__} Args: #{args.inspect} Opts: #{options.inspect}" } = .dup wait_for_job_completion = .delete(:wait_for_job_completion) { } item_export_response = item_export(args, ) if wait_for_job_completion job_id = item_export_response['jobId'] job_monitor_callback = [:job_monitor_callback_function] job_monitor_response = wait_for_job_completion(:job_id => job_id) do |env| logger.debug { "Waiting for '#{args.inspect}' Export Job to Complete. Time Elapsed: #{Time.now - env[:time_started]} seconds" } job_monitor_callback.call(env) if job_monitor_callback end last_response = job_monitor_response[:last_response] # if last_response['status'] == 'FINISHED' # data = last_response['data'] # data = Hash[ data.map { |d| [ d['key'], d['value'] ] } ] # end # if wait_for_transcode_job end last_response || item_export_response end |
#item_shape_add_using_file_path(args = { }, options = { }) ⇒ Object Also known as: item_add_shape_using_file_path
884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 |
# File 'lib/vidispine/api/utilities.rb', line 884 def item_shape_add_using_file_path(args = { }, = { }) logger.debug { "#{__method__}:#{args.inspect}" } _response = { } storage_path_map = args[:storage_path_map] item = args[:item] || { } item_id = args[:item_id] || item['id'] tag = args[:tag] file = args[:file] || { } file_id = args[:file_id] || file['id'] unless file_id storage = args[:storage] || { } storage_id = args[:storage_id] || storage['id'] file_path = args[:file_path] file_path_relative_to_storage_path = args[:relative_file_path] unless file_path_relative_to_storage_path if storage_id # Process file path using storage information else process_file_path_response = process_file_path_using_storage_map(file_path, storage_path_map) end file_path_relative_to_storage_path = process_file_path_response[:relative_file_path] storage_id ||= process_file_path_response[:storage_id] end file = storage_file_get_or_create(storage_id, file_path_relative_to_storage_path) file_id = file['id'] raise "File Error: #{file} Response: #{_response}" unless file_id end item_shape_import_args = { :item_id => item_id, :file_id => file_id, :tag => tag } item_shape_import(item_shape_import_args) end |
#item_shapes_get_extended(args = { }, options = { }) ⇒ Object
931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 |
# File 'lib/vidispine/api/utilities.rb', line 931 def item_shapes_get_extended(args = { }, = { }) item_id = args[:item_id] tag = args[:tag] return_as_hash = .fetch(:return_as_hash, false) if return_as_hash key_by_field = [:hash_key] || 'id' end shapes_response = item_shapes_get(:item_id => item_id, :tag => tag) shape_ids = shapes_response['uri'] || [ ] shapes = [ ] shape_ids.each do |shape_id| shape = item_shape_get(:item_id => item_id, :shape_id => shape_id) shape.dup.each do |k, v| shape[k] = v.first if v.is_a?(Array) and v.length == 1 and !['metadata'].include?(k) end shapes << shape end shapes_formatted = return_as_hash ? Hash[ shapes.map { |v| [ v[key_by_field], v ] } ] : shapes shapes_response['shapes'] = shapes_formatted shapes_response end |
#item_transcode_shape(args = { }, options = { }) ⇒ Object
961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 |
# File 'lib/vidispine/api/utilities.rb', line 961 def item_transcode_shape(args = { }, = { }) _response = { } item_id = args[:item_id] transcode_tag = args[:tag] || args[:transcode_tag] || 'lowres' skip_if_tag_exists = .fetch(:skip_if_shape_with_tag_exists, false) if skip_if_tag_exists item_shapes_response = item_shapes_get(:item_id => item_id, :tag => transcode_tag) shape_ids = item_shapes_response['uri'] || [ ] proxy_shape_id = shape_ids.last _response[:tag_existed_on_shape] = !!proxy_shape_id end unless proxy_shape_id logger.debug { "Generating Transcode of the Item. Tag: '#{transcode_tag}'" } item_transcode_response = item_transcode(:item_id => item_id, :tag => transcode_tag) _response[:item_transcode] = item_transcode_response job_id = item_transcode_response['jobId'] _response[:job_id] = job_id if [:wait_for_transcode_job] job_monitor_callback = [:job_monitor_callback_function] job_monitor_response = wait_for_job_completion(:job_id => job_id) do |env| logger.debug { "Waiting for '#{transcode_tag}' Transcode Job to Complete. Time Elapsed: #{Time.now - env[:time_started]} seconds" } job_monitor_callback.call(env) if job_monitor_callback end last_response = job_monitor_response[:last_response] if last_response['status'] == 'FINISHED' data = last_response['data'] data = Hash[ data.map { |d| [ d['key'], d['value'] ] } ] proxy_shape_ids = data['shapeIds'] proxy_shape_id = proxy_shape_ids end # if wait_for_transcode_job end end if proxy_shape_id item_shape_files = item_shape_files_get(:item_id => item_id, :shape_id => proxy_shape_id) proxy_file = (((item_shape_files || { })['file'] || [ ]).first || { }) proxy_file_uri = (proxy_file['uri'] || [ ]).first _response[:file] = proxy_file _response[:shape_id] = proxy_shape_id _response[:file_uri] = proxy_file_uri _response[:file_path] = URI.decode(URI(proxy_file_uri).path) end _response end |
#items_search_extended(args = { }, options = { }) ⇒ Object Also known as: item_search_extended
1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 |
# File 'lib/vidispine/api/utilities.rb', line 1292 def items_search_extended(args = { }, = { }) _args = symbolize_keys(args, false) _data = Requests::BaseRequest.process_parameters([ { :name => :fields }, { :name => :item_search_document } ], _args) _args = _args.merge(_data[:arguments_out]) fields = _args.delete(:fields) _args[:item_search_document] ||= build_item_search_document(:fields => fields) items_search(_args, ) end |
#process_file_path_using_storage_map(file_path, storage_path_map = nil) ⇒ Hash
Will process a file path through a storage path map
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 |
# File 'lib/vidispine/api/utilities.rb', line 1308 def process_file_path_using_storage_map(file_path, storage_path_map = nil) logger.debug { "Method: #{__method__} Args: #{{:file_path => file_path, :storage_path_map => storage_path_map}.inspect}"} storage_path_map = storage_file_path_map_create unless storage_path_map and !storage_path_map.empty? volume_path, storage_id = storage_path_map.find { |path, _| file_path.start_with?(path) } file_path_relative_to_storage_path = file_path.sub(volume_path, '') _response = { :relative_file_path => file_path_relative_to_storage_path, :storage_id => storage_id, :storage_path_map => storage_path_map, :volume_path => volume_path } logger.debug { "Method: #{__method__} Response: #{_response.inspect}" } _response end |
#storage_file_copy_extended(args = { }, options = { }) ⇒ Object
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 |
# File 'lib/vidispine/api/utilities.rb', line 1326 def storage_file_copy_extended(args = { }, = { }) _args = symbolize_keys(args, false) _data = Requests::BaseRequest.process_parameters([ { :name => :use_source_filename }, { :name => :file_id }, { :name => :filename }, { :name => :source_storage_id } ], _args) _args = _args.merge(_data[:arguments_out]) # Get the source file name and set it as the destination file name if [:use_source_filename] file_id = _args[:file_id] source_storage_id = _args[:source_storage_id] file = storage_file_get(:storage_id => source_storage_id, :file_id => file_id) args[:filename] = file[:filename] end storage_file_copy(args, ) end |
#storage_file_create_extended(args = { }, options = { }) ⇒ Object
1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 |
# File 'lib/vidispine/api/utilities.rb', line 1342 def storage_file_create_extended(args = { }, = { }) _args = symbolize_keys(args, false) _params = Requests::StorageFileCreate::PARAMETERS.concat [ { :name => :directory, :aliases => [ :dir ], :send_in => :none }, { :name => :storage_map, :send_in => :none } ] _data = Requests::BaseRequest.process_parameters(_params, _args) _args = _args.merge(_data[:arguments_out]) storage_path_map = _args.delete(:storage_map) { } if storage_path_map.empty? storage_path_map = storage_file_path_map_create else storage_path_map = Hash[storage_path_map.map { |k,v| [k.to_s, v] }] if storage_path_map.is_a?(Hash) end dir = _args.delete(:directory) { } if dir # raise ArgumentError, ':storage_map is a required argument.' unless storage_path_map volume_path, storage = storage_path_map.find { |path, _| dir.start_with?(path) } raise "Unable to find match in storage path map for '#{dir}'. Storage Map: #{storage_path_map.inspect}" unless volume_path dir_path_relative_to_storage = dir.sub(volume_path, '') storage = storage_get(:id => storage) if storage.is_a?(String) raise 'Error Retrieving Storage Record' unless storage storage_id = storage['id'] _args[:storage_id] = storage_id storage_uri_raw = storage['method'].first['uri'] storage_uri = URI.parse(storage_uri_raw) vidispine_dir_path = File.join(storage_uri.path, dir_path_relative_to_storage) logger.debug { "Vidispine Dir Path: '#{vidispine_dir_path}'" } glob_path = dir.end_with?('*') ? vidispine_dir_path : File.join(vidispine_dir_path, '*') paths = Dir.glob(glob_path) return paths.map do |local_absolute_path| logger.debug { "Found Path: '#{local_absolute_path}'" } _path = local_absolute_path file_path_relative_to_storage_path = _path.sub(volume_path, '') logger.debug { "File Path Relative to Storage Path: #{file_path_relative_to_storage_path}" } _args[:path] = file_path_relative_to_storage_path storage_file_create(_args, ) end end storage_file_create(_args, ) end |
#storage_file_get_or_create(storage_id, file_path_relative_to_storage_path, options = { }) ⇒ Hash
Will search for a relative file path on a storage and if not found will trigger a storage_file_create
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 |
# File 'lib/vidispine/api/utilities.rb', line 1479 def storage_file_get_or_create(storage_id, file_path_relative_to_storage_path, = { }) logger.debug { "Method: #{__method__} Args:#{{:storage_id => storage_id, :file_path_relative_to_storage_path => file_path_relative_to_storage_path, :options => options }.inspect}" } include_item = .fetch(:include_item, true) creation_state = [:creation_state] || 'CLOSED' storage_file_get_response = storage_files_get(:storage_id => storage_id, :path => file_path_relative_to_storage_path, :include_item => include_item) || { 'file' => [ ] } file = ((storage_file_get_response || { })['file'] || [ ]).first if file file_already_existed = true else file_already_existed = false # 4.1.1 Create the storage file record if it does not exist storage_file_create_response = file = storage_file_create(:storage_id => storage_id, :path => file_path_relative_to_storage_path, :state => creation_state) if (file || { })['fileAlreadyExists'] file_already_existed = true = file['fileAlreadyExists'] logger.warn { "Running Recreation of Existing File Work Around: #{_message}" } storage_file_get_response = file = storage_file_get(:storage_id => storage_id, :file_id => ['fileId'], :include_item => include_item) end raise "Error Creating File on Storage. Response: #{response.inspect}" unless (file || { })['id'] end logger.debug { "Method: #{__method__} Response: #{file.inspect}" } if [:extended_response] return { :file => file, :file_already_existed => file_already_existed, :storage_file_get_response => storage_file_get_response, :storage_file_create_response => storage_file_create_response } end file end |
#storage_file_get_using_file_path(args = { }) ⇒ Hash|nil
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 |
# File 'lib/vidispine/api/utilities.rb', line 1401 def storage_file_get_using_file_path(args = { }) _response = { } file_path = args[:file_path] return_extended_response = args.fetch(:extended_response, true) volume_path = args[:volume_path] # The method type of the URI to lookup storage_method_type = (args[:storage_method_type] ||= 'file').to_s.downcase logger.debug { "Storage Method Type: '#{storage_method_type}'" } storage_path_map = args[:storage_path_map] storage_path_map = storage_file_path_map_create(:storage_method => storage_method_type) unless storage_path_map && !storage_path_map.empty? logger.debug { "Storage Path Map: #{storage_path_map.inspect}" } sm_volume_path, storage = storage_path_map.find { |path, _| file_path.start_with?(path) } raise "Unable to find match in storage path map for '#{file_path}'. Storage Map: #{storage_path_map.inspect}" unless sm_volume_path storage = storage_get(:id => storage) if storage.is_a?(String) _response[:storage] = storage storage_id = storage['id'] raise "Error Retrieving Storage Record. Storage: #{storage}" unless storage_id logger.debug { "Storage ID: #{storage_id}" } ## Storage Determined Now Start Digging for the File case storage_method_type when 'file', 'http', 's3' storage_uri_method = "#{storage_method_type}:" storage_uri_raw = (storage['method'].find do |v| ((v['lastSuccess'] || '') >= (v['lastFailure'] || '')) && (storage_method_type == 'any' || v['uri'].start_with?(storage_uri_method)) end || { })['uri'] rescue nil raise "Error Getting URI from Storage Method. Storage: #{storage.inspect}" unless storage_uri_raw if storage_method_type == 's3' # URI was returning URI::InvalidURIError: the scheme s3 does not accept registry part volume_path = storage_uri_raw.split('@').last.sub('s3://', '').split('?').first else storage_uri = URI.parse(storage_uri_raw) volume_path = storage_uri.path end when 'vxa' vxa_local_path = storage['metadata']['field'].find { |m| m['key'] == 'vxaLocalPath' }['value'] volume_path = vxa_local_path else volume_path = sm_volume_path end unless volume_path logger.debug { "Volume Path: '#{volume_path}'" } file_path_relative_to_storage_path = file_path.sub(volume_path, '') logger.debug { "File Path Relative to Storage Path: '#{file_path_relative_to_storage_path}'" } vidispine_file_path = File.join(volume_path, file_path_relative_to_storage_path) logger.debug { "Vidispine File Path: '#{vidispine_file_path}'" } create_if_not_exists = args.fetch(:create_if_not_exists, true) include_item = args.fetch(:include_item, true) = { :include_item => include_item } if create_if_not_exists storage_file_get_or_create_response = storage_file_get_or_create(storage_id, file_path_relative_to_storage_path, .merge(:extended_response => true)) _response[:storage_file_get_or_create_response] = storage_file_get_or_create_response file = storage_file_get_or_create_response[:file] else storage_file_get_response = storage_files_get({ :storage_id => storage_id, :path => file_path_relative_to_storage_path }.merge()) || { 'file' => [ ] } file = ((storage_file_get_response || { })['file'] || [ ]).first end _response[:file] = file return_extended_response ? _response : file end |
#storage_file_path_map_create(args = {}) ⇒ Hash
Generates a storage file path map from the current storages. This is meant as a default, on most methods you can provide your own storage map that can be used to resolve local paths to storage paths.
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 |
# File 'lib/vidispine/api/utilities.rb', line 1523 def storage_file_path_map_create(args = {}) method = args[:storage_method] || 'file' storages = args[:storages] || begin storages_response = args[:storages_response] || storages_get storages_response['storage'] end storage_file_path_map = { } storages.each do |storage| storage_methods = storage['method'] file_storage_method = storage_methods.find { |m| m['uri'].start_with?("#{method}:") } next unless file_storage_method case method when 'vxa' md = Hash[ storage['metadata']['field'].map { |m| [ m['key'], m['value'] ] } ] address = md['vxaLocalPath'] address.concat('/') if address && !(address.empty? || address.end_with?('/')) when 's3' # "s3://{access_key}:_VSENC__{encrypted_secret_access_key}@{bucket_name}/?region=us-east-1?sseAlgorithm=aws:kms?signer=AWSS3V4SignerType/" uri = file_storage_method['uri'] user_info, bucket_info = uri.split('@') address, args = bucket_info.split('?').first address.chomp!('/') if address.end_with?('/') else uri = file_storage_method['uri'] match = uri.match(/(.*):\/\/(.*)/) address = match[2] end storage_file_path_map[address] = storage['id'] end storage_file_path_map end |
#symbolize_keys(value, recursive = true) ⇒ Object
Converts hash keys to symbols
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/vidispine/api/utilities.rb', line 25 def symbolize_keys (value, recursive = true) case value when Hash new_val = {} value.each { |k,v| k = (k.to_sym rescue k) v = symbolize_keys(v, true) if recursive and (v.is_a? Hash or v.is_a? Array) new_val[k] = v } return new_val when Array return value.map { |v| symbolize_keys(v, true) } else return value end end |
#transform_metadata_get_response_to_hash(_response, options = { }) ⇒ Object
246 247 248 |
# File 'lib/vidispine/api/utilities.rb', line 246 def (_response, = { }) self.class.(_response, ) end |
#transform_metadata_to_fields(metadata_in, map = { }, options = { }) ⇒ Object
Transforms metadata from key value to MetadataDocument field and group sequences { k1 => v1, k2 => v2 } becomes
{
:field => [
{ :name => map[k1][:field], :value => [ { :value => v1 } ] },
{ :name => map[k2][:field], :value => [ { :value => v2 } ] }
],
:group => [ ]
}
Metadata Map Example metadata_map = {
'Campaign Title' => { :group => 'Film', :field => 'portal_mf409876' },
'Client' => { :group => 'Editorial and Film', :field => 'portal_mf982459' },
'Product' => { :group => 'Film', :field => 'portal_mf264604' },
'Studio Tracking ID' => { :group => 'Film', :field => 'portal_mf846239' },
#'File Path' => { :field => 'portal_mf48881', :group => 'Film' }
#'File Path' => { :field => 'portal_mf48881' }
'File Path' => 'portal_mf48881'
}
metadata group name { ‘Some Field’ => { :field => ‘properFieldName’, :group => ‘groupName’ } }
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/vidispine/api/utilities.rb', line 159 def (, map = { }, = { }) map = ([:default_metadata_map] || ).merge(map.merge([:metadata_map] || { })) groups = { } .each do |k,v| _map = map[k] next unless _map [*_map].each do |_map_| _map_ = { :field => _map_ } if _map_.is_a?(String) (groups[_map_[:group]] ||= { })[_map_[:field]] = v end end _field = groups.delete(nil) { { } }.map { |fname, values| { :name => fname, :value => [*values].map { |v| { :value => v } } } } _group = groups.map { |name, fields| { :name => name, :field => fields.map { |fname, values| { :name => fname, :value => [*values].map { |v| { :value => v } } } } } } # metadata_out = { } # metadata_out[:field] = _field unless _field.empty? # metadata_out[:group] = _group unless _group.empty? # metadata_out { :field => _field, :group => _group } end |
#wait_for_job_completion(args = { }) ⇒ Hash
Waits for a job to complete
Accepts a block where the following is exposed:
:time_started [TIme]
:poll_interval [Integer]
:latest_response [Hash]
:job_status [String]
:continue_monitoring [Boolean] Can be set to false and job monitoring will exit
:delay [Integer]
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 |
# File 'lib/vidispine/api/utilities.rb', line 1577 def wait_for_job_completion(args = { }) job_id = args[:job_id] raise ArgumentError, 'job_id is a required argument.' unless job_id delay = args[:delay] || 15 timeout = args[:timeout] time_started = Time.now _response = { } continue_monitoring = true timed_out = false loop do _response = job_get(:job_id => job_id) break unless _response job_status = _response['status'] break if %w(FAILED_TOTAL FINISHED FINISHED_WARNING FINISHED_TOTAL ABORTED).include?(job_status) break if timeout and (timed_out = ((Time.now - time_started) > timeout)) if block_given? yield_out = { :time_started => time_started, :poll_interval => delay, :latest_response => _response, :job_status => job_status, :continue_monitoring => continue_monitoring, :delay => delay } yield yield_out break unless continue_monitoring else logger.debug { "Waiting for job completion. Job: #{job_status} Poll Interval: #{delay}" } end sleep(delay) end time_ended = Time.now { :last_response => _response, :time_started => time_started, :time_ended => time_ended, :timed_out => timed_out } end |