class Envoi::Mam::Vidispine::Agent
Constants
- DEFAULT_ASPERA_ARGS
- DEFAULT_DESTINATION_PATH
- DEFAULT_SHAPE_TAG
Attributes
default_aspera_ascp_args[RW]
default_aspera_ascp_path[RW]
default_vidispine_shape_tag[RW]
Public Instance Methods
after_initialize()
click to toggle source
# File lib/envoi/mam/vidispine/agent.rb, line 22 def after_initialize args = initial_args @default_aspera_ascp_path = args[:default_aspera_ascp_path] @default_aspera_args = args[:default_ascp_args] || DEFAULT_ASPERA_ARGS end
download(args = { })
click to toggle source
# File lib/envoi/mam/vidispine/agent.rb, line 62 def download(args = { }) item_id = args[:item_id] shape_id = args[:shape_id] unless shape_id && !shape_id.empty? shape_tag = args[:shape_tag] || default_vidispine_shape_tag shape_id = item_get_shape_by_tag(item_id, shape_tag) end logger.info { "Getting file path for Item ID: #{item_id} Shape ID: #{shape_id}"} item_shape_get_response = api_client.item_shape_get(:item_id => item_id, :shape_id => shape_id) files = item_shape_get_response['containerComponent']['file'] logger.debug { "Files: #{files}"} # file = files.first files = [ files.first ] # just do the first file for now files.each do |file| begin download_file(args, file) rescue => e logger.warn { "Exception: #{$!}" } end end logger.info { 'DONE' } end
download_file(args, file)
click to toggle source
# File lib/envoi/mam/vidispine/agent.rb, line 89 def download_file(args, file) logger.debug { "File: #{file}"} transfer_type = args[:transfer_type] file_storage_id = file['storage'] file_path = file['path'] file_storage_config = vidispine_config['storages'][file_storage_id] unless file_storage_config && !file_storage_config.empty? raise Exception, "No configuration found for storage '#{file_storage_id}'" end logger.info { "Transferring File Path: '#{file_path}'" } preserve_path = args.fetch(:preserve_path, file_storage_config.fetch('preserve_path', true)) destination_path = args[:destination_path] || file_storage_config['destination_path'] || DEFAULT_DESTINATION_PATH relative_path = preserve_path ? File.dirname(file_path) : nil relative_path = nil if relative_path == '.' target_path = relative_path ? File.join(destination_path, relative_path) : destination_path target_path = target_path[0..-1] if target_path.start_with?('/') && !destination_path.start_with?('/') aspera_config = file_storage_config['aspera'] if (transfer_type.empty? || transfer_type == :aspera) && (aspera_config && !aspera_config.empty?) client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self) return client.download(aspera_config, file_path, target_path) # download_using_aspera(aspera_config, file_path, target_path) end s3_config = file_storage_config['s3'] if (transfer_type.empty? || transfer_type == :s3) && (s3_config && !s3_config.empty?) target_path = File.expand_path(target_path) if target_path == '.' target_path = File.join(target_path, File.basename(file_path)) client = Envoi::Mam::Agent::TransferClient::S3.new(agent: self) return client.download(s3_config, file_path, target_path) end logger.warn { "No Supported TransferClient Configuration#{transfer_type && !transfer_type.empty? ? " for transfer type '#{transfer_type}' " : ''}Found in Storage Configuration." } end
dry_run?()
click to toggle source
# File lib/envoi/mam/vidispine/agent.rb, line 28 def dry_run?; @dry_run end
initialize_api_client(args = { })
click to toggle source
# File lib/envoi/mam/vidispine/agent.rb, line 34 def initialize_api_client(args = { }) _vidispine_config = vidispine_config @api_client = args[:vidispine_api_client] || begin vidispine_host = _vidispine_config['host'] vidispine_port = _vidispine_config['port'] vidispine_host_use_ssl = _vidispine_config['use_ssl'] vidispine_username = _vidispine_config['username'] vidispine_password = _vidispine_config['password'] client_args = { } client_args[:http_host_address] = vidispine_host if vidispine_host client_args[:http_host_port] = vidispine_port if vidispine_port client_args[:http_host_use_ssl] = vidispine_host_use_ssl if vidispine_host_use_ssl client_args[:username] = vidispine_username if vidispine_username client_args[:password] = vidispine_password if vidispine_password ::Vidispine::API::Utilities.new(client_args) end @default_vidispine_original_shape_tag = args[:default_shape_tag] || _vidispine_config['default_shape_tag'] || _vidispine_config['shape_tag'] || DEFAULT_SHAPE_TAG end
item_get_shape_by_tag(item_id, shape_tag)
click to toggle source
# File lib/envoi/mam/vidispine/agent.rb, line 57 def item_get_shape_by_tag(item_id, shape_tag) item_shapes_get_response = api_client.item_shapes_get(:item_id => item_id, :tag => shape_tag) shape_id = item_shapes_get_response['uri'].first end
upload(args = { })
click to toggle source
# File lib/envoi/mam/vidispine/agent.rb, line 130 def upload(args = { }) file_path = args[:file_path] raise ArgumentError, "Path not found: '#{file_path}'" unless File.exists?(file_path) if File.directory?(file_path) # Non-recursive directory upload file_paths = Dir.glob(File.join(file_path, '*.*')) logger.debug { "File Paths: #{file_paths}"} file_paths.map { |fp| upload(args.merge(file_path: fp))} return file_paths end logger.debug { "Preparing to upload '#{file_path}'" } transfer_type = args[:transfer_type] || '' storage_id = args[:storage_id] vidispine_storage_config = vidispine_config['storages'][storage_id] unless vidispine_storage_config && !vidispine_storage_config.empty? raise "No configuration found for storage '#{storage_id}'" end should_import_file = args.fetch(:import_file, vidispine_storage_config.fetch('import', true)) should_preserve_path = args.fetch(:preserve_path, vidispine_storage_config.fetch('preserve_path', true)) destination_path = args[:destination_path] || vidispine_storage_config['destination_path'] || '/' relative_path = should_preserve_path ? File.dirname(file_path) : nil relative_path = File.expand_path(relative_path) if relative_path == '.' target_path = relative_path ? File.join(destination_path, relative_path) : destination_path target_path = target_path[0..-1] if target_path.start_with?('/') && !destination_path.start_with?('/') # upload file transfer_response = begin aspera_config = vidispine_storage_config['aspera'] if (transfer_type.empty? || transfer_type == :aspera) && (aspera_config && !aspera_config.empty?) client = Envoi::Mam::Agent::TransferClient::Aspera.new(agent: self) response = client.upload(aspera_config, file_path, target_path) end s3_config = vidispine_storage_config['s3'] if !response && (transfer_type.empty? || transfer_type == :s3) && (s3_config && !s3_config.empty?) _target_path = target_path _target_path = File.expand_path(_target_path) if target_path == '.' _target_path = File.join(_target_path, File.basename(file_path)) client = Envoi::Mam::Agent::TransferClient::S3.new(agent: self) response = client.upload(s3_config, file_path, _target_path) end response end logger.warn { "No supported TransferClient configuration#{transfer_type && !transfer_type.empty? ? " for transfer type '#{transfer_type}' " : ''}found in storage configuration." } unless transfer_response != nil _response = { transfer_response: transfer_response } return _response unless should_import_file item_id = args[:item_id] shape_tag = args[:shape_tag] || default_vidispine_shape_tag # attach file to item as shape path_on_storage = File.join(target_path, File.basename(file_path)) file_create_response = api_client.storage_file_create storage_id: storage_id, path: path_on_storage, state: 'CLOSED' file_id = file_create_response['id'] if item_id item_shape_import_response = vs_api.item_shape_import item_id: item_id, tag: shape_tag, fileId: file_id else item_shape_import_response = vs_api.item_add_using_file_path storage_id: storage_id, file_path: file_path, file_id: file_id, storage_path_map: { '/' => storage_id } end _response[:import_response] = item_shape_import_response _response end
vidispine_config()
click to toggle source
# File lib/envoi/mam/vidispine/agent.rb, line 30 def vidispine_config config['vidispine'] || { } end