clint-upload 0.1.0 → 0.2.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: 0fe353f528d5270f7ad69f146ba4abc7cbb7966e
4
- data.tar.gz: 009642dee8c09494363d08a401fc4fbccae54237
3
+ metadata.gz: 23bc3aac70c4a9229053e9600ab808abe8d1dcf8
4
+ data.tar.gz: b4f86c0e84b0dfb35e20c105a37994bc0e1ee64c
5
5
  SHA512:
6
- metadata.gz: 1bf262073a8642a3884dd9bc27d13ef88a423d067e0b01b46951df6a2a609b7c2496149cbf2c87cd984c4b7a7c1f1342c4b0e3f2e80d9b2fe01ad042d44c155a
7
- data.tar.gz: 75b3bf4de8f1d4a3f67373e290d6813229ac9fe198c2df400659c84b4a4c043fc183299251dbf763d680d4d8464fae2a979366c4567985bf04fa0008201f4b8c
6
+ metadata.gz: 3782f4d470dee1f1d6f863357b98b7bc6b5ad4101b17dcf415394013a28635925c14c1f4dae6a7cd8ee15277d9c83b73b541a3c6b3b830bfaa1e449a4e07a8b5
7
+ data.tar.gz: 78b4457c2af92b62066cb7c16bf56cb915c41fa889501cf6fd57ff7f2870d15fa7d0c5edd85c1aa81b73e1e518d36cda6546d7fd2050226b8634fe834c00c5ef
data/clint-upload.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "pry"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec", "~> 3.0"
24
+ spec.add_development_dependency "timecop", "~> 0"
24
25
 
25
26
  spec.add_dependency "aws-sdk", "~> 2"
26
27
  spec.add_dependency "json"
@@ -0,0 +1,33 @@
1
+ require 'aws-sdk'
2
+ require 'clint/upload/elastic_transcoder/payload/gif'
3
+ require 'clint/upload/elastic_transcoder/payload/mp4'
4
+ require 'clint/upload/elastic_transcoder/unsupported_output_type'
5
+
6
+ module Clint
7
+ module Upload
8
+ module ElasticTranscoder
9
+ class Job
10
+ def create(output_type, input_path, output_prefix, meta)
11
+ payload_creator = case output_type
12
+ when 'gif'
13
+ Payload::Gif.new
14
+ when 'mp4'
15
+ Payload::Mp4.new
16
+ else
17
+ raise UnsupportedOutputType.new(output_type)
18
+ end
19
+
20
+ etc.create_job(
21
+ payload_creator.payload(input_path, output_prefix, meta)
22
+ ).job.id
23
+ end
24
+
25
+ private
26
+
27
+ def etc
28
+ @etc ||= Aws::ElasticTranscoder::Client.new
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,48 @@
1
+ require 'clint/upload/elastic_transcoder/unsupported_output_type'
2
+ require 'clint/upload/elastic_transcoder/job'
3
+
4
+ module Clint
5
+ module Upload
6
+ module ElasticTranscoder
7
+ class JobCreator
8
+ def initialize(config)
9
+ @config = config
10
+ end
11
+
12
+ def create(input_path, prefix, video_id, video_version_id)
13
+ output_formats.each do |type|
14
+ create_job(type, input_path, prefix, video_id, video_version_id)
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :config
21
+
22
+ def create_job(type, input_path, prefix, video_id, video_version_id)
23
+ job.create(
24
+ type,
25
+ input_path,
26
+ prefix,
27
+ video_meta(video_id, video_version_id)
28
+ )
29
+ end
30
+
31
+ def output_formats
32
+ config.output_formats
33
+ end
34
+
35
+ def job
36
+ Job.new
37
+ end
38
+
39
+ def video_meta(video_id, video_version_id)
40
+ {
41
+ 'VideoID' => video_id.to_s,
42
+ 'VideoVersionID' => video_version_id.to_s
43
+ }
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,58 @@
1
+ require 'wes/cloudkit'
2
+
3
+ module Clint
4
+ module Upload
5
+ module ElasticTranscoder
6
+ module Payload
7
+ class Base
8
+ def payload(input_path, output_prefix, meta)
9
+ {
10
+ pipeline_id: pipeline_id,
11
+ input: {
12
+ key: input_path
13
+ },
14
+ output: {
15
+ key: filename,
16
+ preset_id: preset_id
17
+ },
18
+ output_key_prefix: format(
19
+ '%s/%s/', base_prefix, output_prefix
20
+ ),
21
+ user_metadata: generate_meta(meta)
22
+ }
23
+ end
24
+
25
+ protected
26
+
27
+ def filename
28
+ raise NotImplemented
29
+ end
30
+
31
+ def preset_id
32
+ raise NotImplemented
33
+ end
34
+
35
+ def pipeline_id
36
+ config.pipeline_id
37
+ end
38
+
39
+ def base_prefix
40
+ config.base_prefix
41
+ end
42
+
43
+ def generate_meta(meta)
44
+ meta.merge('type' => type)
45
+ end
46
+
47
+ def type
48
+ self.class.name.split('::').last.downcase
49
+ end
50
+
51
+ def config
52
+ Wes::Cloudkit.config('elastic_transcoder')
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,35 @@
1
+ require 'clint/upload/elastic_transcoder/payload/base'
2
+
3
+ module Clint
4
+ module Upload
5
+ module ElasticTranscoder
6
+ module Payload
7
+ class Gif < Base
8
+ def payload(input_path, output_prefix, meta)
9
+ super.tap do |pl|
10
+ pl[:output][:thumbnail_pattern] = thumbnail_pattern
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def prefix
17
+ 'output'
18
+ end
19
+
20
+ def thumbnail_pattern
21
+ format('%s_{count}', prefix)
22
+ end
23
+
24
+ def filename
25
+ format('%s.gif', prefix)
26
+ end
27
+
28
+ def preset_id
29
+ config.gif_preset_id
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,21 @@
1
+ require 'clint/upload/elastic_transcoder/payload/base'
2
+
3
+ module Clint
4
+ module Upload
5
+ module ElasticTranscoder
6
+ module Payload
7
+ class Mp4 < Base
8
+ def filename
9
+ 'output.mp4'
10
+ end
11
+
12
+ private
13
+
14
+ def preset_id
15
+ config.mp4_preset_id
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ module Clint
2
+ module Upload
3
+ module ElasticTranscoder
4
+ class UnsupportedOutputType < StandardError
5
+ def initialise(type)
6
+ msg = format('Unsupported output type: %s', type)
7
+ super(msg)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/clint/upload.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Clint
2
2
  module Upload
3
- VERSION = "0.1.0".freeze
3
+ VERSION = "0.2.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clint-upload
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-20 00:00:00.000000000 Z
11
+ date: 2016-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: timecop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: aws-sdk
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +132,12 @@ files:
118
132
  - Gemfile
119
133
  - clint-upload.gemspec
120
134
  - lib/clint/upload.rb
135
+ - lib/clint/upload/elastic_transcoder/job.rb
136
+ - lib/clint/upload/elastic_transcoder/job_creator.rb
137
+ - lib/clint/upload/elastic_transcoder/payload/base.rb
138
+ - lib/clint/upload/elastic_transcoder/payload/gif.rb
139
+ - lib/clint/upload/elastic_transcoder/payload/mp4.rb
140
+ - lib/clint/upload/elastic_transcoder/unsupported_output_type.rb
121
141
  - lib/clint/upload/signed_url.rb
122
142
  homepage: ''
123
143
  licenses: []