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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 191363dc27d70fda96cacb9df2c059f1e31a47fa
4
- data.tar.gz: fb017b62cf4898b54d36929c868c0ee64f11e9f2
3
+ metadata.gz: c720ac7de84f2d08c402bbcd2cab5eb54b11f867
4
+ data.tar.gz: cc37ddc74a0c93ba68ee8e327fcdf08ed5c708e5
5
5
  SHA512:
6
- metadata.gz: 3f623e35c1d7a8cbb8b49be1f19a8f1a663fb3d6bfb54e295776a52bd44777974fc594030ae021de4c0fd579b2e43f39fe9116f24f180bd06a34036e62929f18
7
- data.tar.gz: 087ba6ef0a6911ebc94d53fa573e5b4e066743877f03758bf7cfee8dd273f849b836899ddf0c45430f3319b8441774d22ac3a77c2d3fb8ee60832b1afb468978
6
+ metadata.gz: 0b6d90cf5b7e8e98ca2a80069dae35ef456c3861b50d3f52898c647ad349f4316f9417fe475a466e12dfc3e4e5081022d6ef8442a8784ea598c90fb04640852a
7
+ data.tar.gz: 9f52f5cca8b54dac0daef7ede6413ea81ccf0c98cdc1c05b8a9433e42047158b93a169ab9b811365ad4372fee53e51b53e4e334aa8995c4964f4ec3505df0cd4
data/filename CHANGED
@@ -1,2 +1,9 @@
1
- 1
2
- 2
1
+ 1
2
+ 00:00:03,495 --> 00:00:05,858
3
+ Tonight, The Deep Dive.
4
+
5
+
6
+ 2
7
+ 00:00:05,891 --> 00:00:10,033
8
+ One company's secret weapon for innovation
9
+
@@ -15,12 +15,10 @@ class STLReader
15
15
 
16
16
  def parse_stl_content(content)
17
17
 
18
- @stl_sub_title_lines = content.lines.select { |line|
19
- line =~ /\d{2}(:[0-5]\d){3}\s+,\s+\d{2}(:[0-5]\d){3}\s+,\s+.*/
20
- }.map { |line|
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
@@ -24,10 +24,6 @@ class SubRibWriter
24
24
  end
25
25
 
26
26
  def to_file(filename)
27
- File.open filename, "w" do |file|
28
- subrib_sub_title_lines.each do |line|
29
- file.puts line
30
- end
31
- end
27
+ File.write(filename, subrib_sub_title_lines.join)
32
28
  end
33
29
  end
@@ -2,18 +2,31 @@
2
2
 
3
3
  class SubtitleConvertor
4
4
 
5
- def from(filename)
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 to(filename)
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)
@@ -1,4 +1,4 @@
1
1
 
2
2
  module SubtitleConverterVersion
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
@@ -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
@@ -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.from(asset_file("IDEO_subtitles_en.txt")).to(output_file("IDEO_subtitles_en.srt")).convert
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.from(asset_file("bad scrummaster_subtitles_en.txt")).to(output_file("bad scrummaster_subtitles_en.srt")).convert
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.from(asset_file("bad scrummaster_subtitles_cn.txt")).to(output_file("bad scrummaster_subtitles_cn.srt")).convert
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
 
@@ -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(result)
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
@@ -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(:open).with("filename", "w").and_yield(file)
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.from("subtitle_stl_file")
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.to("subtitle_srt_file")
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.from("stl_file")
35
- subject.to("srt_file")
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.from("stl_file").to("srt_file").convert
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subtitle_converter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Twin Panichsombat