subber 0.1.4 → 0.1.8
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/Gemfile.lock +1 -1
- data/lib/subber/file/base.rb +15 -0
- data/lib/subber/parser/srt.rb +4 -5
- data/lib/subber/subtitle.rb +29 -0
- data/lib/subber/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d99774cbda4336ea215569220767f66527e1934
|
4
|
+
data.tar.gz: 86c850d34a871e2c97b31cad63605ff4533cdf36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a749c05830ea797c0484f96217bdc7fb4a0415005ff5806941f8b5bce9e82f3452474847f31c5ecc88a9d082df3f2e1560790df025d8958844961704059f29e4
|
7
|
+
data.tar.gz: a524ce7dc665f0ec04b10378b7ffc4c79a0a6eaf33fec5a8f7ef011998eb2918d0029cd1d7144502edc2fc8da17590e73dacf5961a83203e35b7c4f118d0566f
|
data/Gemfile.lock
CHANGED
data/lib/subber/file/base.rb
CHANGED
@@ -56,6 +56,21 @@ module Subber::File
|
|
56
56
|
File.write(path, content)
|
57
57
|
end
|
58
58
|
|
59
|
+
# @param ms [Integer] Can be both positive and negative
|
60
|
+
# @return [Subber::File::Base] return a new copy with shifted subtitles
|
61
|
+
#
|
62
|
+
def shift(ms)
|
63
|
+
new_subtitles = subtitles.map { |subtitle| subtitle.shift(ms) }
|
64
|
+
self.class.new(subtitles: new_subtitles)
|
65
|
+
end
|
66
|
+
|
67
|
+
# @param ms [Integer] Can be both positive and negative
|
68
|
+
# mutates the current file's subtitles
|
69
|
+
#
|
70
|
+
def shift!(ms)
|
71
|
+
subtitles.each { |subtitle| subtitle.shift!(ms) }
|
72
|
+
end
|
73
|
+
|
59
74
|
private
|
60
75
|
|
61
76
|
def formatter
|
data/lib/subber/parser/srt.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
module Subber::Parser
|
2
2
|
class Srt < Base
|
3
3
|
SUBTITLE_REGEX = /([^\n]*)\n([^\n]*)(\n(.*))?/m
|
4
|
-
COUNTER_REGEX =
|
4
|
+
COUNTER_REGEX = /(\d+)$/
|
5
5
|
TIME_RANGE_REGEX = /(\d{2}:\d{2}:\d{2},\d{3})\s*-->\s*(\d{2}:\d{2}:\d{2},\d{3})/
|
6
6
|
TIMECODE_REGEX = /(\d{2}):(\d{2}):(\d{2}),(\d{3})/
|
7
7
|
|
8
8
|
DELIMITER_REGEX = /\n?\n\n/
|
9
9
|
WINDOW_LINE_BREAK_REGEX = /\r/
|
10
|
-
BYTE_ORDER_MARK_STRING = "\xEF\xBB\xBF"
|
11
10
|
|
12
11
|
class << self
|
13
12
|
# @param file_content [String]
|
@@ -62,9 +61,9 @@ module Subber::Parser
|
|
62
61
|
# @raise [Subber::Errors::InvalidCounter]
|
63
62
|
#
|
64
63
|
def extract_counter(text)
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
counter_text = text.match(COUNTER_REGEX).to_a.last
|
65
|
+
raise(Subber::Errors::InvalidCounter) if counter_text.nil?
|
66
|
+
counter_text.to_i
|
68
67
|
end
|
69
68
|
|
70
69
|
# @param text [String]
|
data/lib/subber/subtitle.rb
CHANGED
@@ -10,4 +10,33 @@ class Subber::Subtitle
|
|
10
10
|
@end_time = attributes[:end_time]
|
11
11
|
@content = attributes[:content]
|
12
12
|
end
|
13
|
+
|
14
|
+
def as_json
|
15
|
+
{
|
16
|
+
'counter' => counter,
|
17
|
+
'start_time' => start_time,
|
18
|
+
'end_time' => end_time,
|
19
|
+
'content' => content
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param miliseconds [Integer] Can be both positive and negative
|
24
|
+
# @return [Subber::Subtitle] return a copy with shifted subtitle
|
25
|
+
#
|
26
|
+
def shift(ms)
|
27
|
+
self.class.new(
|
28
|
+
counter: counter,
|
29
|
+
start_time: start_time + ms,
|
30
|
+
end_time: end_time + ms,
|
31
|
+
content: content
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
# @param miliseconds [Integer] Can be both positive and negative
|
36
|
+
# mutates the current subtitle's start and end time by ms
|
37
|
+
#
|
38
|
+
def shift!(ms)
|
39
|
+
@start_time += ms
|
40
|
+
@end_time += ms
|
41
|
+
end
|
13
42
|
end
|
data/lib/subber/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subber
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Viki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.5.2
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Subtitle converter
|