flatiron-video-uploader 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49245bc8824c685790d548e8b5b3e104a9991b74
4
+ data.tar.gz: 3ded48c384c92641f8f223ecb0702b0279a15d33
5
+ SHA512:
6
+ metadata.gz: fa29809ff5a4fd57cd1427df8a5872648154d0cbfc221efd0ba0b9512317ec9bb9983539e2d22491607b035ebe39cbb4d1dda15eccaee3e78dd3a4edb1d48114
7
+ data.tar.gz: 123579a29d5ec2830f3d496604eb7d92c40aa30686a7d2f4a7e9dc3f1491c69cfcea78b35142fe622bbcc16e4f2db946a59c9db529b9c4ac6b944bbe51012db1
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in flatiron-video-uploader.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Joe Burgess
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Flatiron::Video::Uploader
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'flatiron-video-uploader'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install flatiron-video-uploader
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/flatiron-video-uploader/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'flatiron-video-uploader'
4
+
5
+ FlatironVideoUploader::Cli.start( ARGV )
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'flatiron-video-uploader/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "flatiron-video-uploader"
8
+ spec.version = FlatironVideoUploader::VERSION
9
+ spec.authors = ["Joe Burgess"]
10
+ spec.email = ["joemburgess@gmail.com"]
11
+ spec.summary = %q{Gem to upload videos to s3 and youtube}
12
+ spec.description = %q{Gem to upload videos to s3 and youtube}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_runtime_dependency "httparty"
24
+ spec.add_runtime_dependency "faraday"
25
+ spec.add_runtime_dependency "thor"
26
+ spec.add_runtime_dependency "signet"
27
+ spec.add_runtime_dependency "httpclient"
28
+ spec.add_runtime_dependency "aws-sdk"
29
+ spec.add_runtime_dependency "streamio-ffmpeg"
30
+ spec.add_runtime_dependency "terminal-notifier"
31
+ spec.add_runtime_dependency "google-api-client"
32
+ end
@@ -0,0 +1,19 @@
1
+ require 'httparty'
2
+ require 'openssl'
3
+ require 'yaml'
4
+ require 'google/api_client'
5
+ require 'signet'
6
+ require 'httpclient'
7
+ require 'aws-sdk'
8
+ require 'streamio-ffmpeg'
9
+ require 'thread'
10
+ require 'terminal-notifier'
11
+
12
+
13
+ require "flatiron-video-uploader/version"
14
+ require "flatiron-video-uploader/cli"
15
+ require "flatiron-video-uploader/runner"
16
+
17
+ module FlatironVideoUploader
18
+
19
+ end
@@ -0,0 +1,16 @@
1
+ require 'thor'
2
+
3
+ module FlatironVideoUploader
4
+ class Cli < Thor
5
+ desc "hello NAME", "This will greet you"
6
+ def hello (name)
7
+ puts name.upcase
8
+ end
9
+
10
+ desc "upload FILE", "This will greet you"
11
+ method_option :batch, :type => :string, :default => ""
12
+ def upload (file)
13
+ FlatironVideoUploader::Runner.upload_video(file,options[:batch])
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,175 @@
1
+ Faraday.default_adapter = :httpclient
2
+ module FlatironVideoUploader
3
+ class Runner
4
+ GRANT_TYPE = "http://oauth.net/grant_type/device/1.0"
5
+ THOR_SHELL = Thor::Shell::Basic.new
6
+ def self.upload_video(file,batch)
7
+
8
+ FFMPEG.logger=Logger.new(STDOUT)
9
+ FFMPEG.logger.level = Logger::ERROR
10
+ begin
11
+ token_response = YAML.load_file(File.expand_path('~/.flatiron-uploader'))
12
+ rescue
13
+ puts "We are going to need a few ID/Secret stuff."
14
+ puts "\n\nGoogle"
15
+ google_client_id = THOR_SHELL.ask("What is your Google Client ID?")
16
+ google_client_secret = THOR_SHELL.ask("What is your Google Client Secret?")
17
+ puts "Finished with Google.\n\n"
18
+ puts "#"*30
19
+ puts "\n\nAmazon S3"
20
+ amazon_s3_key = THOR_SHELL.ask("What is your Amazon S3 Key?")
21
+ amazon_s3_secret = THOR_SHELL.ask("What is your Amazon S3 Secret?")
22
+ puts "#"*30
23
+ response = HTTParty.post("https://accounts.google.com/o/oauth2/device/code",:query => {:scope => "https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtube", :client_id => "404828420863-l0nvu5ihjg7kji18d4pghrnetre28d5e.apps.googleusercontent.com"})
24
+
25
+ puts "OK cool, go to #{response["verification_url"]} and type in the following code"
26
+ `open #{response["verification_url"]}`
27
+ puts "#"*30
28
+ puts response["user_code"]
29
+ puts "#"*30
30
+ puts "polling"
31
+
32
+ token_response = HTTParty.post("https://www.googleapis.com/oauth2/v3/token", :query => {:client_id => google_client_id, :client_secret => google_client_secret, :grant_type => GRANT_TYPE, :code => response["device_code"]})
33
+ while(token_response.code==400)
34
+ sleep(response["interval"])
35
+ token_response = HTTParty.post("https://www.googleapis.com/oauth2/v3/token", :query => {:client_id => google_client_id, :client_secret => google_client_secret, :grant_type => GRANT_TYPE, :code => response["device_code"]})
36
+ end
37
+ puts "Found!"
38
+
39
+ token_response["google_client_id"] = google_client_id
40
+ token_response["google_client_secret"] = google_client_secret
41
+ token_response["amazon_s3_key"] = amazon_s3_key
42
+ token_response["amazon_s3_secret"] = amazon_s3_secret
43
+ File.open(File.expand_path('~/.flatiron-uploader'), 'w') do |h|
44
+ h.write token_response.to_yaml
45
+ end
46
+ end
47
+
48
+ if !File.exist?(file) || !File.file?(file)
49
+ puts "Not a file!"
50
+ exit
51
+ end
52
+ progress_mutex = Mutex.new
53
+ print_progress = false
54
+ movie_transcode_thread = Thread.new do
55
+ movie = FFMPEG::Movie.new(file)
56
+ movie.transcode("/tmp/transcoded.mp4","-vf 'scale=-2:720:flags=lanczos' -vcodec libx264 -profile:v main -level 3.1 -preset veryfast -crf 23 -x264-params ref=4 -acodec copy -movflags +faststart") do |prog|
57
+ progress_mutex.synchronize do
58
+ if print_progress
59
+ print "\r"
60
+ # puts add \n to the end of string, use print instead
61
+ print sprintf("%.2f",prog*100)
62
+
63
+ # force the output to appear immediately when using print
64
+ # by default when \n is printed to the standard output, the buffer is flushed.
65
+ $stdout.flush
66
+ end
67
+ end
68
+ end
69
+ TerminalNotifier.notify("Finished Transcoding for iPad")
70
+ end
71
+
72
+ auth = Signet::OAuth2::Client.new(
73
+ :authorization_uri => "https://accounts.google.com/o/oauth2/auth",
74
+ :token_credential_uri => "https://accounts.google.com/o/oauth2/token",
75
+ :client_id => token_response['google_client_id'],
76
+ :client_secret => token_response['google_client_secret']
77
+ )
78
+ auth.refresh_token = token_response["refresh_token"]
79
+ auth.refresh!
80
+
81
+ client = Google::APIClient.new(
82
+ :application_name => "flatiron_uploder",
83
+ :application_version => "0.1")
84
+
85
+ client.authorization = auth
86
+ video_title= ""
87
+ topics = []
88
+ answer = "N"
89
+ while (answer.upcase != "Y") do
90
+ temp = THOR_SHELL.ask("What is the name of this video(#{video_title})?")
91
+ video_title = temp unless temp.empty?
92
+ if (batch.empty?)
93
+ puts "#"*30
94
+ puts "\n\nUploading Topic Video!\n\n"
95
+ puts "#"*30
96
+ end
97
+ temp = THOR_SHELL.ask("Comma separated list of topics (#{topics})?")
98
+ topics = temp.split(",") unless temp.empty?
99
+ puts "#"*30
100
+ puts "Summary"
101
+ puts "Title: #{video_title}"
102
+ puts "Batch: #{batch}" unless batch.empty?
103
+ puts "Topics: #{topics}"
104
+ answer=THOR_SHELL.ask("Is that correct (Y/N)?")
105
+
106
+ end
107
+ youtube = client.discovered_api("youtube","v3")
108
+
109
+ s3 = Aws::S3::Resource.new(
110
+ # credentials: Aws::Credentials.new('AKIAJY4YSCUKNRWWASIA', 'lXp+rsDPaHcoaEay3XcjfAnE1l1W8BRWOrdLfsPH'),
111
+ credentials: Aws::Credentials.new(token_response['amazon_s3_key'], token_response['amazon_s3_secret']),
112
+ region: 'us-east-1'
113
+ )
114
+
115
+ topics << batch unless batch.empty?
116
+ begin
117
+ body = {
118
+ :snippet => {
119
+ :title => video_title,
120
+ :tags => topics
121
+ },
122
+ :status => {
123
+ :privacyStatus => "unlisted"
124
+ }
125
+ }
126
+
127
+ puts "\n\nOK, about to upload the video. This will take a while"
128
+ videos_insert_response = client.execute!(
129
+ :api_method => youtube.videos.insert,
130
+ :body_object => body,
131
+ :media => Google::APIClient::UploadIO.new(file, 'video/*'),
132
+ :parameters => {
133
+ :uploadType => 'resumable',
134
+ :part => body.keys.join(',')
135
+ }
136
+ )
137
+ videos_insert_response.resumable_upload.send_all(client)
138
+ puts "Uploaded wooooooooo. The id is #{videos_insert_response.data.id}"
139
+ puts "\n\n"
140
+ puts "#"*30
141
+ puts "Place this in todays schedule on github\n\n\n"
142
+ command = "<iframe width=\"560\" height=\"315\"
143
+ src=\"https://www.youtube.com/embed/#{videos_insert_response.data.id}\" frameborder=\"0\"
144
+ allowfullscreen></iframe><p><a href=\"https://www.youtube.com/watch?v=#{videos_insert_response.data.id}\">#{video_title}</a></p>"
145
+ puts command
146
+ puts "\n\n"
147
+ puts "#"*30
148
+
149
+ TerminalNotifier.notify("Finished Uploading Video to Youtube. Click to copy embed ", :title => "Video Uploader", :execute => `echo '#{command}' | pbcopy`)
150
+ rescue Google::APIClient::TransmissionError => e
151
+ puts e.result.body
152
+ end
153
+
154
+ puts "Waiting for the video to finish encoding to iPad format\n\n"
155
+ raw_upload_thread = nil
156
+ if batch.empty?
157
+ raw_upload_thread = Thread.new do
158
+ raw_obj = s3.bucket('flatiron-school-learn-videos').object("topic-videos-full/#{videos_insert_response.data.id}.mp4")
159
+ raw_obj.upload_file(file, acl:'public-read')
160
+ end
161
+ end
162
+ print_progress = true
163
+ movie_transcode_thread.join
164
+
165
+ puts "\nDone transcoding. Let's upload to S3"
166
+
167
+ obj = s3.bucket('flatiron-school-learn-videos').object("lecture-videos/#{videos_insert_response.data.id}.mp4")
168
+ obj.upload_file('/tmp/transcoded.mp4', acl:'public-read')
169
+ raw_upload_thread.join unless raw_upload_thread.nil?
170
+ puts "All Done!"
171
+ TerminalNotifier.notify("All Done!", :title =>"Video Uploader")
172
+ `rm /tmp/transcoded.mp4`
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,3 @@
1
+ module FlatironVideoUploader
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flatiron-video-uploader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Joe Burgess
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: thor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: signet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: httpclient
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: aws-sdk
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: streamio-ffmpeg
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: terminal-notifier
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: google-api-client
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :runtime
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ description: Gem to upload videos to s3 and youtube
168
+ email:
169
+ - joemburgess@gmail.com
170
+ executables:
171
+ - flatiron-video-uploader
172
+ extensions: []
173
+ extra_rdoc_files: []
174
+ files:
175
+ - ".gitignore"
176
+ - Gemfile
177
+ - LICENSE.txt
178
+ - README.md
179
+ - Rakefile
180
+ - bin/flatiron-video-uploader
181
+ - flatiron-video-uploader.gemspec
182
+ - lib/flatiron-video-uploader.rb
183
+ - lib/flatiron-video-uploader/cli.rb
184
+ - lib/flatiron-video-uploader/runner.rb
185
+ - lib/flatiron-video-uploader/version.rb
186
+ homepage: ''
187
+ licenses:
188
+ - MIT
189
+ metadata: {}
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.4.8
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Gem to upload videos to s3 and youtube
210
+ test_files: []