vidispine 1.5.5 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 787d02467c745b817b16e3c82b6b883e09dc28ce
4
- data.tar.gz: 0df35672bacdb4945b455dc31d7a3363c091d6fb
3
+ metadata.gz: 42f586329307e5534298c0619169e8d2b2a5f78d
4
+ data.tar.gz: ecc3b8ba4c3472090ff6c45f48a263e624e95b9b
5
5
  SHA512:
6
- metadata.gz: f281423491d31ca84a0583ea310fe786038fa8a2adc8e2aba3cf69744fa155e140014a00b76bd50af5e5e9c9fa134c4dd394683bb88254925d5f8650a26ae75e
7
- data.tar.gz: 2b5d4a7827796d1a9cb7dbefdf8937de48dc6f3148407734dde6a81780fec95a2ecead0cb69a15fe486259fffefc92431fe4e6b213f059ebf703d336a27827b4
6
+ metadata.gz: f6dd1740b880a7730fe6786aa8cc30891b79a0cf641671f8a10f76472dae73c16fda520ba77df3aaf1eb68f9504b588ff76383288bb7800ffc3c4ce3921273ba
7
+ data.tar.gz: 4fe948a108b5ce5d23150bb2b2d3d5facaa8403066b4f5712b0b90f924d4231f1e7edc40b24ea8cc082b2f9e4f608a65b6a9e0c410a9a43e3134b821b203e271
@@ -45,22 +45,21 @@ module Vidispine
45
45
 
46
46
  @default_query_data = args[:default_query_data] || { }
47
47
 
48
- # @user_agent_default = "#{@hostname}:#{@username} Ruby SDK Version #{Vidispine::VERSION}"
49
-
50
48
  @username = args[:username] || DEFAULT_USERNAME
51
49
  @password = args[:password] || DEFAULT_PASSWORD
52
50
 
53
51
  @authorization_header_key = args.fetch(:authorization_header_key, 'Authorization')
54
52
  @authorization_header_value = args.fetch(:authorization_header_value, %(Basic #{["#{username}:#{password}"].pack('m').delete("\r\n")}))
55
53
 
56
- content_type = args[:content_type_header] ||= DEFAULT_HEADER_CONTENT_TYPE
57
- accepts = args[:accepts_header] ||= args[:accept_header] || DEFAULT_HEADER_ACCEPTS
54
+ user_agent = args.fetch(:user_agent, false)
55
+ content_type = args.fetch(:content_type_header, DEFAULT_HEADER_CONTENT_TYPE)
56
+ accept_header = args.fetch(:accept_header, args.fetch(:accepts_header, DEFAULT_HEADER_ACCEPTS))
58
57
 
59
- @default_request_headers = {
60
- 'Content-Type' => content_type,
61
- 'Accept' => accepts,
62
- authorization_header_key => authorization_header_value,
63
- }
58
+ @default_request_headers = { }
59
+ @default_request_headers['Content-Type'] = content_type if content_type
60
+ @default_request_headers['Accept'] = accept_header if accept_header
61
+ @default_request_headers[@authorization_header_key] = @authorization_header_value if @authorization_header_key
62
+ @default_request_headers['User-Agent'] = user_agent if user_agent
64
63
 
65
64
  @log_request_body = args.fetch(:log_request_body, true)
66
65
  @log_response_body = args.fetch(:log_response_body, true)
@@ -93,6 +92,18 @@ module Vidispine
93
92
  http
94
93
  end
95
94
 
95
+ def user_agent=(value)
96
+ if (value)
97
+ default_request_headers['User-Agent'] = value
98
+ else
99
+ default_request_headers.delete('User-Agent')
100
+ end
101
+ end
102
+
103
+ def user_agent
104
+ default_request_headers['User-Agent']
105
+ end
106
+
96
107
  # Formats a HTTPRequest or HTTPResponse body for log output.
97
108
  # @param [HTTPRequest|HTTPResponse] obj
98
109
  # @return [String]
@@ -137,7 +148,7 @@ module Vidispine
137
148
  case response.content_type
138
149
  when 'application/json'
139
150
  response_body.empty? ? response_body : JSON.parse(response_body) # rescue response
140
- else
151
+ else
141
152
  response_body
142
153
  end
143
154
  end
@@ -1,5 +1,5 @@
1
1
  require 'logger'
2
-
2
+ require 'vidispine/version'
3
3
  require 'vidispine/api/client/http_client'
4
4
  require 'vidispine/api/client/requests'
5
5
 
@@ -19,6 +19,7 @@ module Vidispine
19
19
  # APInoAuth Path
20
20
  @api_noauth_endpoint_prefix = args.fetch(:api_noauth_endpoint_prefix, 'APInoauth')
21
21
 
22
+ args.fetch(:user_agent, "Vidispine Ruby SDK v#{Vidispine::VERSION}")
22
23
  @http_client = HTTPClient.new(args)
23
24
  @logger = http_client.logger
24
25
  end
@@ -41,14 +41,24 @@ module Vidispine
41
41
 
42
42
  # Tries to find a collection using either the collection id, name, or a file path with a collection name position.
43
43
  # For use in other methods that need to perform the same type of lookup
44
- # @param [Hash] :collection
45
- # @param [String] :collection_id
46
- # @param [String] :collection_name
44
+ # @args [Hash]
45
+ # @option args [Hash] :collection
46
+ # @option args [String] :collection_id
47
+ # @option args [String] :collection_name
48
+ # @option args [Array] :collections (nil) If not nil then the each element will be run through
49
+ # determine_collection and the array returned
50
+ # @option args [String] :file_path Used when :file_path_collection_name_position is set
51
+ # @option args [Integer] :file_path_collection_name_position Will split the file path and be used as the index
52
+ # for the collection name location
53
+ #
47
54
  def determine_collection(args, options = { })
55
+ collections = args[:collections]
56
+ return collections.map { |v| determine_collection(v, options) } if collections.is_a?(Array)
57
+
48
58
  collection = args[:collection] || { }
49
59
 
50
60
  # 3 Get Collection
51
- collection_id = args[:collection_id] || collection['id']
61
+ collection_id = args[:collection_id] || collection[:id] || collection['id']
52
62
  unless collection_id
53
63
  collection_name = args[:collection_name] || args[:name]
54
64
  unless collection_name
@@ -541,6 +551,7 @@ module Vidispine
541
551
  #
542
552
  # @param [Hash] options
543
553
  # @option options [Boolean] :add_item_to_collection
554
+ # @option options [Boolean] :wait_for_import_job (true)
544
555
  # @option options [Boolean] :wait_for_transcode_job (false)
545
556
  # @option options [Boolean] :skip_transcode_if_shape_with_tag_exists (true)
546
557
  # @option options [Boolean] :use_placeholder_import (true)
@@ -605,7 +616,9 @@ module Vidispine
605
616
 
606
617
  # Allow the file to be passed in
607
618
  file = args[:file]
608
- unless file
619
+ if file
620
+ file_id = file['id']
621
+ else
609
622
  file_id = args[:file_id]
610
623
  file = { 'id' => file_id }
611
624
  end
@@ -617,6 +630,8 @@ module Vidispine
617
630
  raise "Error Getting Storage File. '#{storage_file_get_response.inspect}'" unless storage_file_get_response and storage_file_get_response['id']
618
631
  _response[:storage_file_get_response] = storage_file_get_response
619
632
 
633
+ file_found = true
634
+
620
635
  file = storage_file_get_response
621
636
  else
622
637
  storage_file_get_or_create_response = storage_file_get_or_create(storage_id, file_path_relative_to_storage_path, :extended_response => true)
@@ -627,27 +642,23 @@ module Vidispine
627
642
 
628
643
  if file
629
644
  _response[:item] = item = file['item']
630
- file_found = true
631
645
  end
632
646
 
633
647
  _response[:file_already_existed] = file_found
634
648
  _response[:item_already_existed] = !!item
635
- return _response if item
649
+ return _response if item # We already have an item so nothing to do
636
650
 
637
- file_id = file['id']
651
+ file_id ||= file['id']
638
652
 
639
- unless item
640
- # 4.2 Create a Placeholder
641
- logger.debug { 'Creating Placeholder.' }
642
- #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' } ] } }
643
- #placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1, :metadata_document => { :timespan => [ { :start => '-INF', :end => '+INF' }.merge(_metadata_as_fields) ] } }
644
- #placeholder_args = args[:placeholder_args] ||= { :container => 1, :metadata_document => { :timespan => [ { :start => '-INF', :end => '+INF' }.merge(_metadata_as_fields) ] } }
645
- placeholder_args = args[:placeholder_args] ||= { :container => 1, :metadata_document => metadata_document }
646
- _response[:item] = item = import_placeholder(placeholder_args)
647
- end
648
- item_id = item['id']
649
- shape = item['shape']
653
+ # 4.2 Create a Placeholder
654
+ logger.debug { 'Creating Placeholder.' }
655
+ #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' } ] } }
656
+ #placeholder_args = args[:placeholder_args] ||= { :container => 1, :video => 1, :metadata_document => { :timespan => [ { :start => '-INF', :end => '+INF' }.merge(_metadata_as_fields) ] } }
657
+ #placeholder_args = args[:placeholder_args] ||= { :container => 1, :metadata_document => { :timespan => [ { :start => '-INF', :end => '+INF' }.merge(_metadata_as_fields) ] } }
658
+ placeholder_args = args[:placeholder_args] ||= { :container => 1, :metadata_document => metadata_document }
659
+ _response[:item] = item = import_placeholder(placeholder_args)
650
660
 
661
+ item_id = item['id']
651
662
  raise "Error Creating Placeholder: #{item.inspect}" unless item_id
652
663
 
653
664
  # Add any additional metadata (Vidispine will only take one group at a time)
@@ -657,18 +668,26 @@ module Vidispine
657
668
 
658
669
  if options[:add_item_to_collection]
659
670
  logger.debug { 'Determining Collection to Add the Item to.' }
660
- collection = determine_collection(args, options)
661
- _response[:collection] = collection
662
- collection_id = collection['id']
671
+ collections = determine_collection(args, options)
672
+ if collections.is_a?(Array)
673
+ single_collection = false
674
+ _response[:collections] = collections
675
+ else
676
+ single_collection = true
677
+ _response[:collection] = collections
678
+ collections = [ collections ]
679
+ end
680
+ collection_object_add_responses = collections.map do |collection|
681
+ collection_id = collection['id']
682
+ logger.debug { 'Adding Item to Collection.' }
683
+ collection_object_add(:collection_id => collection_id, :object_id => item_id)
684
+ end
663
685
 
664
- logger.debug { 'Adding Item to Collection.' }
665
- collection_object_add_response = collection_object_add(:collection_id => collection_id, :object_id => item_id)
666
- _response[:collection_object_add] = collection_object_add_response
686
+ _response[:collection_object_add] = single_collection ? collection_object_add_responses.first : collection_object_add_responses
667
687
  end
668
688
 
669
- create_thumbnails = args.fetch(:create_thumbnails, true)
670
- create_posters = args.fetch(:create_posters, 3)
671
689
 
690
+ shape = item['shape']
672
691
  unless shape
673
692
  import_args_in = args[:import_args]
674
693
 
@@ -697,15 +716,22 @@ module Vidispine
697
716
  end
698
717
  raise "Error Creating Item Shape Import Job. Response: #{item_shape_import_response.inspect}" unless job_id
699
718
 
700
- job_monitor_response = wait_for_job_completion(:job_id => job_id) { |env|
701
- logger.debug { "Waiting for Item Shape Import Job to Complete. Time Elapsed: #{Time.now - env[:time_started]} seconds" }
702
- }
703
- last_response = job_monitor_response[:last_response]
704
- raise "Error Adding file As Original Shape. Response: #{last_response.inspect}" unless last_response['status'] == 'FINISHED'
705
719
 
706
720
  # 7. Generate the Transcode of the item
707
721
  transcode_tag = args.fetch(:transcode_tag, 'lowres')
708
- if transcode_tag and !transcode_tag.empty? and transcode_tag.to_s.downcase != 'false'
722
+ should_transcode = transcode_tag and !transcode_tag.empty? and transcode_tag.to_s.downcase != 'false'
723
+
724
+ should_wait_for_import_job_completion = should_transcode || options.fetch(:wait_for_import_job, true)
725
+ if should_wait_for_import_job_completion
726
+ job_monitor_response = wait_for_job_completion(:job_id => job_id) { |env|
727
+ logger.debug { "Waiting for Item Shape Import Job to Complete. Time Elapsed: #{Time.now - env[:time_started]} seconds" }
728
+ }
729
+ last_response = job_monitor_response[:last_response]
730
+ _response[:item_shape_import_job_result] = last_response
731
+ raise "Error Importing File. Response: #{last_response.inspect}" unless last_response['status'] == 'FINISHED'
732
+ end
733
+
734
+ if should_transcode
709
735
  wait_for_transcode_job = options[:wait_for_transcode_job]
710
736
  skip_transcode_if_shape_with_tag_exists = options.fetch(:skip_transcode_if_shape_with_tag_exists, true)
711
737
  [*transcode_tag].each do |_transcode_tag|
@@ -726,6 +752,9 @@ module Vidispine
726
752
  end
727
753
 
728
754
  # 8. Generate the Thumbnails and Poster Frame
755
+ create_thumbnails = args.fetch(:create_thumbnails, true)
756
+ create_posters = args.fetch(:create_posters, 3)
757
+
729
758
  if (create_thumbnails or create_posters)
730
759
  logger.debug { 'Generating Thumbnails(s) and Poster Frame.' }
731
760
  args_out = { :item_id => item_id }
@@ -1,3 +1,3 @@
1
1
  module Vidispine
2
- VERSION = '1.5.5'
2
+ VERSION = '1.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vidispine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.5
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Whitson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-31 00:00:00.000000000 Z
11
+ date: 2018-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler