srt_subtitle_validator 0.1.7 → 0.2.0

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.
@@ -0,0 +1,86 @@
1
+ 1
2
+ 00:00:03,400 --> 00:00:04,280
3
+ V�te...
4
+
5
+ 2
6
+ 00:00:04,600 --> 00:00:07,600
7
+ Kdy� mi �ekli, �e polet�m do jin� galaxie
8
+
9
+ 3
10
+ 00:00:07,840 --> 00:00:10,400
11
+ nav�t�v�m ciz� sv�ty
12
+
13
+ 4
14
+ 00:00:10,960 --> 00:00:14,080
15
+ a budu br�nit lidstvo p�ed
16
+ nep�edstaviteln�mi hrozbami z vesm�ru
17
+
18
+ 5
19
+ 00:00:14,120 --> 00:00:17,520
20
+ p�edstavoval jsem si to jinak.
21
+
22
+ 6
23
+ 00:00:17,720 --> 00:00:19,640
24
+ Mo�n� zachra�ujeme Zemi
25
+
26
+ 7
27
+ 00:00:19,680 --> 00:00:21,360
28
+ pr�v� te� a pr�v� tady, majore.
29
+
30
+ 8
31
+ 00:00:21,400 --> 00:00:23,000
32
+ Ano? A jak?
33
+
34
+ 9
35
+ 00:00:23,120 --> 00:00:25,280
36
+ T�m, �e l�pe pochop�me
37
+
38
+ 10
39
+ 00:00:25,320 --> 00:00:30,240
40
+ jak zdej�� rostlinn� �ivot ovliv�uje velice
41
+ n�zk� hladina atmosf�rick�ho ozonu.
42
+
43
+ 11
44
+ 00:00:30,280 --> 00:00:33,200
45
+ Mo�n� si to nebudete cht�t p�iznat,
46
+ ale jde o velice v�nou v�c.
47
+
48
+ 12
49
+ 00:00:33,360 --> 00:00:35,000
50
+ Ach... jo... jasn�.
51
+
52
+ 13
53
+ 00:00:35,320 --> 00:00:37,920
54
+ Glob�ln� oteplov�n�, �tok Wraith�.
55
+
56
+ 14
57
+ 00:00:38,200 --> 00:00:40,960
58
+ Kdy� se nad t�m zamysl�m,
59
+ je tu jasn� podobnost. D�ky.
60
+
61
+ 15
62
+ 00:00:41,000 --> 00:00:43,000
63
+ Necho�te moc daleko, doktore. OK?
64
+
65
+ 16
66
+ 00:00:43,080 --> 00:00:44,600
67
+ ��dn� strach, majore!
68
+
69
+ 17
70
+ 00:00:44,760 --> 00:00:47,160
71
+ Nemysl�m si, �e by n�jak� zv��e mohlo p�e��t
72
+
73
+ 18
74
+ 00:00:47,200 --> 00:00:50,720
75
+ dlouhodob� vystaven� slune�n�mu
76
+ z��en� na t�to planet�.
77
+
78
+ 19
79
+ 00:00:50,760 --> 00:00:52,400
80
+ Tak�e to nebude dobr�
81
+ m�sto na letn� s�dlo.
82
+
83
+ 20
84
+ 00:00:53,960 --> 00:00:58,400
85
+ Po pravd�, vegetaci se tu da�� velice dob�e.
86
+
@@ -0,0 +1,86 @@
1
+ 1
2
+ 00:00:03,400 --> 00:00:04,280
3
+ Víte...
4
+
5
+ 2
6
+ 00:00:04,600 --> 00:00:07,600
7
+ Když mi řekli, že poletím do jiné galaxie
8
+
9
+ 3
10
+ 00:00:07,840 --> 00:00:10,400
11
+ navštívím cizí světy
12
+
13
+ 4
14
+ 00:00:10,960 --> 00:00:14,080
15
+ a budu bránit lidstvo před
16
+ nepředstavitelnými hrozbami z vesmíru
17
+
18
+ 5
19
+ 00:00:14,120 --> 00:00:17,520
20
+ představoval jsem si to jinak.
21
+
22
+ 6
23
+ 00:00:17,720 --> 00:00:19,640
24
+ Možná zachraňujeme Zemi
25
+
26
+ 7
27
+ 00:00:19,680 --> 00:00:21,360
28
+ právě teď a právě tady, majore.
29
+
30
+ 8
31
+ 00:00:21,400 --> 00:00:23,000
32
+ Ano? A jak?
33
+
34
+ 9
35
+ 00:00:23,120 --> 00:00:25,280
36
+ Tím, že lépe pochopíme
37
+
38
+ 10
39
+ 00:00:25,320 --> 00:00:30,240
40
+ jak zdejší rostlinný život ovlivňuje velice
41
+ nízká hladina atmosférického ozonu.
42
+
43
+ 11
44
+ 00:00:30,280 --> 00:00:33,200
45
+ Možná si to nebudete chtít přiznat,
46
+ ale jde o velice vážnou věc.
47
+
48
+ 12
49
+ 00:00:33,360 --> 00:00:35,000
50
+ Ach... jo... jasně.
51
+
52
+ 13
53
+ 00:00:35,320 --> 00:00:37,920
54
+ Globální oteplování, útok Wraithů.
55
+
56
+ 14
57
+ 00:00:38,200 --> 00:00:40,960
58
+ Když se nad tím zamyslím,
59
+ je tu jasná podobnost. Díky.
60
+
61
+ 15
62
+ 00:00:41,000 --> 00:00:43,000
63
+ Nechoďte moc daleko, doktore. OK?
64
+
65
+ 16
66
+ 00:00:43,080 --> 00:00:44,600
67
+ Žádný strach, majore!
68
+
69
+ 17
70
+ 00:00:44,760 --> 00:00:47,160
71
+ Nemyslím si, že by nějaké zvíře mohlo přežít
72
+
73
+ 18
74
+ 00:00:47,200 --> 00:00:50,720
75
+ dlouhodobé vystavení slunečnímu
76
+ záření na této planetě.
77
+
78
+ 19
79
+ 00:00:50,760 --> 00:00:52,400
80
+ Takže to nebude dobré
81
+ místo na letní sídlo.
82
+
83
+ 20
84
+ 00:00:53,960 --> 00:00:58,400
85
+ Po pravdě, vegetaci se tu daří velice dobře.
86
+
@@ -0,0 +1,82 @@
1
+ 1
2
+ 00:00:03,400 --> 00:00:04,280
3
+ Víte...
4
+
5
+ 2
6
+ 00:00:04,600 --> 00:00:07,600
7
+ Když mi řekli, že poletím do jiné galaxie
8
+
9
+ 3
10
+ 00:00:07,840 --> 00:00:10,400
11
+ navštívím cizí světy
12
+
13
+ 4
14
+ 00:00:10,960 --> 00:00:14,080
15
+ a budu bránit lidstvo před
16
+ nepředstavitelnými hrozbami z vesmíru
17
+
18
+ 6
19
+ 00:00:17,720 --> 00:00:19,640
20
+ Možná zachraňujeme Zemi
21
+
22
+ 7
23
+ 00:00:19,680 --> 00:00:21,360
24
+ právě teď a právě tady, majore.
25
+
26
+ 8
27
+ 00:00:21,400 --> 00:00:23,000
28
+ Ano? A jak?
29
+
30
+ 9
31
+ 00:00:23,120 --> 00:00:25,280
32
+ Tím, že lépe pochopíme
33
+
34
+ 10
35
+ 00:00:25,320 --> 00:00:30,240
36
+ jak zdejší rostlinný život ovlivňuje velice
37
+ nízká hladina atmosférického ozonu.
38
+
39
+ 11
40
+ 00:00:30,280 --> 00:00:33,200
41
+ Možná si to nebudete chtít přiznat,
42
+ ale jde o velice vážnou věc.
43
+
44
+ 12
45
+ 00:00:33,360 --> 00:00:35,000
46
+ Ach... jo... jasně.
47
+
48
+ 13
49
+ 00:00:35,320 --> 00:00:37,920
50
+ Globální oteplování, útok Wraithů.
51
+
52
+ 14
53
+ 00:00:38,200 --> 00:00:40,960
54
+ Když se nad tím zamyslím,
55
+ je tu jasná podobnost. Díky.
56
+
57
+ 15
58
+ 00:00:41,000 --> 00:00:43,000
59
+ Nechoďte moc daleko, doktore. OK?
60
+
61
+ 16
62
+ 00:00:43,080 --> 00:00:44,600
63
+ Žádný strach, majore!
64
+
65
+ 17
66
+ 00:00:44,760 --> 00:00:47,160
67
+ Nemyslím si, že by nějaké zvíře mohlo přežít
68
+
69
+ 18
70
+ 00:00:47,200 --> 00:00:50,720
71
+ dlouhodobé vystavení slunečnímu
72
+ záření na této planetě.
73
+
74
+ 18
75
+ 00:00:50,760 --> 00:00:52,400
76
+ Takže to nebude dobré
77
+ místo na letní sídlo.
78
+
79
+ 20
80
+ 00:00:53,960 --> 00:00:58,400
81
+ Po pravdě, vegetaci se tu daří velice dobře.
82
+
@@ -0,0 +1,104 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ end
30
+
31
+ # rspec-mocks config goes here. You can use an alternate test double
32
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
33
+ config.mock_with :rspec do |mocks|
34
+ # Prevents you from mocking or stubbing a method that does not exist on
35
+ # a real object. This is generally recommended, and will default to
36
+ # `true` in RSpec 4.
37
+ mocks.verify_partial_doubles = true
38
+ end
39
+
40
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
41
+ # have no way to turn it off -- the option exists only for backwards
42
+ # compatibility in RSpec 3). It causes shared context metadata to be
43
+ # inherited by the metadata hash of host groups and examples, rather than
44
+ # triggering implicit auto-inclusion in groups with matching metadata.
45
+ config.shared_context_metadata_behavior = :apply_to_host_groups
46
+
47
+ def fixture_file(name)
48
+ File.join(__dir__, "fixtures/files", name)
49
+ end
50
+
51
+ # The settings below are suggested to provide a good initial experience
52
+ # with RSpec, but feel free to customize to your heart's content.
53
+ =begin
54
+ # This allows you to limit a spec run to individual examples or groups
55
+ # you care about by tagging them with `:focus` metadata. When nothing
56
+ # is tagged with `:focus`, all examples get run. RSpec also provides
57
+ # aliases for `it`, `describe`, and `context` that include `:focus`
58
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
59
+ config.filter_run_when_matching :focus
60
+
61
+ # Allows RSpec to persist some state between runs in order to support
62
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
63
+ # you configure your source control system to ignore this file.
64
+ config.example_status_persistence_file_path = "spec/examples.txt"
65
+
66
+ # Limits the available syntax to the non-monkey patched syntax that is
67
+ # recommended. For more details, see:
68
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
69
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
70
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
71
+ config.disable_monkey_patching!
72
+
73
+ # This setting enables warnings. It's recommended, but in some cases may
74
+ # be too noisy due to issues in dependencies.
75
+ config.warnings = true
76
+
77
+ # Many RSpec users commonly either run the entire suite or an individual
78
+ # file, and it's useful to allow more verbose output when running an
79
+ # individual spec file.
80
+ if config.files_to_run.one?
81
+ # Use the documentation formatter for detailed output,
82
+ # unless a formatter has already been configured
83
+ # (e.g. via a command-line flag).
84
+ config.default_formatter = "doc"
85
+ end
86
+
87
+ # Print the 10 slowest examples and example groups at the
88
+ # end of the spec run, to help surface which specs are running
89
+ # particularly slow.
90
+ config.profile_examples = 10
91
+
92
+ # Run specs in random order to surface order dependencies. If you find an
93
+ # order dependency and want to debug it, you can fix the order by providing
94
+ # the seed, which is printed after each run.
95
+ # --seed 1234
96
+ config.order = :random
97
+
98
+ # Seed global randomization in this process using the `--seed` CLI option.
99
+ # Setting this allows you to use `--seed` to deterministically reproduce
100
+ # test failures related to randomization by passing the same `--seed` value
101
+ # as the one that triggered the failure.
102
+ Kernel.srand config.seed
103
+ =end
104
+ end
@@ -0,0 +1,27 @@
1
+ require 'srt_subtitle_validator/srt_block'
2
+
3
+ RSpec.describe SrtSubtitleValidator::SrtBlock do
4
+ let(:args) { "5\n00:00:14,120 --> 00:00:17,520\ntřista-třicet tři písmen" }
5
+ describe "initialize" do
6
+ subject { described_class.new(*args) }
7
+ context "one argument" do
8
+ it { is_expected.to have_attributes dialog_number: 5 }
9
+ end
10
+
11
+ context "three arguments" do
12
+ let(:args) { ["5", "00:00:14,120 --> 00:00:17,520", "třista-třicet tři písmen"] }
13
+ it { is_expected.to have_attributes dialog_number: 5 }
14
+ end
15
+
16
+ context "more arguments" do
17
+ let(:args) { %w[5 time x x x] }
18
+ it { expect { subject }.to raise_exception ArgumentError }
19
+ end
20
+ end
21
+
22
+ describe "#to_s" do
23
+ let(:entity) { described_class.new(*args)}
24
+ subject { entity.to_s }
25
+ it { is_expected.to eq "#{args}\n\n" }
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ require 'srt_subtitle_validator/srt_file'
2
+
3
+ RSpec.describe SrtSubtitleValidator::SrtFile do
4
+ let(:subtitle_file) { fixture_file("cp1250-crlf.srt") }
5
+ let(:entity) { described_class.new File.read(subtitle_file) }
6
+ describe "#valid?" do
7
+ subject { entity.valid? }
8
+ it "non-UTF8 file" do
9
+ expect { subject }.to raise_error ArgumentError, /invalid byte sequence/
10
+ end
11
+
12
+ context "utf8 file" do
13
+ let(:subtitle_file) { fixture_file("utf8-crlf.srt") }
14
+ it { is_expected.to eq true }
15
+ end
16
+
17
+ context "no srt file" do
18
+ let(:entity) { SrtSubtitleValidator::SrtFile.new"invalid file\n" }
19
+
20
+ it do
21
+ is_expected.to eq false
22
+ expect(entity.errors).to include "File is zero size"
23
+ end
24
+ end
25
+
26
+ context "missing block" do
27
+ let(:subtitle_file) { fixture_file("utf8-invalid-blocks.srt") }
28
+ it do
29
+ is_expected.to eq false
30
+ expect(entity.errors).to include "Numbers sequence is corrupted"
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,31 @@
1
+ require "fileutils"
2
+ require 'srt_subtitle_validator/validator'
3
+ require "tmpdir"
4
+
5
+ RSpec.describe SrtSubtitleValidator::Validator do
6
+ let(:subtitle_file) { fixture_file("cp1250-crlf.srt") }
7
+ let(:entity) { described_class.new subtitle_file }
8
+
9
+ it "parse cp1250 file" do
10
+ expect { entity.valid? }.not_to raise_exception
11
+ end
12
+
13
+ describe "#convert_srt" do
14
+ let(:output_file) { File.join(Dir.tmpdir, "output.srt") }
15
+ let(:entity) { described_class.new output_file }
16
+
17
+ context "with backup" do
18
+ subject { entity.convert_srt output_file }
19
+ before do
20
+ FileUtils.cp subtitle_file, output_file
21
+ end
22
+ it do
23
+ expect(entity).to receive(:backup_original_file).and_call_original
24
+ expect(entity).to receive(:recalculate_number_sequence).and_call_original
25
+ subject
26
+ expect(File).to exist output_file
27
+ expect(File).to exist "#{output_file}.1"
28
+ end
29
+ end
30
+ end
31
+ end