=begin Copyright 2010, Roger Pack This file is part of Sensible Cinema. Sensible Cinema is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Sensible Cinema is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Sensible Cinema. If not, see . =end require File.expand_path(File.dirname(__FILE__) + '/common') require_relative '../lib/subtitle_profanity_finder' require 'sane' describe SubtitleProfanityFinder do describe "should parse out various profanities" do output = SubtitleProfanityFinder.edl_output 'dragon.srt' describe "h..." do it "should include the bad line with timestamp" do output.should match(/0:00:54.93.*"h\.\.\."/) end it "should include the description in its output" do output.should include("e [h...] b") end end describe "deity various" do it "should parse output plural deity" do output.should include("nordic [deitys] ") end it "should parse out deity singular and at very end" do output = SubtitleProfanityFinder.edl_output 'deity_end.srt' output.should include("fortress is our [vain use]") end it "should remove et al " do output = SubtitleProfanityFinder.edl_output 'deity_end.srt' output.should_not include(" i ") output.should_not include(" 'word'}, 1, 1.5 out.should include "45.46" out.should include "51.59" end def test_this_added_text text, extra = {} SubtitleProfanityFinder.edl_output_from_string(<<-EOL, extra, 0, 0, 0, 0, 100, 100) 6 00:00:55,068 --> 00:00:59,164 #{text} EOL end it "should remove some punctuation" do out = test_this_added_text " .- (ab\nc)." out[1][0].single_line_text.should == "(ab c)." out = test_this_added_text "(abc)., " out[1][0].single_line_text.should == "(abc)." end it "should let you set replacement text" do out = test_this_added_text "a good day", {'good' => ['replace with', :partial_word, 'category']} good = "\n \"0:00:55.07\" , \"0:00:59.16\", \"profanity\", \"category\", \"a [replace with] day\",\n\n" out[0].should == good out = test_this_added_text "a good day", {'good' => ['replace with', :full_word, 'category']} out[0].should == good end it "should accomodate lesser profanities" do out = test_this_added_text "I believe in the Lord" out[0].should include "55.0" assert out[1][0].text =~ /l.../i end it "should do full word with dashes" do parsed, entries = test_this_added_text("I believe in heaven and-hell-") assert parsed =~ /heaven/ assert parsed !~ /hel/ end describe "it should take optional user params" do output = SubtitleProfanityFinder.edl_output 'dragon.srt', {'word' => 'word'} it "should parse out the word word" do output.should match(/0:00:50.09.*"word"/) end it "should parse out and replace with euphemism" do output = SubtitleProfanityFinder.edl_output 'dragon.srt', {'word' => 'w...'} output.should match(/0:00:50.09.*In a \[w\.\.\.\]/) end end S = SubtitleProfanityFinder describe "it should let you re-factor the timestamps on the fly if desired" do it "should subtract from beginning etc. etc." do normal = S.edl_output 'dragon.srt' normal.should =~ /0:00:50.23/ normal.should =~ /0:00:54.93/ subtract = S.edl_output 'dragon.srt', {}, 1.0 subtract.should =~ /0:00:49.23/ normal.should =~ /0:00:54.93/ add = S.edl_output 'dragon.srt', {}, 0.0, 1.0 add.should =~ /0:00:55.93/ add.should =~ /0:00:50.23/ end it "should compensate for differing start timestamps" do starts_ten_later_than_srt = S.edl_output 'dragon.srt', {}, 0.0, 0.0, 10.0, 20.0, 110, 120 starts_ten_later_than_srt.should =~ /0:01:00.23/ # 50.23 -> this starts_ten_later_than_srt.should =~ /0:01:04.93/ end it "should compensate for differing end timestamps with a multiple" do lasts_longer = S.edl_output 'dragon.srt', {}, 0.0, 0.0, 0.0, 0.0, 60.0, 90.0 # actual ends 50% later lasts_longer.should =~ /0:01:15.34/ lasts_longer.should =~ /0:01:22.39/ end describe "combining different initial time offsets with total times" do it "should combine different initial time offset with different total time" do lasts_longer_with_initial_add = S.edl_output 'dragon.srt', {}, 0.0, 0.0, begin_srt = 0.0, begin_actual = 10.0, end_srt = 55.0, end_actual = 55.0 # this one starts off weird, but then ends at almost exactly the same! lasts_longer_with_initial_add.should =~ /0:00:51.10/ lasts_longer_with_initial_add.should =~ /0:00:54.94/ # note--almost on end it "should be ok if they line up perfectly with just an offset" do plus_ten = S.edl_output 'dragon.srt', {}, 0.0, 0.0, begin_srt = 0.0, begin_actual = 10.0, end_srt = 55.0, end_actual = 65.0 plus_ten.should =~ /0:01:00.23/ plus_ten.should =~ /0:01:04.93/ end end end it "should split to human friendlier entries" do yo = S.split_to_entries File.read('dragon.srt') for entry in yo ts_begin = entry.beginning_time ts_end = entry.ending_time for timestamp in [ts_begin, ts_end] assert timestamp.present? assert timestamp.is_a? Float end assert ts_end > ts_begin assert entry.text =~ /\n/m end end it "should capture times and tweak them, and keep punctuation" do out = S.edl_output_from_string <<-EOL, {}, 0,0,88, 88.16, 7296.5, 7292.4, true 1 00:01:28,000 --> 00:01:29,036 Grandpa(sris)! your's is here?!., EOL assert out[1][0].beginning_time == 88.16 out[1][0].text.should match /\(sris\)!/ end end