cloudinary_subtitles_embedder 0.1.2 → 0.1.3
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 +4 -4
- data/.gitignore +13 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +41 -0
- data/Rakefile +10 -0
- data/cloudinary_subtitles_embedder.gemspec +34 -0
- data/lib/cloudinary_subtitles_embedder.rb +1 -2
- data/lib/cloudinary_subtitles_embedder/subtitle_line.rb +33 -0
- data/lib/cloudinary_subtitles_embedder/subtitle_time.rb +28 -0
- data/lib/cloudinary_subtitles_embedder/version.rb +3 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4122a1c5d64a32420756100c9807b91cda8de333
|
4
|
+
data.tar.gz: 28c32e30a6ef3514ed911f932c94d3ea01b19631
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418e8baf50272a49162e8d9d67cce2f432aa683030cbd4ab69cbba3e3a389746162fa7bf0c85c23ba3d2036ac08f395cd31d0a92b3ee8534d0d76a303ad47367
|
7
|
+
data.tar.gz: a1a00463b0a43a42a85a3c96e438e2ae6f6e35e7beae31dfc8ad4ad68f9fbd94591d457336633f1c53f1c08bb4ad18e6fa3a4bc96b7d3ca9f74066c13740c0d4
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# CloudinarySubtitlesEmbedder
|
2
|
+
This gem is used in order to take a video that is hosted on cloudinary and subtitles, and give back a link to video with subtitles embedded in it.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's Gemfile:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'cloudinary_subtitles_embedder'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install cloudinary_subtitles_embedder
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
This gem is exposing a simple API:
|
23
|
+
CloudinarySubtitlesEmbedder.addSubtitlesToVideo(videoPublicId, subtitles, cloud_name)
|
24
|
+
Where
|
25
|
+
|
26
|
+
videoPublicId - the name of the video + file type.
|
27
|
+
|
28
|
+
subtitles - json object of this format: http://res.cloudinary.com/candidate-evaluation/raw/upload/v1545227339/thepresent_-_subtitles.txt .
|
29
|
+
|
30
|
+
cloud_name - the cloud_name in cloudinary.com - the default is candidate-evaluation.
|
31
|
+
|
32
|
+
## Development
|
33
|
+
|
34
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
35
|
+
|
36
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cloudinary_subtitles_embedder.
|
41
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cloudinary_subtitles_embedder/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cloudinary_subtitles_embedder"
|
8
|
+
spec.version = CloudinarySubtitlesEmbedder::VERSION
|
9
|
+
spec.authors = ["Tuval Rotem"]
|
10
|
+
spec.email = ["tuva.roteml@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{add subtitles to cloudinary hosted video}
|
13
|
+
spec.homepage = "https://github.com/tuval10/cloudinary-subtitle-embedder"
|
14
|
+
|
15
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
16
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
21
|
+
"public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
34
|
+
end
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'cloudinary_subtitles_embedder/version'
|
2
|
-
|
3
1
|
module CloudinarySubtitlesEmbedder
|
4
2
|
def self.add_subtitles_to_video(
|
5
3
|
video_public_id,
|
@@ -20,4 +18,5 @@ module CloudinarySubtitlesEmbedder
|
|
20
18
|
|
21
19
|
require 'cloudinary_subtitles_embedder/subtitle_time'
|
22
20
|
require 'cloudinary_subtitles_embedder/subtitle_line'
|
21
|
+
require 'cloudinary_subtitles_embedder/version'
|
23
22
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'erb'
|
2
|
+
module CloudinarySubtitlesEmbedder
|
3
|
+
class SubtitleLine
|
4
|
+
attr_accessor :start_time, :end_time, :text
|
5
|
+
|
6
|
+
def display_options
|
7
|
+
@display_options || %w(co_white g_south y_20)
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.font
|
11
|
+
'Roboto_34px_bold'
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(subtitle_options, general_display_options = nil)
|
15
|
+
self.start_time = subtitle_options["start-timing"]
|
16
|
+
self.end_time = subtitle_options["end-timing"]
|
17
|
+
self.text = subtitle_options["text"]
|
18
|
+
@display_options = general_display_options
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
display_options_string = display_options.join(',')
|
23
|
+
# see https://support.cloudinary.com/hc/en-us/community/posts/200788162-Using-special-characters-in-Text-overlaying-
|
24
|
+
escaped_text = ERB::Util.url_encode(text)
|
25
|
+
.gsub('%2C', '%252C')
|
26
|
+
start_time_sec = CloudinarySubtitlesEmbedder::SubtitleTime.to_seconds(start_time)
|
27
|
+
end_time_sec = CloudinarySubtitlesEmbedder::SubtitleTime.to_seconds(end_time)
|
28
|
+
"/l_text:#{self.class.font}:#{escaped_text},so_#{start_time_sec},eo_#{end_time_sec}" +
|
29
|
+
(display_options_string.empty? ? '' : ',') +
|
30
|
+
display_options_string
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module CloudinarySubtitlesEmbedder
|
2
|
+
class SubtitleTime
|
3
|
+
class << self
|
4
|
+
def multipliers
|
5
|
+
[1, 60, 3600]
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_seconds(duration_string)
|
9
|
+
validate_duration_format(duration_string)
|
10
|
+
time_parts = duration_string.split('.')[0].split(':')
|
11
|
+
seconds = time_parts
|
12
|
+
.reverse.map(&:to_i)
|
13
|
+
.zip(multipliers[0..time_parts.length])
|
14
|
+
.map {|(time_part, seconds_multiplier)| time_part * seconds_multiplier}
|
15
|
+
.reduce(&:+)
|
16
|
+
return seconds unless duration_string.include? '.'
|
17
|
+
milliseconds = duration_string.split('.')[-1]
|
18
|
+
"#{seconds}.#{milliseconds}".to_f
|
19
|
+
end
|
20
|
+
|
21
|
+
def validate_duration_format(duration_string)
|
22
|
+
valid = duration_string =~ /^([0-9]+:)?([0-5]?[0-9]:)?([0-5]?[0-9])(\.[0-9]?[0-9])?$/
|
23
|
+
exception = ArgumentError.new('time format supports only format hours:minutes:seconds.milliseconds')
|
24
|
+
raise exception unless valid
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudinary_subtitles_embedder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tuval Rotem
|
@@ -59,7 +59,16 @@ executables: []
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".travis.yml"
|
64
|
+
- Gemfile
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- cloudinary_subtitles_embedder.gemspec
|
62
68
|
- lib/cloudinary_subtitles_embedder.rb
|
69
|
+
- lib/cloudinary_subtitles_embedder/subtitle_line.rb
|
70
|
+
- lib/cloudinary_subtitles_embedder/subtitle_time.rb
|
71
|
+
- lib/cloudinary_subtitles_embedder/version.rb
|
63
72
|
homepage: https://github.com/tuval10/cloudinary-subtitle-embedder
|
64
73
|
licenses: []
|
65
74
|
metadata:
|
@@ -80,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
89
|
version: '0'
|
81
90
|
requirements: []
|
82
91
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.
|
92
|
+
rubygems_version: 2.5.1
|
84
93
|
signing_key:
|
85
94
|
specification_version: 4
|
86
95
|
summary: add subtitles to cloudinary hosted video
|