cloudinary_subtitles_embedder 0.1.1 → 0.1.2
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3f505c1a5bfbcdebecf687d22524ec661d39a0c
|
4
|
+
data.tar.gz: 46d27168911d9e200504f622d91c98c1461902a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c7161485d91c2c66f018933635555e810bb978ea64940a1a3084c06497815c57b6d5a8df240964b66cd69e55c97aeb824ffd76c7e4d03a547c951affbaef3ac
|
7
|
+
data.tar.gz: a59a1704df16f3cc7e1a5971b29cb92422b55c7013fc519d1a1ab00e89b1260b87dd315ddc5e8126dbffe5ee8cc03d2586af6e242ec8e67b8343d6edcfc97844
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tuval Rotem
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,9 +60,6 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- lib/cloudinary_subtitles_embedder.rb
|
63
|
-
- lib/cloudinary_subtitles_embedder/subtitle_line.rb
|
64
|
-
- lib/cloudinary_subtitles_embedder/subtitle_time.rb
|
65
|
-
- lib/cloudinary_subtitles_embedder/version.rb
|
66
63
|
homepage: https://github.com/tuval10/cloudinary-subtitle-embedder
|
67
64
|
licenses: []
|
68
65
|
metadata:
|
@@ -83,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
80
|
version: '0'
|
84
81
|
requirements: []
|
85
82
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.6.8
|
87
84
|
signing_key:
|
88
85
|
specification_version: 4
|
89
86
|
summary: add subtitles to cloudinary hosted video
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
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 = SubtitleTime.to_seconds(start_time)
|
27
|
-
end_time_sec = 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
|
@@ -1,26 +0,0 @@
|
|
1
|
-
class SubtitleTime
|
2
|
-
class << self
|
3
|
-
def multipliers
|
4
|
-
[1, 60, 3600]
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_seconds(duration_string)
|
8
|
-
validate_duration_format(duration_string)
|
9
|
-
time_parts = duration_string.split('.')[0].split(':')
|
10
|
-
seconds = time_parts
|
11
|
-
.reverse.map(&:to_i)
|
12
|
-
.zip(multipliers[0..time_parts.length])
|
13
|
-
.map {|(time_part, seconds_multiplier)| time_part * seconds_multiplier}
|
14
|
-
.reduce(&:+)
|
15
|
-
return seconds unless duration_string.include? '.'
|
16
|
-
milliseconds = duration_string.split('.')[-1]
|
17
|
-
"#{seconds}.#{milliseconds}".to_f
|
18
|
-
end
|
19
|
-
|
20
|
-
def validate_duration_format(duration_string)
|
21
|
-
valid = duration_string =~ /^([0-9]+:)?([0-5]?[0-9]:)?([0-5]?[0-9])(\.[0-9]?[0-9])?$/
|
22
|
-
exception = ArgumentError.new('time format supports only format hours:minutes:seconds.milliseconds')
|
23
|
-
raise exception unless valid
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|