warlley-subtitle_it 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/subtitle_it/bin.rb +32 -23
- data/lib/subtitle_it/formats/srt.rb +3 -3
- data/lib/subtitle_it/formats/sub.rb +12 -10
- data/lib/subtitle_it/formats/xml.rb +0 -1
- data/lib/subtitle_it/subdown.rb +1 -1
- data/lib/subtitle_it/subtitle.rb +8 -2
- data/lib/subtitle_it/version.rb +1 -1
- data/spec/spec_helper.rb +34 -0
- data/spec/subtitle_it/bin_spec.rb +97 -23
- data/spec/subtitle_it/formats/mpl_spec.rb +2 -2
- data/spec/subtitle_it/formats/rsb_spec.rb +2 -2
- data/spec/subtitle_it/formats/srt_spec.rb +18 -3
- data/spec/subtitle_it/formats/sub_spec.rb +2 -2
- data/spec/subtitle_it/formats/xml_spec.rb +2 -2
- data/spec/subtitle_it/formats/yml_spec.rb +1 -1
- data/spec/subtitle_it/subtitle_spec.rb +38 -0
- data/spec/subtitle_it_spec.rb +1 -1
- data/subtitle_it.gemspec +1 -1
- metadata +1 -1
data/lib/subtitle_it/bin.rb
CHANGED
@@ -3,13 +3,13 @@
|
|
3
3
|
module SubtitleIt
|
4
4
|
|
5
5
|
class Subwork
|
6
|
-
def run!(file,
|
7
|
-
|
8
|
-
content = File.open(
|
9
|
-
puts "Working on file #{
|
10
|
-
sub = Subtitle.new(content,
|
6
|
+
def run!(file, format)
|
7
|
+
raise unless format
|
8
|
+
content = File.open(file, 'r')
|
9
|
+
puts "Working on file #{file}..."
|
10
|
+
sub = Subtitle.new(nil, content, Bin.get_extension(file))
|
11
11
|
dump = sub.send :"to_#{format}"
|
12
|
-
Bin::write_out(file
|
12
|
+
Bin::write_out(Bin.swap_extension(file, format), dump)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -20,14 +20,13 @@ module SubtitleIt
|
|
20
20
|
@down.log_in!
|
21
21
|
res = @down.search_subtitles(@movie)
|
22
22
|
puts "Found #{res.length} result#{"s" if res.length > 1}. Choose one:\n"
|
23
|
-
res.each_with_index { |r,i| puts
|
23
|
+
res.sort.each_with_index { |r,i| puts print_option(r,i) }
|
24
24
|
puts "You can choose multiple ones, separated with spaces or a range separated with hifen."
|
25
25
|
printf "Choose: "
|
26
26
|
choose = parse_input(STDIN.gets.chomp)
|
27
27
|
choose = choose.map { |c| res[c.to_i-1] }
|
28
28
|
puts "Downloading #{choose.length} subtitles..."
|
29
29
|
choose.each do |sub|
|
30
|
-
puts "#{sub.inspect}"
|
31
30
|
down_a_sub(sub, sub.format)
|
32
31
|
end
|
33
32
|
@down.log_out!
|
@@ -35,11 +34,11 @@ module SubtitleIt
|
|
35
34
|
|
36
35
|
def down_a_sub(sub, format)
|
37
36
|
dump = @down.download_subtitle(sub)
|
38
|
-
movie_name =
|
39
|
-
Bin::write_out(
|
37
|
+
movie_name = @movie.filename[0..-4]
|
38
|
+
Bin::write_out(movie_name + format, dump)
|
40
39
|
end
|
41
40
|
|
42
|
-
def
|
41
|
+
def print_option(r, index)
|
43
42
|
c = "#{index+1}) #{r.info["MovieName"]} / #{r.info["MovieYear"]} | #{r.info["SubFileName"]} | Movie score: #{r.info["MovieImdbRating"]}\n"
|
44
43
|
c << " Lang: #{r.info["SubLanguageID"].capitalize} | Format: #{r.info["SubFormat"].upcase} | Downloads: #{r.info["SubDownloadsCnt"]} | Rating: #{r.info["SubRating"]} | CDs: #{r.info["SubSumCD"]}\n"
|
45
44
|
c << " Comments: #{r.info["SubAuthorComment"]} \n\n"
|
@@ -61,15 +60,22 @@ module SubtitleIt
|
|
61
60
|
class Bin
|
62
61
|
|
63
62
|
def Bin.run! argv, format=nil, force=false, delay=nil
|
64
|
-
# SubtitleIt::Bin.new.run!(argv, format, force, delay)
|
65
63
|
raise unless argv
|
64
|
+
@force = force
|
65
|
+
@format = format
|
66
|
+
|
66
67
|
if File.exists?(argv[0]) # && ( argv[1] || format )
|
67
|
-
@file_in
|
68
|
-
@
|
68
|
+
@file_in = argv[0]
|
69
|
+
@file_in_ext = Bin.get_extension(@file_in)
|
70
|
+
if argv[1]
|
71
|
+
@file_out = argv[1]
|
72
|
+
@file_out_ext = Bin.get_extension(@file_out)
|
73
|
+
@format = @file_out_ext
|
74
|
+
end
|
69
75
|
if MOVIE_EXTS.include? @file_in_ext
|
70
|
-
Subdownloader.new.run!(argv[0])
|
76
|
+
Subdownloader.new.run!(argv[0])
|
71
77
|
elsif SUB_EXTS.include? @file_in_ext
|
72
|
-
Subwork.new.run!(@file_in, @
|
78
|
+
Subwork.new.run!(@file_in, @format)
|
73
79
|
else
|
74
80
|
raise "Unknown file."
|
75
81
|
end
|
@@ -81,16 +87,19 @@ module SubtitleIt
|
|
81
87
|
exit 1
|
82
88
|
end
|
83
89
|
|
84
|
-
def Bin.
|
90
|
+
def Bin.get_extension(file)
|
85
91
|
raise unless file =~ /\./
|
86
|
-
file
|
87
|
-
ext = file.delete_at(-1)
|
88
|
-
file = file.join('.')
|
89
|
-
[file, ext]
|
92
|
+
file.split(".").last
|
90
93
|
end
|
91
94
|
|
92
|
-
def Bin.
|
93
|
-
|
95
|
+
def Bin.swap_extension(file,extension)
|
96
|
+
f = file.dup
|
97
|
+
f[-3..-1] = extension
|
98
|
+
f
|
99
|
+
end
|
100
|
+
|
101
|
+
def Bin.write_out(filename,dump)
|
102
|
+
if File.exists?(filename) && !@force
|
94
103
|
puts "File exists. #{filename}"
|
95
104
|
else
|
96
105
|
File.open(filename, 'w') {|f| f.write(dump) }
|
@@ -24,9 +24,9 @@ module SubtitleIt
|
|
24
24
|
def to_srt
|
25
25
|
out = []
|
26
26
|
@lines.each_with_index do |l,i|
|
27
|
-
out << "#{i}"
|
28
|
-
out << "%s --> %s" % [l.time_on.to_s, l.time_off.to_s]
|
29
|
-
out << l.text.gsub("|","\n")
|
27
|
+
out << "#{i+1}"
|
28
|
+
out << "%s --> %s" % [l.time_on.to_s(','), l.time_off.to_s(',')]
|
29
|
+
out << l.text.gsub("|","\n") + "\n"
|
30
30
|
end
|
31
31
|
out.join("\n")
|
32
32
|
end
|
@@ -19,27 +19,29 @@ module SubtitleIt
|
|
19
19
|
module Formats
|
20
20
|
#between our formats, what changes can be reduced to a value
|
21
21
|
def ratio
|
22
|
-
1
|
23
|
-
|
22
|
+
1
|
24
23
|
end
|
25
|
-
|
26
|
-
|
24
|
+
|
27
25
|
def parse_sub
|
28
26
|
@raw.to_a.inject([]) do |i,l|
|
29
27
|
line_data = l.scan(/^\{([0-9]{1,})\}\{([0-9]{1,})\}(.+)$/)
|
30
28
|
line_data = line_data.at 0
|
31
29
|
time_on, time_off, text = line_data
|
32
|
-
time_on, time_off = [time_on.to_i, time_off.to_i].map
|
30
|
+
time_on, time_off = [time_on.to_i, time_off.to_i].map do |t|
|
31
|
+
(t.to_i / @fps * 1000 / ratio).to_i
|
32
|
+
end
|
33
33
|
i << Subline.new(time_on, time_off, text.chomp)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
def to_sub
|
38
38
|
@lines.inject([]) do |i,l|
|
39
|
-
|
40
|
-
stop = l.time_off.to_i / 1000 * @fps * ratio
|
41
|
-
i << "{%d}{%d}%s" % [start, stop, l.text]
|
39
|
+
i << "{%d}{%d}%s" % [parse_time(l.time_on), parse_time(l.time_off), l.text]
|
42
40
|
end.join("\r\n")
|
43
|
-
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def parse_time(n)
|
44
|
+
n.to_i / 1000 * @fps * ratio
|
45
|
+
end
|
44
46
|
end
|
45
|
-
end
|
47
|
+
end
|
data/lib/subtitle_it/subdown.rb
CHANGED
@@ -48,7 +48,7 @@ module SubtitleIt
|
|
48
48
|
result = call('SearchSubtitles', [args])
|
49
49
|
return [] unless result['data'] # if no results result['data'] == false
|
50
50
|
result['data'].inject([]) do |subs, sub_info|
|
51
|
-
subs << Subtitle.new(
|
51
|
+
subs << Subtitle.new(sub_info)
|
52
52
|
subs
|
53
53
|
end
|
54
54
|
end
|
data/lib/subtitle_it/subtitle.rb
CHANGED
@@ -12,13 +12,14 @@ module SubtitleIt
|
|
12
12
|
SUB_EXTS = %w(srt sub smi txt ssa ass mpl xml yml rsb)
|
13
13
|
|
14
14
|
class Subtitle
|
15
|
-
attr_reader :id, :raw, :format, :lines, :style, :info, :filename
|
15
|
+
attr_reader :id, :raw, :format, :lines, :style, :info, :filename, :rating
|
16
16
|
|
17
|
-
def initialize(
|
17
|
+
def initialize(info=nil,dump=nil,format=nil)
|
18
18
|
if @info = info
|
19
19
|
@id = info['IDSubtitleFile'].to_i
|
20
20
|
@filename = info['SubFileName'].to_s
|
21
21
|
@format = info['SubFormat'].to_s
|
22
|
+
@rating = info['SubRating'].to_f
|
22
23
|
end
|
23
24
|
@fps=23.976
|
24
25
|
parse_dump(dump,format) if dump
|
@@ -42,6 +43,11 @@ module SubtitleIt
|
|
42
43
|
def data=(data)
|
43
44
|
@raw = data
|
44
45
|
end
|
46
|
+
|
47
|
+
def <=>(other)
|
48
|
+
self.rating <=> other.rating
|
49
|
+
end
|
50
|
+
include Comparable
|
45
51
|
|
46
52
|
private
|
47
53
|
|
data/lib/subtitle_it/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -34,4 +34,38 @@ module SubFixtures
|
|
34
34
|
def mpl_fixture
|
35
35
|
File.open(File.expand_path(File.dirname(__FILE__) + '/fixtures/puplfiction.mpl'))
|
36
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
|
37
71
|
end
|
@@ -5,11 +5,18 @@ module BinspecHelper
|
|
5
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
6
|
end
|
7
7
|
def mock_movie
|
8
|
-
@mock_movie = mock(Movie, :
|
8
|
+
@mock_movie = mock(Movie, {:filename => "Beavis Butthead Do America",
|
9
|
+
:haxx => '09a2c497663259cb' })
|
9
10
|
end
|
10
11
|
def mock_subdown
|
11
12
|
@mock_subdown = mock(Subdown)
|
12
13
|
end
|
14
|
+
def mock_subtitle
|
15
|
+
@mock_subtitle = mock(Subtitle)
|
16
|
+
end
|
17
|
+
def mock_file
|
18
|
+
@mock_file = mock(File)
|
19
|
+
end
|
13
20
|
end
|
14
21
|
|
15
22
|
describe Bin do
|
@@ -19,33 +26,78 @@ describe Bin do
|
|
19
26
|
lambda { Bin::run!(nil) }.should raise_error
|
20
27
|
end
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
# Having a hard time testing the command line tool...
|
30
|
+
# it "should call for movie" do
|
31
|
+
# Subdownloader.should_receive(:new)
|
32
|
+
# File.should_receive(:exists?).and_return(true)
|
33
|
+
# File.should_receive(:open).and_return(mock_file)
|
34
|
+
# SubtitleIt::Bin::run!(["movie.avi"])
|
35
|
+
# end
|
36
|
+
#
|
37
|
+
# it "should call for subtitle" do
|
38
|
+
# @subwork_mock = mock(Subwork, :run! => true)#.should_receive(:new)
|
39
|
+
# @subwork_mock.should_receive(:new)
|
40
|
+
# @subwork_mock.should_receive(:run!)
|
41
|
+
# File.should_receive(:exists?).and_return(true)
|
42
|
+
# SubtitleIt::Bin::run!(["movie.srt"])
|
43
|
+
# end
|
27
44
|
end
|
28
45
|
|
29
46
|
describe Subdownloader do
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
47
|
+
include BinspecHelper
|
48
|
+
# this crashes autotest...
|
49
|
+
# it "should fetch subtitles" do
|
50
|
+
# Movie.should_receive(:new).and_return(mock_movie)
|
51
|
+
# File.should_receive(:exists?).and_return(true)
|
52
|
+
# File.should_receive(:size).with('file.avi').and_return(1020)
|
53
|
+
# File.should_receive(:open).with("file.avi", "rb")
|
54
|
+
# Subdown.should_receive(:new).and_return(mock_subdown)#mock(Subdown))
|
55
|
+
# @mock_subdown.should_receive(:log_in!).and_return(true)
|
56
|
+
# @mock_subdown.should_receive(:search_subtitles).and_return([])
|
57
|
+
# Subdownloader.new.run! "file.avi"
|
58
|
+
# end
|
59
|
+
# it "should down a sub!" do
|
60
|
+
#
|
61
|
+
# Movie.should_receive(:new).and_return(mock_movie)
|
62
|
+
# Subdown.should_receive(:new).and_return(mock_subdown)
|
63
|
+
# Subtitle.should_receive(:new).and_return(mock_subtitle)
|
64
|
+
# STDIN.should_receive(:gets).and_return("1")
|
65
|
+
# #@mock_movie.should_receive(:size).and_return(1313)
|
66
|
+
# #@mock_movie.should_receive(:filename).and_return("Beavis and Butthead do America")
|
67
|
+
# #@mock_movie.should_receive(:filename).and_return("Beavis and Butthead do America")
|
68
|
+
# @mock_subtitle.should_receive(:info).and_return({
|
69
|
+
# "SubLanguageID" => 'eng',
|
70
|
+
# "MovieName" => 'Resevoir Dogs',
|
71
|
+
# "MovieYear" => '1992',
|
72
|
+
# "SubFileName" => 'Cool sub',
|
73
|
+
# "MovieImdbRating" => '10.0',
|
74
|
+
# "SubDownloadsCnt" => '310',
|
75
|
+
# "SubRating" => '9.5',
|
76
|
+
# "SubFormat" => 'srt',
|
77
|
+
# "SubSumCD" => '2',
|
78
|
+
# "SubAuthorComment" => 'Nice nice...'
|
79
|
+
# })
|
80
|
+
# @mock_subdown.should_receive(:log_in!)
|
81
|
+
# @mock_subdown.should_receive(:log_out!)
|
82
|
+
# @mock_subdown.should_receive(:search_subtitles).and_return([mock_subtitle])
|
83
|
+
# @mock_subdown.should_receive(:download_subtitle).and_return(mock_subtitle)#.with(@mock_subtitle)
|
84
|
+
# @mock_subtitle.should_receive(:format).and_return('sub')
|
85
|
+
# @mock_subdown.stub!(:format).and_return('srt')
|
86
|
+
#
|
87
|
+
# @subd = Subdownloader.new
|
88
|
+
# @subd.run!('teste.avi')
|
89
|
+
#
|
90
|
+
# @subd.down_a_sub(mock_subtitle, "xxx")
|
43
91
|
|
92
|
+
#end
|
93
|
+
|
94
|
+
it "should get extension files" do
|
95
|
+
Bin.get_extension("Lots.of.dots.happen").should eql("happen")
|
96
|
+
lambda { Bin.get_extension("Nodotstoo") }.should raise_error
|
44
97
|
end
|
45
98
|
|
46
|
-
it "should
|
47
|
-
Bin.
|
48
|
-
lambda { Bin.parse_file("Nodotstoo") }.should raise_error
|
99
|
+
it "should swap extensions" do
|
100
|
+
Bin.swap_extension("foo.txt", "srt").should eql("foo.srt")
|
49
101
|
end
|
50
102
|
|
51
103
|
it "should parse user input" do
|
@@ -67,8 +119,30 @@ describe Subdownloader do
|
|
67
119
|
"SubAuthorComment" => 'Nice nice...'
|
68
120
|
})
|
69
121
|
@subd = Subdownloader.new
|
70
|
-
@subd.
|
122
|
+
@subd.print_option(@sub, 1).should eql("2) Resevoir Dogs / 1992 | Cool sub | Movie score: 10.0
|
71
123
|
Lang: Eng | Format: SRT | Downloads: 310 | Rating: 9.5 | CDs: 2
|
72
124
|
Comments: Nice nice... \n\n")
|
73
125
|
end
|
74
126
|
end
|
127
|
+
|
128
|
+
describe Subwork do
|
129
|
+
include BinspecHelper
|
130
|
+
|
131
|
+
it "should call a new subtitle" do
|
132
|
+
File.should_receive(:open).with("file.srt", "r").and_return(mock_file)
|
133
|
+
File.should_receive(:open).with("file.sub", "w").and_return(true)
|
134
|
+
|
135
|
+
Subtitle.should_receive(:new).and_return(mock_subtitle)
|
136
|
+
@mock_subtitle.should_receive(:to_sub).and_return('subbb')
|
137
|
+
|
138
|
+
Subwork.new.run!("file.srt", "sub")
|
139
|
+
end
|
140
|
+
|
141
|
+
it "should not write if file exists" do
|
142
|
+
File.should_receive(:open).with("file.srt", "r").and_return(mock_file)
|
143
|
+
File.should_receive(:exists?).and_return(true)
|
144
|
+
Subtitle.should_receive(:new).and_return(mock_subtitle)
|
145
|
+
@mock_subtitle.should_receive(:to_sub).and_return('subbb')
|
146
|
+
Subwork.new.run!("file.srt", "sub")
|
147
|
+
end
|
148
|
+
end
|
@@ -5,7 +5,7 @@ describe Formats, ".mpl" do
|
|
5
5
|
describe "In" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@mpl = Subtitle.new(mpl_fixture,'mpl')
|
8
|
+
@mpl = Subtitle.new(nil, mpl_fixture,'mpl')
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should parse the sub to an array" do
|
@@ -32,7 +32,7 @@ describe Formats, ".mpl" do
|
|
32
32
|
describe "Out!" do
|
33
33
|
|
34
34
|
before(:each) do
|
35
|
-
@sub = Subtitle.new(yml_fixture,'yml')
|
35
|
+
@sub = Subtitle.new(nil, yml_fixture,'yml')
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should dump the object as a SRT" do
|
@@ -5,7 +5,7 @@ describe Formats, ".rsb" do
|
|
5
5
|
describe "In" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@rsb = Subtitle.new(rsb_fixture,'rsb')
|
8
|
+
@rsb = Subtitle.new(nil, rsb_fixture,'rsb')
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should parse the sub to an array" do
|
@@ -32,7 +32,7 @@ describe Formats, ".rsb" do
|
|
32
32
|
describe "Out" do
|
33
33
|
include SubFixtures
|
34
34
|
before(:each) do
|
35
|
-
@sub = Subtitle.new(yml_fixture,'yml')
|
35
|
+
@sub = Subtitle.new(nil, yml_fixture,'yml')
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should dump the object to rsb" do
|
@@ -5,7 +5,7 @@ describe Formats, ".srt" do
|
|
5
5
|
describe "In" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@srt = Subtitle.new(srt_fixture,'srt')
|
8
|
+
@srt = Subtitle.new(nil, srt_fixture,'srt')
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should parse the sub to an array" do
|
@@ -32,11 +32,26 @@ describe Formats, ".srt" do
|
|
32
32
|
describe "Out!" do
|
33
33
|
|
34
34
|
before(:each) do
|
35
|
-
@sub = Subtitle.new(yml_fixture,'yml')
|
35
|
+
@sub = Subtitle.new(nil, yml_fixture,'yml')
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should dump the object as a SRT" do
|
39
|
-
@sub.to_srt.should eql("
|
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")
|
40
55
|
end
|
41
56
|
end
|
42
57
|
end
|
@@ -5,7 +5,7 @@ describe Formats, ".sub" do
|
|
5
5
|
describe "Parse" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@sub = Subtitle.new(sub_fixture,'sub')
|
8
|
+
@sub = Subtitle.new(nil, sub_fixture,'sub')
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should parse the sub to an array" do
|
@@ -36,7 +36,7 @@ describe Formats, ".sub" do
|
|
36
36
|
describe "Out" do
|
37
37
|
|
38
38
|
before(:each) do
|
39
|
-
@sub = Subtitle.new(yml_fixture,'yml')
|
39
|
+
@sub = Subtitle.new(nil, yml_fixture,'yml')
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should dump the object as a SUB" do
|
@@ -4,7 +4,7 @@ describe Formats, ".xml" do
|
|
4
4
|
include SubFixtures
|
5
5
|
describe "In" do
|
6
6
|
before(:each) do
|
7
|
-
@xml = Subtitle.new(xml_fixture,'xml')
|
7
|
+
@xml = Subtitle.new(nil, xml_fixture,'xml')
|
8
8
|
end
|
9
9
|
|
10
10
|
it "should parse the sub to an array" do
|
@@ -32,7 +32,7 @@ describe Formats, ".xml" do
|
|
32
32
|
|
33
33
|
describe "Out" do
|
34
34
|
before(:each) do
|
35
|
-
@sub = Subtitle.new(yml_fixture,'yml')
|
35
|
+
@sub = Subtitle.new(nil, yml_fixture,'yml')
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should parse the sub to an array" do
|
@@ -1 +1,39 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe Subtitle do
|
4
|
+
def attr_valid_subtitle
|
5
|
+
{
|
6
|
+
"SubLanguageID" => 'eng',
|
7
|
+
"MovieName" => 'Resevoir Dogs',
|
8
|
+
"MovieYear" => '1992',
|
9
|
+
"SubFileName" => 'Cool sub',
|
10
|
+
"MovieImdbRating" => '10.0',
|
11
|
+
"SubDownloadsCnt" => '310',
|
12
|
+
"SubRating" => '9.5',
|
13
|
+
"SubFormat" => 'srt',
|
14
|
+
"SubSumCD" => '2',
|
15
|
+
"SubAuthorComment" => 'Nice nice...'
|
16
|
+
}
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should instantiate" do
|
20
|
+
@sub = Subtitle.new(attr_valid_subtitle)
|
21
|
+
@sub.rating.should eql(9.5)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Compare" do
|
25
|
+
before(:each) do
|
26
|
+
@sub = Subtitle.new(attr_valid_subtitle)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should compare to another using rating" do
|
30
|
+
@another_sub = Subtitle.new(attr_valid_subtitle.with("SubRating" => 4.0))
|
31
|
+
(@sub > @another_sub).should be_true
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
end
|
data/spec/subtitle_it_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
5
5
|
describe SubtitleIt do
|
6
6
|
|
7
7
|
it "should instantiate " do
|
8
|
-
@sub = Subtitle.new("{12}{30}hey hey heypending", "sub")
|
8
|
+
@sub = Subtitle.new(nil, "{12}{30}hey hey heypending", "sub")
|
9
9
|
@sub.should be_instance_of(Subtitle)
|
10
10
|
end
|
11
11
|
end
|
data/subtitle_it.gemspec
CHANGED