subtitle_converter 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/filename +9 -2
- data/lib/subtitle_converter/stl_reader.rb +4 -6
- data/lib/subtitle_converter/sub_rib_writer.rb +1 -5
- data/lib/subtitle_converter/subtitle_convertor.rb +16 -3
- data/lib/subtitle_converter/version.rb +1 -1
- data/spec/assets/bad scrummaster_subtitles_en.txt +1 -1
- data/spec/integration_spec.rb +3 -3
- data/spec/stl_reader_spec.rb +8 -10
- data/spec/subrib_writer_spec.rb +1 -2
- data/spec/subtitle_convertor_spec.rb +8 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c720ac7de84f2d08c402bbcd2cab5eb54b11f867
|
4
|
+
data.tar.gz: cc37ddc74a0c93ba68ee8e327fcdf08ed5c708e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b6d90cf5b7e8e98ca2a80069dae35ef456c3861b50d3f52898c647ad349f4316f9417fe475a466e12dfc3e4e5081022d6ef8442a8784ea598c90fb04640852a
|
7
|
+
data.tar.gz: 9f52f5cca8b54dac0daef7ede6413ea81ccf0c98cdc1c05b8a9433e42047158b93a169ab9b811365ad4372fee53e51b53e4e334aa8995c4964f4ec3505df0cd4
|
data/filename
CHANGED
@@ -15,12 +15,10 @@ class STLReader
|
|
15
15
|
|
16
16
|
def parse_stl_content(content)
|
17
17
|
|
18
|
-
@stl_sub_title_lines = content.lines.
|
19
|
-
|
20
|
-
|
21
|
-
line.gsub!(", \t", ",\t")
|
22
|
-
line.gsub!("\t ,", "\t,")
|
23
|
-
line.split("\t,\t").map(&:strip).join("#")
|
18
|
+
@stl_sub_title_lines = content.lines.collect { |line|
|
19
|
+
matchdata = line.match(/(\d{2}(?::[0-5]\d){3})\s+,\s+(\d{2}(?::[0-5]\d){3})\s+,\s+(.*)/)
|
20
|
+
matchdata.nil? ? nil : matchdata[1] + "#" + matchdata[2] + "#" + matchdata[3]
|
24
21
|
}
|
22
|
+
@stl_sub_title_lines.compact!
|
25
23
|
end
|
26
24
|
end
|
@@ -2,18 +2,31 @@
|
|
2
2
|
|
3
3
|
class SubtitleConvertor
|
4
4
|
|
5
|
-
def
|
5
|
+
def initialize
|
6
6
|
@reader = STLReader.new
|
7
|
+
@writer = SubRibWriter.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def from(content)
|
11
|
+
@reader.parse_stl_content(content)
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def from_file(filename)
|
7
16
|
@reader.import_stl_content(filename)
|
8
17
|
self
|
9
18
|
end
|
10
19
|
|
11
|
-
def
|
12
|
-
@writer = SubRibWriter.new
|
20
|
+
def to_file(filename)
|
13
21
|
@output_file = filename
|
14
22
|
self
|
15
23
|
end
|
16
24
|
|
25
|
+
def convert_to_s
|
26
|
+
@writer.parse_stl_lines(@reader.stl_sub_title_lines)
|
27
|
+
@writer.subrib_sub_title_lines.join
|
28
|
+
end
|
29
|
+
|
17
30
|
def convert
|
18
31
|
@writer.parse_stl_lines(@reader.stl_sub_title_lines)
|
19
32
|
@writer.to_file(@output_file)
|
@@ -35,7 +35,7 @@ $TapeOffset = TRUE
|
|
35
35
|
00:00:51:26 , 00:00:55:22 , As your ScrumMaster and product owner, these are the stories I need you to commit this sprint
|
36
36
|
00:00:59:02 , 00:01:03:07 , My computer was stolen during a break in last night, I can't get any work done until I get a new one
|
37
37
|
00:01:03:08 , 00:01:04:22 , Have you heard of paper?
|
38
|
-
00:01:04:23 , 00:01:08:15 , Adam, I'm gonna need this feature demo this afternoon, you can get it done right?
|
38
|
+
00:01:04:23 , 00:01:08:15 , Adam, I'm gonna need this feature demo this afternoon, you can get it done right?
|
39
39
|
00:01:08:16 , 00:01:09:16 , Yeah, no problem
|
40
40
|
00:01:09:16 , 00:01:09:20 , Great
|
41
41
|
00:01:09:21 , 00:01:10:18 , I'm just gonna add this to your work in progress
|
data/spec/integration_spec.rb
CHANGED
@@ -24,17 +24,17 @@ describe "Trying out different files and output to see if the integration works"
|
|
24
24
|
subject { SubtitleConvertor.new }
|
25
25
|
|
26
26
|
it "Can convert the IDEO shopping cart video subtitles from STL to SRT" do
|
27
|
-
subject.
|
27
|
+
subject.from_file(asset_file("IDEO_subtitles_en.txt")).to_file(output_file("IDEO_subtitles_en.srt")).convert
|
28
28
|
File.read(output_file("IDEO_subtitles_en.srt")).should== File.read(asset_file("IDEO_subtitles_en.srt"))
|
29
29
|
end
|
30
30
|
|
31
31
|
it "Can convert the Shit ScrumMasters say in English" do
|
32
|
-
subject.
|
32
|
+
subject.from_file(asset_file("bad scrummaster_subtitles_en.txt")).to_file(output_file("bad scrummaster_subtitles_en.srt")).convert
|
33
33
|
File.read(output_file("bad scrummaster_subtitles_en.srt")).should== File.read(asset_file("bad scrummaster_subtitles_en.srt"))
|
34
34
|
end
|
35
35
|
|
36
36
|
it "Can convert the Shit ScrumMasters say in Chinese" do
|
37
|
-
subject.
|
37
|
+
subject.from_file(asset_file("bad scrummaster_subtitles_cn.txt")).to_file(output_file("bad scrummaster_subtitles_cn.srt")).convert
|
38
38
|
File.read(output_file("bad scrummaster_subtitles_cn.srt")).should== File.read(asset_file("bad scrummaster_subtitles_cn.srt"))
|
39
39
|
end
|
40
40
|
|
data/spec/stl_reader_spec.rb
CHANGED
@@ -7,19 +7,17 @@ describe STLReader do
|
|
7
7
|
|
8
8
|
let(:stl_reader) { STLReader.new }
|
9
9
|
|
10
|
-
let(:data) {
|
11
|
-
"00:00:03:15\t,\t00:00:05:26\t,\tTonight, The Deep Dive.
|
12
|
-
00:00:05:27\t,\t00:00:10:01\t,\tOne company's secret weapon for innovation"
|
13
|
-
}
|
14
|
-
|
15
|
-
let(:result) { [
|
16
|
-
"00:00:03:15#00:00:05:26#Tonight, The Deep Dive.","00:00:05:27#00:00:10:01#One company's secret weapon for innovation"
|
17
|
-
]}
|
18
|
-
|
19
10
|
it "should open STL file and import content to 'srt_sub_title_lines'" do
|
11
|
+
data = "00:00:03:15\t,\t00:00:05:26\t,\tTonight, The Deep Dive.\n00:00:05:27\t,\t00:00:10:01\t,\tOne company's secret weapon for innovation"
|
20
12
|
File.stub(:read).with("file_name") { data }
|
21
13
|
stl_reader.import_stl_content("file_name")
|
22
|
-
stl_reader.stl_sub_title_lines.should eq(
|
14
|
+
stl_reader.stl_sub_title_lines.should eq(["00:00:03:15#00:00:05:26#Tonight, The Deep Dive.","00:00:05:27#00:00:10:01#One company's secret weapon for innovation"])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should be able to deal with files with spaces and not tabs" do
|
18
|
+
data = "00:00:03:15 , 00:00:05:26 , Tonight, The Deep Dive.\n00:00:05:27 , 00:00:10:01\t,\tOne company's secret weapon for innovation"
|
19
|
+
stl_reader.parse_stl_content(data)
|
20
|
+
stl_reader.stl_sub_title_lines.should eq(["00:00:03:15#00:00:05:26#Tonight, The Deep Dive.","00:00:05:27#00:00:10:01#One company's secret weapon for innovation"])
|
23
21
|
end
|
24
22
|
end
|
25
23
|
end
|
data/spec/subrib_writer_spec.rb
CHANGED
@@ -43,8 +43,7 @@ describe SubRibWriter do
|
|
43
43
|
describe "write_to_file" do
|
44
44
|
it "should create file 'subrib_subtitle.srt' all data in subrib_sub_title_lines in" do
|
45
45
|
file = double("filename")
|
46
|
-
File.should_receive(:
|
47
|
-
file.should_receive(:puts).at_least(:twice)
|
46
|
+
File.should_receive(:write).with("filename", /.*/)
|
48
47
|
|
49
48
|
subrib_writer.parse_stl_lines(stl_sub_title_lines)
|
50
49
|
subrib_writer.to_file("filename")
|
@@ -14,13 +14,13 @@ describe "the subtitle convertor" do
|
|
14
14
|
STLReader.should_receive(:new).and_return(@reader)
|
15
15
|
@reader.should_receive(:import_stl_content).with("subtitle_stl_file")
|
16
16
|
|
17
|
-
subject.
|
17
|
+
subject.from_file("subtitle_stl_file")
|
18
18
|
end
|
19
19
|
|
20
20
|
it "Should create a writer when calling to" do
|
21
21
|
SubRibWriter.should_receive(:new).and_return(nil)
|
22
22
|
|
23
|
-
subject.
|
23
|
+
subject.to_file("subtitle_srt_file")
|
24
24
|
end
|
25
25
|
|
26
26
|
it "Should convert from one to another on convert" do
|
@@ -31,8 +31,8 @@ describe "the subtitle convertor" do
|
|
31
31
|
@writer.should_receive(:parse_stl_lines).with("subtitles")
|
32
32
|
@writer.should_receive(:to_file).with("srt_file")
|
33
33
|
|
34
|
-
subject.
|
35
|
-
subject.
|
34
|
+
subject.from_file("stl_file")
|
35
|
+
subject.to_file("srt_file")
|
36
36
|
subject.convert
|
37
37
|
end
|
38
38
|
|
@@ -40,7 +40,10 @@ describe "the subtitle convertor" do
|
|
40
40
|
STLReader.should_receive(:new).and_return(@reader)
|
41
41
|
SubRibWriter.should_receive(:new).and_return(@writer)
|
42
42
|
|
43
|
-
subject.
|
43
|
+
subject.from_file("stl_file").to_file("srt_file").convert
|
44
|
+
end
|
44
45
|
|
46
|
+
it "Can convert content without writing to files" do
|
47
|
+
subject.from("00:01:08:16 , 00:01:09:16 , Yeah, no problem").convert_to_s.should== "1\n00:01:08,528 --> 00:01:09,528\nYeah, no problem\n\n"
|
45
48
|
end
|
46
49
|
end
|