subtitle_it 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +19 -0
- data/History.txt +53 -0
- data/License.txt +20 -0
- data/Manifest.txt +68 -0
- data/README.markdown +41 -0
- data/README.txt +102 -0
- data/Rakefile +4 -0
- data/bin/subtitle_it +66 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/lib/subtitle_it/bin.rb +132 -0
- data/lib/subtitle_it/fixes.rb +12 -0
- data/lib/subtitle_it/formats/ass.rb +13 -0
- data/lib/subtitle_it/formats/mpl.rb +29 -0
- data/lib/subtitle_it/formats/rsb.rb +37 -0
- data/lib/subtitle_it/formats/srt.rb +45 -0
- data/lib/subtitle_it/formats/sub.rb +49 -0
- data/lib/subtitle_it/formats/xml.rb +65 -0
- data/lib/subtitle_it/formats/yml.rb +18 -0
- data/lib/subtitle_it/generator.rb +15 -0
- data/lib/subtitle_it/languages.rb +60 -0
- data/lib/subtitle_it/movie.rb +24 -0
- data/lib/subtitle_it/movie_hasher.rb +30 -0
- data/lib/subtitle_it/platform_endl.rb +9 -0
- data/lib/subtitle_it/subdown.rb +107 -0
- data/lib/subtitle_it/subline.rb +25 -0
- data/lib/subtitle_it/substyle.rb +11 -0
- data/lib/subtitle_it/subtime.rb +41 -0
- data/lib/subtitle_it/subtitle.rb +76 -0
- data/lib/subtitle_it/version.rb +9 -0
- data/lib/subtitle_it.rb +22 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/spec/fixtures/godfather.srt +2487 -0
- data/spec/fixtures/huge.ass +22 -0
- data/spec/fixtures/movie.xml +28 -0
- data/spec/fixtures/movie.yml +163 -0
- data/spec/fixtures/pseudo.rsb +6 -0
- data/spec/fixtures/pulpfiction.sub +2025 -0
- data/spec/fixtures/puplfiction.mpl +12 -0
- data/spec/fixtures/sincity.yml +12 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +71 -0
- data/spec/subtitle_it/bin_spec.rb +142 -0
- data/spec/subtitle_it/fixes_spec.rb +0 -0
- data/spec/subtitle_it/formats/ass_spec.rb +5 -0
- data/spec/subtitle_it/formats/mpl_spec.rb +45 -0
- data/spec/subtitle_it/formats/rsb_spec.rb +42 -0
- data/spec/subtitle_it/formats/srt_spec.rb +57 -0
- data/spec/subtitle_it/formats/sub_spec.rb +49 -0
- data/spec/subtitle_it/formats/xml_spec.rb +60 -0
- data/spec/subtitle_it/formats/yml_spec.rb +20 -0
- data/spec/subtitle_it/generator_spec.rb +0 -0
- data/spec/subtitle_it/movie_hasher_spec.rb +13 -0
- data/spec/subtitle_it/movie_spec.rb +25 -0
- data/spec/subtitle_it/subdown_spec.rb +94 -0
- data/spec/subtitle_it/subline_spec.rb +30 -0
- data/spec/subtitle_it/substyle_spec.rb +1 -0
- data/spec/subtitle_it/subtime_spec.rb +73 -0
- data/spec/subtitle_it/subtitle_spec.rb +40 -0
- data/spec/subtitle_it_spec.rb +11 -0
- data/subtitle_it.gemspec +41 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- metadata +152 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
[1025][1115]You always say that.|The same thing every time.
|
2
|
+
[1118][1177]"l'm through, never again,|too dangerous."
|
3
|
+
[1180][1270]I know that's what I always say.|I'm always right too.
|
4
|
+
[1274][1364]- You forget about it in a day or two.|- The days of me forgetting are over.
|
5
|
+
[1368][1428]The days of me remembering|have just begun.
|
6
|
+
[1430][1490]You know, when you go on like this,|what you sound like ?
|
7
|
+
[1493][1583]- I sound like a sensible fuckin' man.|- You sound like a duck.
|
8
|
+
[1587][1707]- Quack, quack, quack.|- Take heart, 'cause you're never
|
9
|
+
[1712][1802]Since I'm never gonna|do it again, you're never
|
10
|
+
[1806][1956]- After tonight ?|- Correct. I got all tonight to quack.
|
11
|
+
[1962][2022]- Can I get anyone more coffee ?|- Oh, yes !
|
12
|
+
[2087][2176]- Thank you.|- You're welcome.
|
@@ -0,0 +1,12 @@
|
|
1
|
+
header:
|
2
|
+
title: sincity
|
3
|
+
authors: warlley, nofxx
|
4
|
+
version: 1.1
|
5
|
+
|
6
|
+
lines:
|
7
|
+
- ['00:05:26.5', '00:05:28.5', 'worth killing for...']
|
8
|
+
- ['00:06:00.4', '00:06:03.4', 'worth dying for...']
|
9
|
+
- ['00:07:00.3', '00:07:03.3', 'worth going to the hell for...']
|
10
|
+
- ['00:07:00.3', '00:07:03.3', 'worth going a | line...']
|
11
|
+
|
12
|
+
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
begin
|
2
|
+
require 'spec'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
10
|
+
require 'subtitle_it'
|
11
|
+
include SubtitleIt
|
12
|
+
|
13
|
+
module SubFixtures
|
14
|
+
def sub_fixture
|
15
|
+
File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/pulpfiction.sub'))
|
16
|
+
end
|
17
|
+
|
18
|
+
def srt_fixture
|
19
|
+
File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/godfather.srt'))
|
20
|
+
end
|
21
|
+
|
22
|
+
def yml_fixture
|
23
|
+
File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/sincity.yml'))
|
24
|
+
end
|
25
|
+
|
26
|
+
def rsb_fixture
|
27
|
+
File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/pseudo.rsb'))
|
28
|
+
end
|
29
|
+
|
30
|
+
def xml_fixture
|
31
|
+
File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/movie.xml'))
|
32
|
+
end
|
33
|
+
|
34
|
+
def mpl_fixture
|
35
|
+
File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/puplfiction.mpl'))
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
# ##
|
41
|
+
# rSpec Hash additions.
|
42
|
+
#
|
43
|
+
# From
|
44
|
+
# * http://wincent.com/knowledge-base/Fixtures_considered_harmful%3F
|
45
|
+
# * Neil Rahilly
|
46
|
+
class Hash
|
47
|
+
##
|
48
|
+
# Filter keys out of a Hash.
|
49
|
+
#
|
50
|
+
# { :a => 1, :b => 2, :c => 3 }.except(:a)
|
51
|
+
# => { :b => 2, :c => 3 }
|
52
|
+
def except(*keys)
|
53
|
+
self.reject { |k,v| keys.include?(k || k.to_sym) }
|
54
|
+
end
|
55
|
+
##
|
56
|
+
# Override some keys.
|
57
|
+
#
|
58
|
+
# { :a => 1, :b => 2, :c => 3 }.with(:a => 4)
|
59
|
+
# => { :a => 4, :b => 2, :c => 3 }
|
60
|
+
def with(overrides = {})
|
61
|
+
self.merge overrides
|
62
|
+
end
|
63
|
+
##
|
64
|
+
# Returns a Hash with only the pairs identified by +keys+.
|
65
|
+
#
|
66
|
+
# { :a => 1, :b => 2, :c => 3 }.only(:a)
|
67
|
+
# => { :a => 1 }
|
68
|
+
def only(*keys)
|
69
|
+
self.reject { |k,v| !keys.include?(k || k.to_sym) }
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
module BinspecHelper
|
4
|
+
def mock_xmlrpc(stubs={}); @mock_xmlrpc ||= mock(XMLRPC::Client, stubs); end
|
5
|
+
def mock_subdown; @mock_subdown = mock(Subdown); end
|
6
|
+
def mock_file; @mock_file = mock(File); end
|
7
|
+
|
8
|
+
def mock_movie
|
9
|
+
@mock_movie = mock(Movie, {:filename => "Beavis Butthead Do America.avi",
|
10
|
+
:haxx => '09a2c497663259cb' })
|
11
|
+
end
|
12
|
+
|
13
|
+
def mock_subtitle
|
14
|
+
@mock_subtitle = mock(Subtitle, {
|
15
|
+
:info => sub_info, :format => 'srt', :<=> => 1
|
16
|
+
})
|
17
|
+
end
|
18
|
+
|
19
|
+
def sub_info
|
20
|
+
{
|
21
|
+
"SubLanguageID" => 'eng',
|
22
|
+
"MovieName" => 'Resevoir Dogs',
|
23
|
+
"MovieYear" => '1992',
|
24
|
+
"SubFileName" => 'Cool sub',
|
25
|
+
"MovieImdbRating" => '10.0',
|
26
|
+
"SubDownloadsCnt" => '310',
|
27
|
+
"SubRating" => '9.5',
|
28
|
+
"SubFormat" => 'srt',
|
29
|
+
"SubSumCD" => '2',
|
30
|
+
"SubAuthorComment" => 'Nice nice...'
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe Bin do
|
36
|
+
include BinspecHelper
|
37
|
+
|
38
|
+
it "should require ARGV" do
|
39
|
+
lambda { Bin::run!(nil) }.should raise_error
|
40
|
+
end
|
41
|
+
|
42
|
+
# Having a hard time testing the command line tool...
|
43
|
+
# #
|
44
|
+
#
|
45
|
+
# it "should call for movie" do
|
46
|
+
# Subdownloader.should_receive(:new)
|
47
|
+
# File.should_receive(:exists?).and_return(true)
|
48
|
+
# File.should_receive(:open).and_return(mock_file)
|
49
|
+
# SubtitleIt::Bin::run!(["movie.avi"])
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# it "should call for subtitle" do
|
53
|
+
# @subwork_mock = mock(Subwork, :run! => true)#.should_receive(:new)
|
54
|
+
# @subwork_mock.should_receive(:new)
|
55
|
+
# @subwork_mock.should_receive(:run!)
|
56
|
+
# File.should_receive(:exists?).and_return(true)
|
57
|
+
# SubtitleIt::Bin::run!(["movie.srt"])
|
58
|
+
# end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe Subdownloader do
|
62
|
+
include BinspecHelper
|
63
|
+
|
64
|
+
it "should print languages" do
|
65
|
+
STDOUT.should_receive(:puts).at_least(30).times
|
66
|
+
SubtitleIt::Bin.print_languages
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should download a subtitle" do
|
70
|
+
Movie.should_receive(:new).and_return(mock_movie)
|
71
|
+
Subdown.should_receive(:new).and_return(mock_subdown)#mock(Subdown))
|
72
|
+
|
73
|
+
STDIN.should_receive(:gets).and_return("1")
|
74
|
+
STDOUT.should_receive(:puts).with("Found 2 results. Choose one:\n")
|
75
|
+
STDOUT.should_receive(:printf).with("Choose: ")
|
76
|
+
STDOUT.should_receive(:puts).with("You can choose multiple ones, separated with spaces or a range separated with hifen.")
|
77
|
+
STDOUT.should_receive(:puts).with("Downloading 1 subtitles...")
|
78
|
+
STDOUT.should_receive(:puts).with("1) Resevoir Dogs / 1992 | Cool sub | Movie score: 10.0\n Lang: Eng | Format: SRT | Downloads: 310 | Rating: 9.5 | CDs: 2\n Comments: Nice nice... \n\n")
|
79
|
+
STDOUT.should_receive(:puts).with("2) Resevoir Dogs / 1992 | Cool sub | Movie score: 10.0\n Lang: Eng | Format: SRT | Downloads: 310 | Rating: 9.5 | CDs: 2\n Comments: Nice nice... \n\n")
|
80
|
+
STDOUT.should_receive(:puts).with("Done. Wrote: Beavis Butthead Do America.srt.")
|
81
|
+
|
82
|
+
File.should_receive(:open).with("Beavis Butthead Do America.srt", "w").and_return(true)
|
83
|
+
|
84
|
+
@mock_subdown.should_receive(:log_in!).and_return(true)
|
85
|
+
@mock_subdown.should_receive(:download_subtitle).and_return(mock_subtitle)
|
86
|
+
@mock_subdown.should_receive(:search_subtitles).and_return([mock_subtitle, mock_subtitle])
|
87
|
+
@mock_subdown.should_receive(:log_out!).and_return(true)
|
88
|
+
|
89
|
+
Subdownloader.new.run! "file.avi"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should get extension files" do
|
93
|
+
Bin.get_extension("Lots.of.dots.happen").should eql("happen")
|
94
|
+
lambda { Bin.get_extension("Nodotstoo") }.should raise_error
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should swap extensions" do
|
98
|
+
Bin.swap_extension("foo.txt", "srt").should eql("foo.srt")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should parse user input" do
|
102
|
+
@subd = Subdownloader.new
|
103
|
+
@subd.parse_input("1 2-5 7 8-10 15").should eql([1, 2, 3, 4, 5, 7, 8, 9, 10, 15])
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should print choice" do
|
107
|
+
@sub = mock(Subtitle, :info => sub_info)
|
108
|
+
@subd = Subdownloader.new
|
109
|
+
@subd.print_option(@sub, 1).should eql("2) Resevoir Dogs / 1992 | Cool sub | Movie score: 10.0
|
110
|
+
Lang: Eng | Format: SRT | Downloads: 310 | Rating: 9.5 | CDs: 2
|
111
|
+
Comments: Nice nice... \n\n")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe Subwork do
|
116
|
+
include BinspecHelper
|
117
|
+
|
118
|
+
it "should call a new subtitle" do
|
119
|
+
File.should_receive(:open).with("file.srt", "r").and_return(mock_file)
|
120
|
+
File.should_receive(:open).with("file.sub", "w").and_return(true)
|
121
|
+
|
122
|
+
STDOUT.should_receive(:puts).with("Working on file file.srt...")
|
123
|
+
STDOUT.should_receive(:puts).with('Done. Wrote: file.sub.')
|
124
|
+
|
125
|
+
Subtitle.should_receive(:new).and_return(mock_subtitle)
|
126
|
+
@mock_subtitle.should_receive(:to_sub).and_return('subbb')
|
127
|
+
|
128
|
+
Subwork.new.run!("file.srt", "sub")
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should not write if file exists" do
|
132
|
+
File.should_receive(:open).with("file.srt", "r").and_return(mock_file)
|
133
|
+
File.should_receive(:exists?).and_return(true)
|
134
|
+
|
135
|
+
STDOUT.should_receive(:puts).with("Working on file file.srt...")
|
136
|
+
STDOUT.should_receive(:puts).with("File exists. file.sub")
|
137
|
+
|
138
|
+
Subtitle.should_receive(:new).and_return(mock_subtitle)
|
139
|
+
@mock_subtitle.should_receive(:to_sub).and_return('subbb')
|
140
|
+
Subwork.new.run!("file.srt", "sub")
|
141
|
+
end
|
142
|
+
end
|
File without changes
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Formats, ".mpl" do
|
4
|
+
include SubFixtures
|
5
|
+
describe "In" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@mpl = Subtitle.new({:dump => mpl_fixture, :format => 'mpl'})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse the sub to an array" do
|
12
|
+
@mpl.lines.should be_instance_of(Array)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have N lines" do
|
16
|
+
@mpl.should have(12).lines
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should parse time of" do
|
20
|
+
@mpl.lines[0].time_on.to_s.should eql("00:17:05.000")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should parse time of" do
|
24
|
+
@mpl.lines[0].time_off.to_s.should eql("00:18:35.000")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should parse text" do
|
28
|
+
@mpl.lines[0].text.should eql("You always say that.|The same thing every time.")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "Out!" do
|
33
|
+
|
34
|
+
before(:each) do
|
35
|
+
@sub = Subtitle.new({:dump => yml_fixture, :format => 'yml'})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should dump the object as a SRT" do
|
39
|
+
@sub.to_mpl.should eql("[3265][3285]worth killing for...
|
40
|
+
[3604][3634]worth dying for...
|
41
|
+
[4203][4233]worth going to the hell for...
|
42
|
+
[4203][4233]worth going a | line...\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Formats, ".rsb" do
|
4
|
+
include SubFixtures
|
5
|
+
describe "In" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@rsb = Subtitle.new({:dump => rsb_fixture, :format => 'rsb'})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse the sub to an array" do
|
12
|
+
@rsb.lines.should be_instance_of(Array)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have N lines" do
|
16
|
+
@rsb.should have(3).lines
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should parse time of" do
|
20
|
+
@rsb.lines[0].time_on.to_s.should eql("00:05:26.500")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should parse time of" do
|
24
|
+
@rsb.lines[0].time_off.to_s.should eql("00:05:28.500")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should parse text" do
|
28
|
+
@rsb.lines[0].text.should eql("worth killing for...")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "Out" do
|
33
|
+
include SubFixtures
|
34
|
+
before(:each) do
|
35
|
+
@sub = Subtitle.new({:dump => yml_fixture, :format => 'yml'})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should dump the object to rsb" do
|
39
|
+
@sub.to_rsb.should eql("- title: sincity\n- authors: \n- version: 1.1\n00:05:26.500 => 00:05:28.500 == worth killing for...\n00:06:00.400 => 00:06:03.400 == worth dying for...\n00:07:00.300 => 00:07:03.300 == worth going to the hell for...\n00:07:00.300 => 00:07:03.300 == worth going a | line...\n")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Formats, ".srt" do
|
4
|
+
include SubFixtures
|
5
|
+
describe "In" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@srt = Subtitle.new({:dump => srt_fixture, :format => 'srt'})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse the sub to an array" do
|
12
|
+
@srt.lines.should be_instance_of(Array)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have N lines" do
|
16
|
+
@srt.should have(543).lines
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should parse time of" do
|
20
|
+
@srt.lines[0].time_on.to_s.should eql("00:01:43.680")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should parse time of" do
|
24
|
+
@srt.lines[0].time_off.to_s.should eql("00:01:45.557")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should parse text" do
|
28
|
+
@srt.lines[0].text.should eql("My dear children,")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "Out!" do
|
33
|
+
|
34
|
+
before(:each) do
|
35
|
+
@sub = Subtitle.new({:dump => yml_fixture, :format => 'yml'})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should dump the object as a SRT" do
|
39
|
+
@sub.to_srt.should eql("1
|
40
|
+
00:05:26,500 --> 00:05:28,500
|
41
|
+
worth killing for...
|
42
|
+
|
43
|
+
2
|
44
|
+
00:06:00,400 --> 00:06:03,400
|
45
|
+
worth dying for...
|
46
|
+
|
47
|
+
3
|
48
|
+
00:07:00,300 --> 00:07:03,300
|
49
|
+
worth going to the hell for...
|
50
|
+
|
51
|
+
4
|
52
|
+
00:07:00,300 --> 00:07:03,300
|
53
|
+
worth going a
|
54
|
+
line...\n")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Formats, ".sub" do
|
4
|
+
include SubFixtures
|
5
|
+
describe "Parse" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@sub = Subtitle.new({:dump => sub_fixture, :format => 'sub'})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should parse the sub to an array" do
|
12
|
+
@sub.lines.should be_instance_of(Array)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have N lines" do
|
16
|
+
@sub.should have(2025).lines
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have a nic text on" do
|
20
|
+
@sub.lines[110].time_on.to_s.should eql('00:10:44.936')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have a nice text out" do
|
24
|
+
@sub.lines[110].time_off.to_s.should eql('00:10:49.941')
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should parse the sentece correctly" do
|
28
|
+
@sub.lines[0].text.should eql("You always say that.|The same thing every time.")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should parse the sentece correctly" do
|
32
|
+
@sub.lines[2020].text.should eql("I'm tryin' real hard...")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "Out" do
|
37
|
+
|
38
|
+
before(:each) do
|
39
|
+
@sub = Subtitle.new({:dump => yml_fixture, :format => 'yml'})
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should dump the object as a SUB" do
|
43
|
+
@sub.to_sub.should eql("{7816}{7864}worth killing for...
|
44
|
+
{8631}{8703}worth dying for...
|
45
|
+
{10069}{10141}worth going to the hell for...
|
46
|
+
{10069}{10141}worth going a | line...\n")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Formats, ".xml" do
|
4
|
+
include SubFixtures
|
5
|
+
describe "In" do
|
6
|
+
before(:each) do
|
7
|
+
@xml = Subtitle.new({:dump => xml_fixture, :format => 'xml'})
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should parse the sub to an array" do
|
11
|
+
@xml.lines.should be_instance_of(Array)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should have N lines" do
|
15
|
+
@xml.should have(13).lines
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should parse time of" do
|
19
|
+
@xml.lines[0].time_on.to_s.should eql("00:00:00.000")
|
20
|
+
@xml.lines[10].time_on.to_s.should eql("00:00:25.520")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should parse time of" do
|
24
|
+
@xml.lines[0].time_off.to_s.should eql("00:00:03.700")
|
25
|
+
@xml.lines[10].time_off.to_s.should eql("00:00:27.520")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should parse text" do
|
29
|
+
@xml.lines[0].text.should eql("I had just joined <span tts:fontSize=\"+2\" tts:fontFamily=\"monospaceSansSerif,proportionalSerif,TheOther\">Macromedia</span> in 1996,")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "Out" do
|
34
|
+
before(:each) do
|
35
|
+
@sub = Subtitle.new({:dump => yml_fixture, :format => 'yml'})
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should parse the sub to an array" do
|
39
|
+
@sub.to_xml.should be_instance_of(String)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should equal..." do
|
43
|
+
@sub.to_xml.should eql("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
44
|
+
<tt xml:lang=\"en\" xmlns=\"http://www.w3.org/2006/04/ttaf1\" xmlns:tts=\"http://www.w3.org/2006/04/ttaf1#styling\">
|
45
|
+
<head>
|
46
|
+
<styling>
|
47
|
+
</styling>
|
48
|
+
</head>
|
49
|
+
<body>
|
50
|
+
<div xml:lang=\"en\">
|
51
|
+
<p begin=\"00:05:26.500\" dur=\"00:00:02.000\">worth killing for...</p>
|
52
|
+
<p begin=\"00:06:00.400\" dur=\"00:00:03.000\">worth dying for...</p>
|
53
|
+
<p begin=\"00:07:00.300\" dur=\"00:00:03.000\">worth going to the hell for...</p>
|
54
|
+
<p begin=\"00:07:00.300\" dur=\"00:00:03.000\">worth going a | line...</p>
|
55
|
+
</div>
|
56
|
+
</body>
|
57
|
+
</tt>")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe Formats, ".yml" do
|
4
|
+
describe "Out" do
|
5
|
+
include SubFixtures
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@sub = Subtitle.new({:dump => yml_fixture, :format => 'yml'})
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should have author" do
|
12
|
+
@sub.to_yml.should match(/author: warlley, nofxx/)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have version" do
|
16
|
+
@sub.to_yml.should match(/version: 1.1/)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe MovieHasher do
|
4
|
+
|
5
|
+
it "should generate a beatiful hash for us" do
|
6
|
+
MovieHasher::CHUNK_SIZE.should eql(65536)
|
7
|
+
|
8
|
+
File.should_receive(:size).with('onefile').and_return(1020)
|
9
|
+
File.should_receive(:open).with("onefile", "rb")
|
10
|
+
|
11
|
+
MovieHasher.compute_haxx('onefile').should eql("00000000000003fc")
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Movie do
|
4
|
+
before(:each) do
|
5
|
+
@movie = Movie.new('pulpfiction')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should initialize nicely" do
|
9
|
+
@movie.info.should be_instance_of(Hash)
|
10
|
+
@movie.filename.should eql("pulpfiction")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should call for a hash" do
|
14
|
+
File.should_receive(:open).with("pulpfiction", "rb")
|
15
|
+
File.should_receive(:size).with('pulpfiction').and_return(13141)
|
16
|
+
#TODO.. how to mock this?
|
17
|
+
#MovieHasher.should_receive(:compute_hash)
|
18
|
+
@movie.haxx.should eql('0000000000003355')
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should call for size" do
|
22
|
+
File.should_receive(:size).with('pulpfiction')
|
23
|
+
@movie.size
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
module SubdownHelper
|
4
|
+
def mock_xmlrpc(stubs={})
|
5
|
+
@mock_xmlrpc ||= mock(XMLRPC::Client, stubs)#, @auth=nil, @parser=nil, @user=nil, @timeout=30, @cookie=nil, @http=#<Net::HTTP www.opensubtitles.org:80 open=false>, @use_ssl=false, @http_last_response=nil, @port=80, @host="www.opensubtitles.org", @path="/xml-rpc", @http_header_extra=nil, @create=nil, @password=nil, @proxy_port=nil, @proxy_host=nil>
|
6
|
+
end
|
7
|
+
def mock_movie
|
8
|
+
@mock_movie = mock(Movie, :haxx => '09a2c497663259cb')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
describe Subdown do
|
14
|
+
include SubdownHelper
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
@sub = mock(Subtitle)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should initialize nicely" do
|
21
|
+
XMLRPC::Client.should_receive(:new2)
|
22
|
+
@down = Subdown.new
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should log in!" do
|
26
|
+
XMLRPC::Client.should_receive(:new2).with('http://www.opensubtitles.org/xml-rpc').and_return(mock_xmlrpc)
|
27
|
+
@mock_xmlrpc.should_receive(:call).with("LogIn", "", "", "", "SubtitleIt #{SubtitleIt::VERSION::STRING}").and_return({
|
28
|
+
"status"=>"200 OK",
|
29
|
+
"seconds"=>0.004,
|
30
|
+
"token"=>"shkuj98gcvu5gp1b5tlo8uq525"
|
31
|
+
})
|
32
|
+
@down = Subdown.new
|
33
|
+
@down.should_not be_logged_in
|
34
|
+
@down.log_in!
|
35
|
+
@down.should be_logged_in
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should raise if connection sux" do
|
39
|
+
XMLRPC::Client.should_receive(:new2).with('http://www.opensubtitles.org/xml-rpc').and_return(mock_xmlrpc)
|
40
|
+
@mock_xmlrpc.should_receive(:call).with("LogIn", "", "", "", "SubtitleIt #{SubtitleIt::VERSION::STRING}").and_return({
|
41
|
+
"status"=>"404 FAIL",
|
42
|
+
"seconds"=>0.004,
|
43
|
+
"token"=>""
|
44
|
+
})
|
45
|
+
@down = Subdown.new
|
46
|
+
lambda { @down.log_in! }.should raise_error
|
47
|
+
@down.should_not be_logged_in
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
describe "Instantiate" do
|
52
|
+
before(:each) do
|
53
|
+
@down = Subdown.new
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should get subtitle languages" do
|
57
|
+
@down.subtitle_languages.should be_instance_of(Array)
|
58
|
+
@down.subtitle_languages.length.should eql(51)
|
59
|
+
@down.subtitle_languages[0].should be_instance_of(String)
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# REAL TESTS THAT USES THE INTERNET... DUNNO BETTER PRACTICE FOR THIS
|
66
|
+
# Mock is nice, but I would like to keep this here, who knows if
|
67
|
+
# Opensubtitle API changes.... any suggestions?
|
68
|
+
#
|
69
|
+
# #
|
70
|
+
# describe Subdown, " - Wired tests" do
|
71
|
+
# before(:each) do
|
72
|
+
# @down = Subdown.new
|
73
|
+
# @movie = mock(Movie, :haxx => '09a2c497663259cb')
|
74
|
+
# @down.log_in!
|
75
|
+
# end
|
76
|
+
#
|
77
|
+
# it "should get imdb info" do
|
78
|
+
# @movie.should_receive('info=').with({"MovieYear"=>"2004",
|
79
|
+
# "MovieImdbID"=>"403358",
|
80
|
+
# "MovieName"=>"Nochnoy dozor",
|
81
|
+
# "MovieHash"=>"09a2c497663259cb"})
|
82
|
+
# @down.imdb_info(@movie)
|
83
|
+
# end
|
84
|
+
#
|
85
|
+
# it "should search subs info" do
|
86
|
+
#
|
87
|
+
# @movie.stub!(:size).and_return(733589504)
|
88
|
+
# res = @down.search_subtitles(@movie, 'pt')
|
89
|
+
# res.should be_instance_of(Array)
|
90
|
+
# res.each do |r|
|
91
|
+
# r.should be_instance_of(Subtitle)
|
92
|
+
# end
|
93
|
+
# end
|
94
|
+
# end
|